Incremental servo

Selfbondage software and other kinky developments

Moderators: Riddle, Shannon SteelSlave

User avatar
atiedslut
*
Posts: 22
Joined: 25 Jun 2010, 00:58
Location: Florida, USA
Contact:

Incremental servo

Post by atiedslut »

I'm been using "pain.exe" and the motion detection to drive a servo. The servo is connected to ChA of my 312 so that each time I get teased the servo turns up the 312 ChA. However, the 180 deg is too much of an increase so I have modified the Arduino code to limit the travel to about 20deg but even this is a bit intense !

What I would like to do is change either "pain.exe" or the Arduino sketch so that each tease increases the servo movement by a few degrees each time hence it progressively increases the ChA value. Has anyone else done this or can give me any ideas pls ?
Stephanie
User avatar
Dark_Lizerd
*****
Posts: 2416
Joined: 22 Oct 2006, 11:30
Location: New Mexico

Re: Incremental servo

Post by Dark_Lizerd »

Controlled incremental change...
Sounds like what you are after is a stepper motor...
Some steppers can single-step 1 degree at a time...
Some even less...
Second:
Is the servo directly connected to the ChA knob (I guess)
Then try a pulley arrangement, small pulley on the servo and a larger one on the control...
And connect them with a rubber band for the belt...
That way, the servo can make several turn to 1 turn of the knob...
All advice is checked, re-checked and verified to be questionable...
Don't ask, we both wont understand the answer...
http://www.mediafire.com/download/09dtr ... e_V2_2.exe Not just for nubies any more...
User avatar
qwerty212
Moderator
Posts: 1064
Joined: 23 Mar 2010, 20:24

Re: Incremental servo

Post by qwerty212 »

atiedslut wrote:I'm been using "pain.exe" and the motion detection to drive a servo. The servo is connected to ChA of my 312 so that each time I get teased the servo turns up the 312 ChA. However, the 180 deg is too much of an increase so I have modified the Arduino code to limit the travel to about 20deg but even this is a bit intense !

What I would like to do is change either "pain.exe" or the Arduino sketch so that each tease increases the servo movement by a few degrees each time hence it progressively increases the ChA value. Has anyone else done this or can give me any ideas pls ?
Welcome to the forum :hi:

Now I have to go to to work (my boss considers that if he pays me I had to go Image) Can you believe it?

This weekend I'll publish source code of pain.exe and the arduino sketch and we'll see how can I help you.

Bye :hi:
User avatar
bound_jenny
Moderator
Posts: 10268
Joined: 09 Dec 2007, 12:37
Location: Montreal, Canada, Great Kinky North

Re: Incremental servo

Post by bound_jenny »

Image)

Qwerty's boss has hired me as motivational director. He felt that his employees needed to be whipped into shape. :mrgreen:

Cute. :love:

Jenny.
Helplessness is a doorway to the innermost reaches of the soul.
If my corset isn't tight, it just isn't right!
Kink is the spice of life!
Come to the Dark Side - we have cookies!
lj
Moderator
Posts: 2255
Joined: 14 Oct 2008, 18:22
Location: East Anglia, UK

Re: Incremental servo

Post by lj »

I don't have any experience of the Arduino (yet, it may feature one day) but I do write code for the PIC processors. I wrote code for a servo controller a while ago - all you have to do is vary an output pulse width to cause any movement of the servo from tiny to full travel - the pulse width goes from 1msec to 2msec with a frame width of around 20msec. My code allowed 256 steps as I kept the counters within 8 bits.

sorry if this is teaching granny...
be a switch, double the fun :-)
User avatar
atiedslut
*
Posts: 22
Joined: 25 Jun 2010, 00:58
Location: Florida, USA
Contact:

Re: Incremental servo

Post by atiedslut »

Wow...thank you for all the suggestions :-)
Dark_Lizerd wrote:Controlled incremental change...
Sounds like what you are after is a stepper motor...
Some steppers can single-step 1 degree at a time...
Some even less...
Second:
Is the servo directly connected to the ChA knob (I guess)
Then try a pulley arrangement, small pulley on the servo and a larger one on the control...
And connect them with a rubber band for the belt...
That way, the servo can make several turn to 1 turn of the knob...
I thought of using a stepper but it was much easier to use a servo as qwerty212 already had a way to drive a servo from the programs and are easier to mechanically interface to a pot using plastic tube. Once I can get the servo to increase incrementally which should be possible then I think I'd have what I need.
qwerty212 wrote:This weekend I'll publish source code os pain.exe and the arduino sketch and we'll see how can I help you.
Thank you that would be great ! my biggest issue is not knowing what "pain.exe" is sending to the Arduino. Btw I just want you to know how wonderful I think your programs are and to thank you for all the time and effort it must have taken you.
lj wrote:I don't have any experience of the Arduino (yet, it may feature one day) but I do write code for the PIC processors. I wrote code for a servo controller a while ago - all you have to do is vary an output pulse width to cause any movement of the servo from tiny to full travel - the pulse width goes from 1msec to 2msec with a frame width of around 20msec. My code allowed 256 steps as I kept the counters within 8 bits.

sorry if this is teaching granny...
No you are not teaching granny (well not in that sense..LOL). Arduino makes it easy as there are libraries to do many things including driving a servo so you dont have to get into the details of pulse width etc . If you've written for a PIC you'd find Arduino easy :-)

Thanks for all the feedback .
Stephanie
User avatar
qwerty212
Moderator
Posts: 1064
Joined: 23 Mar 2010, 20:24

Re: Incremental servo

Post by qwerty212 »

bound_jenny wrote:Image)

Qwerty's boss has hired me as motivational director. He felt that his employees needed to be whipped into shape. :mrgreen:

Cute. :love:

Jenny.
Bufff, you would finish with unemployment in Spain in just a week :wink:

Ok atiedslut, let's see if I can help you with the incremental servo issue.
OK this is the pde that you have uploaded to your Arduino Board.

Code: Select all

#include <Servo.h>
Servo Servo1;  // create servo called Servo1
Servo Servo2;  // create servo called Servo2
Servo Servo3;  // create servo called Servo2
char Address;  //Variable to store Incoming Packets ID
int val = 0;
int data = 0;
void setup()
{
  Serial.begin(9600);
  Servo1.attach(8);  // attaches the servo1 on pin 8 to the servo object
  Servo2.attach(9);  // attaches the servo2 on pin 9 to the servo object
  Servo3.attach(13);  // attaches the servo2 on pin 13 to the servo object
}
void loop()
{
  while (Serial.available() > 0)
  {
    Address = Serial.read();
    if (Address == 'A') Read_Servo1();  // If ID = A goto Servo1
    if (Address == 'B') Read_Servo2();  // If ID = B goto Servo2
    if (Address == 'C') Read_Servo3();  // If ID = C goto Servo3
  }
}
 
void Read_Servo1()
{
  delay(2); int data100 = Serial.read()- '0';  // Read in first bit od data
  delay(2); int data10 = Serial.read()- '0';  // Read in second bit od data
  delay(2); int data1 = Serial.read()- '0';  // Read in third bit od data
  data = 100*data100 + 10*data10 + data1; // Left shift each byte, add add together to get our value 000
  val = map(data, 0, 180, 10, 180);  // Asign our range of 0 - 180 to the servos range of  0 - 180
  Servo1.write(val);  //Write the value to Serial
  delay(10);      // waits 10ms for the servo to reach the position
}
void Read_Servo2()
{
  delay(2); int data100 = Serial.read()- '0';
  delay(2); int data10 = Serial.read()- '0';
  delay(2); int data1 = Serial.read()- '0';
  data = 100*data100 + 10*data10 + data1;
  val = map(data, 0, 180, 10, 180);
  Servo2.write(val);
  delay(10);      // waits 10ms for the servo to reach the position
}

void Read_Servo3()
{
  delay(2); int data100 = Serial.read()- '0';
  delay(2); int data10 = Serial.read()- '0';
  delay(2); int data1 = Serial.read()- '0';
  data = 100*data100 + 10*data10 + data1;
  val = map(data, 0, 180, 10, 180);
  Servo3.write(val);
  delay(10);      // waits 10ms for the servo to reach the position
}
Notice that it let's you put up to 3 servos inthe same Arduino. My Pian.exe just sends via serial port a letter (A, B or C to determinate wich servo should be moved) and a degree from 0º to 180º. After a sleep of x miliseconds it sends to the Arduino the same letter and the reposing position of the servo (I use to use 90º, but it can be 0º depending on your session setup).

I'm going to create a Pain.exe that will let you determinate the cero position of your servo just storing the variable in an .ini file. You will also be able to set the ms that the sleep will last. Let's see how:

Code: Select all

#include 'CommMG.au3'
#include <Misc.au3>


_Singleton("PAIN") ;this instruction will not let to be pain.exe running at the same time
;Internal for the Serial UDF
Global $sportSetError = ''
_CommSetDllPath(@ScriptDir & "\commg.dll") ; you just have to have the comm.dll in the same folder than pain.exe
;COM Vars
Global $CMPort = IniRead(@ScriptDir & "\Settings.ini", "Settings", "Port", "4") ; Port to be used in the serial comunication. Set it in the .ini file.
Global $CmBoBaud = 9600 ; Baud
Global $CmboDataBits = 8 ; Data Bits
Global $CmBoParity = "none" ; Parity
Global $CmBoStop = 1 ; Stop
Global $setflow = 2 ; Flow
_CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow)
_CommSetRTS(0)
_CommSetDTR(0)



movetostartposition() ;just a function to be sure that the servo is in its initial position
Sleep (1000) ; a little sleep before the servo moves to the teasing position
movetoteasingposition() ; the instruction that will move the servo to the teasing position.
;thats the one that we are going to modify to make it incremental.



Func movetostartposition()

	$Servorestingposition = IniRead(@ScriptDir & "\Settings.ini", "Settings", "Startposition", "0") ;we read the resting position of your servo

	_CommSendString(StringFormat("A%03d", Int($Servorestingposition))) ; we send to the Arduino this position

	EndFunc

Func movetoteasingposition()

	$sleeptime = IniRead(@ScriptDir & "\Settings.ini", "Settings", "Sleeptime", "500"); time that the servo will remain in the teasing position in miliseconds

	$Servoteasingposition = IniRead(@ScriptDir & "\Settings.ini", "Settings", "Teasingposition", "180"); we read the position of the teasing that the servo should move

	_CommSendString(StringFormat("A%03d", Int($Servoteasingposition))); we send this position to the Arduino board

	sleep ($sleeptime) ; we wait this amount of miliseconds until the servo reaches the position and waits before leaving


	$Servorestingposition = IniRead(@ScriptDir & "\Settings.ini", "Settings", "Startposition", "0"); now we send the servo back to home

	_CommSendString(StringFormat("A%03d", Int($Servorestingposition)))

	Sleep (500)

	Exit

EndFunc
Finally you need the .dll taht makes the magic of comunicate the Pain.exe with the Arduino using the serial port:
https://mega.co.nz/#!ycMB0arD!9wYns6imJ ... tYvXNlSdCI

and the .ini file with the settings (name it Settings.ini:

Code: Select all

[Settings]
Port=4
Sleeptime=1000
Startposition=0
Teasingposition=180
Now I need to know what kind of increment do you need. how many differents positions may the servo reach before it arrives to 180º. Always with the same sleeping time? What do you want to happen once the servo has reached the 180ª? Start again from the beggining? Maybe random teasing duration when it reach the max position?

Greets from Barcelona
User avatar
atiedslut
*
Posts: 22
Joined: 25 Jun 2010, 00:58
Location: Florida, USA
Contact:

Re: Incremental servo

Post by atiedslut »

Thanks for the code and explanation.

I probably need to explain a little better what I am trying to do as its not quite the same.

My servo is mechanically connected to the Ch A on my 312 so when the servo turns it increases the output of the 312. What I want to do is use the motion detector to detect motion and/or sound while I am tied and each time it detects it will run a 'tease'. The tease program commands the servo via Arduino to turn the servo by some number of degrees, ideally select-able between 1 and up to 10. So during the time I am tied each time I move the 312 gets turned up a little. Clearly, I will also need some maximum ! This is a little different to the current "pain.exe' as it doesnt have a pause and return. The servo simply turns up the 312 each time it gets a command and stays at that position.

My thoughts are that the the PC code would just select the servo (nice you now drive 3 !)and send a command to the Arduino ? I could simply set the pde to increase the servo angle by some increment angle each time it gets an "A" ? and check that its less than some max value ? or I can use a .ini file to set the step value and maximum ? which might be the best ?

I was able to compile and upload the pde sketch and also got the dll . I assume the other code is Autoit ? but I was not able to compile it because it couldnt find commg.au3 ? I have never used Autoit so my apologies.

Stephanie
Stephanie
User avatar
qwerty212
Moderator
Posts: 1064
Joined: 23 Mar 2010, 20:24

Re: Incremental servo

Post by qwerty212 »

atiedslut wrote:Thanks for the code and explanation.

I probably need to explain a little better what I am trying to do as its not quite the same.

My servo is mechanically connected to the Ch A on my 312 so when the servo turns it increases the output of the 312. What I want to do is use the motion detector to detect motion and/or sound while I am tied and each time it detects it will run a 'tease'. The tease program commands the servo via Arduino to turn the servo by some number of degrees, ideally select-able between 1 and up to 10. So during the time I am tied each time I move the 312 gets turned up a little. Clearly, I will also need some maximum ! This is a little different to the current "pain.exe' as it doesnt have a pause and return. The servo simply turns up the 312 each time it gets a command and stays at that position.

My thoughts are that the the PC code would just select the servo (nice you now drive 3 !)and send a command to the Arduino ? I could simply set the pde to increase the servo angle by some increment angle each time it gets an "A" ? and check that its less than some max value ? or I can use a .ini file to set the step value and maximum ? which might be the best ?

I was able to compile and upload the pde sketch and also got the dll . I assume the other code is Autoit ? but I was not able to compile it because it couldnt find commg.au3 ? I have never used Autoit so my apologies.

Stephanie
Uops, sorry. My fault. Here you can get my personal Include folder:
https://mega.co.nz/#!KUlBAYaJ!uXLMhHe7g ... izJ18mOtL8

Just copy the content inside yours.

As I understand you just need that the servo move from 0º to 1º and stay there until you finish your session or until it has to be moved to 2º, 3º, 4º... up to a maximum?

Greets from Barcelona
User avatar
atiedslut
*
Posts: 22
Joined: 25 Jun 2010, 00:58
Location: Florida, USA
Contact:

Re: Incremental servo

Post by atiedslut »

Ok, thank you. I got your 'include' files and was able to compile the code :-)...Once I worked out the servo 1 is now on pin 8 it all worked fine and I can change the start & stop positions as well as the 'sleep' time from the ini file.

What I want to happen is starting at 0 deg (servo start) each time movement is detected the servo moves by 1deg more and stays in that position. So it will behave like this loop (not coded btw).

Start Servo position = 0
Loop
If "motion detected" then Servo position = servo position + 1 // or some step size larger than 1 for the brave .
Until Servo position => max servo position.

So what will happen is that the 312 will progressively be increased making staying motionless or silent increasingly harder :-).

Now I can control 3 servo's I need to decide what other torments I might add too ! Am I correct to assume that in _CommSendString(StringFormat("A%03d", Int($Servorestingposition))) that the "A%03d" string selects servo 1 ( ie A), so if I wanted to select servo 2 It would be "B%03d", what are the other characters used for ?

I am trying to learn as I go so will do some experimenting over the next few days and then post my attempts. I probably have enough to try to do this now but would appreciate your comments once I have something which works just in case I make some mistakes. My biggest fear is the servo would go all the way to max because of an error in the code...Eeeek !

Thanks
Stephanie
User avatar
qwerty212
Moderator
Posts: 1064
Joined: 23 Mar 2010, 20:24

Re: Incremental servo

Post by qwerty212 »

atiedslut wrote:Ok, thank you. I got your 'include' files and was able to compile the code :-)...Once I worked out the servo 1 is now on pin 8 it all worked fine and I can change the start & stop positions as well as the 'sleep' time from the ini file.
Neat!
atiedslut wrote:What I want to happen is starting at 0 deg (servo start) each time movement is detected the servo moves by 1deg more and stays in that position. So it will behave like this loop (not coded btw).

Start Servo position = 0
Loop
If "motion detected" then Servo position = servo position + 1 // or some step size larger than 1 for the brave .
Until Servo position => max servo position.

So what will happen is that the 312 will progressively be increased making staying motionless or silent increasingly harder :-).
Now I get it!!
atiedslut wrote:Now I can control 3 servo's I need to decide what other torments I might add too ! Am I correct to assume that in _CommSendString(StringFormat("A%03d", Int($Servorestingposition))) that the "A%03d" string selects servo 1 ( ie A), so if I wanted to select servo 2 It would be "B%03d", what are the other characters used for ?
Is the way to format numbers, so when you send a 1 it will be sent as 001. If you change the code to _CommSendString(StringFormat("A%02d", Int($Servorestingposition))) it will be 01.
Do not change it as your .pde works fine as it is now.
atiedslut wrote:I am trying to learn as I go so will do some experimenting over the next few days and then post my attempts. I probably have enough to try to do this now but would appreciate your comments once I have something which works just in case I make some mistakes. My biggest fear is the servo would go all the way to max because of an error in the code...Eeeek !

Thanks
In my opninion a good way of proceed would be let the .pde as you have it right now and work with the Autoit code. You can store the current position of the servo in the same ini file doing something like:

Code: Select all

Func movetoteasingposition() ;the funtion that is going to tease you


Local $newteasingposition =  Iniread(@ScriptDir & "\Settings.ini", "Settings", "CurrentPosition", "0")  ; we read the current position, in case value doesn't exist it takes zero as default

   If $newteasingposition <   IniRead(@ScriptDir & "\Settings.ini", "Settings", "Teasingposition", "10") Then    ;If the current position is less that the max positioon allowed in the .ini file then...

$newteasingposition = $newteasingposition + 1  ;the bew position will be the current degree plus one

 Iniwrite(@ScriptDir & "\Settings.ini", "Settings", "CurrentPosition",$newteasingposition) ; we store the new position in the .ini file for the next time we execute the pogram

   _CommSendString(StringFormat("A%03d", Int($newteasingposition))); we send this position to the Arduino board

   sleep ($sleeptime) ; we wait this amount of miliseconds until the servo reaches the position.

Exit ; as we do not want the servo to come back to zero.
You also are going to need a "ready to play".exe that moves the servo to zero and sets that value as current position in the ini file.

Do you need me to built the exe for you?
User avatar
atiedslut
*
Posts: 22
Joined: 25 Jun 2010, 00:58
Location: Florida, USA
Contact:

Re: Incremental servo

Post by atiedslut »

Thank you for the Autoit code. I think I need to do some study on Autoit 1st so I can better understand the syntax before I attempt any code :-). I can see that making the changes in the .exe would be more flexible but I find the Arduino code a little easier as I am more familiar with it.

I wont get much time till the weekend to work on this but will let you know how I get on.

Thank you for your help.
Stephanie
User avatar
qwerty212
Moderator
Posts: 1064
Joined: 23 Mar 2010, 20:24

Re: Incremental servo

Post by qwerty212 »

atiedslut wrote:Thank you for the Autoit code. I think I need to do some study on Autoit 1st so I can better understand the syntax before I attempt any code :-). I can see that making the changes in the .exe would be more flexible but I find the Arduino code a little easier as I am more familiar with it.

I wont get much time till the weekend to work on this but will let you know how I get on.

Thank you for your help.
If you want while you are learning I can compile the code above to let you play during the coding pauses :mrgreen:
User avatar
atiedslut
*
Posts: 22
Joined: 25 Jun 2010, 00:58
Location: Florida, USA
Contact:

Re: Incremental servo

Post by atiedslut »

Ok, I think I have it working !

I run the "start.exe" to set the servo to the zero position. The run "pain3.exe" each time the tease is triggered. The step size and maximum angle is set in the .ini file.

Code: Select all

#include 'CommMG.au3'
#include <Misc.au3>


_Singleton("PAIN") ;this instruction will not let to be pain.exe running at the same time
;Internal for the Serial UDF
Global $sportSetError = ''
_CommSetDllPath(@ScriptDir & "\commg.dll") ; you just have to have the comm.dll in the same folder than pain.exe
;COM Vars
Global $CMPort = IniRead(@ScriptDir & "\Settings.ini", "Settings", "Port", "4") ; Port to be used in the serial comunication. Set it in the .ini file.
Global $CmBoBaud = 9600 ; Baud
Global $CmboDataBits = 8 ; Data Bits
Global $CmBoParity = "none" ; Parity
Global $CmBoStop = 1 ; Stop
Global $setflow = 2 ; Flow
_CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow)
_CommSetRTS(0)
_CommSetDTR(0)




movetostartposition() ; the instruction that will move the servo to the start position.


Func movetostartposition()

   $Servorestingposition = IniRead(@ScriptDir & "\Settings.ini", "Settings", "Startposition", "0") ;we read the start position of your servo from the ini file

   _CommSendString(StringFormat("A%03d", Int($Servorestingposition))) ; we send to the Arduino this position
   
   IniWrite(@ScriptDir & "\Settings.ini", "Settings", "CurrentPosition",$Servorestingposition) ; we store the new position in the .ini file for the next time we execute the pogram
   
   Sleep (500)
   
   Exit
   
   EndFunc
and

Code: Select all

#include 'CommMG.au3'
#include <Misc.au3>


_Singleton("PAIN") ;this instruction will not let to be pain.exe running at the same time
;Internal for the Serial UDF
Global $sportSetError = ''
_CommSetDllPath(@ScriptDir & "\commg.dll") ; you just have to have the comm.dll in the same folder than pain.exe
;COM Vars
Global $CMPort = IniRead(@ScriptDir & "\Settings.ini", "Settings", "Port", "4") ; Port to be used in the serial comunication. Set it in the .ini file.
Global $CmBoBaud = 9600 ; Baud
Global $CmboDataBits = 8 ; Data Bits
Global $CmBoParity = "none" ; Parity
Global $CmBoStop = 1 ; Stop
Global $setflow = 2 ; Flow
_CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow)
_CommSetRTS(0)
_CommSetDTR(0)

;movetostartposition()
Sleep (1000) ; a little sleep before the servo moves to the teasing position
movetoteasingposition() ; the instruction that will move the servo to the teasing position.
;thats the one that we are going to modify to make it incremental.



Func movetostartposition()

   $Servorestingposition = IniRead(@ScriptDir & "\Settings.ini", "Settings", "Startposition", "0") ;we read the resting position of your servo

   _CommSendString(StringFormat("A%03d", Int($Servorestingposition))) ; we send to the Arduino this position

   EndFunc

Func movetoteasingposition() ;the funtion that is going to tease you


Local $newteasingposition =  IniRead(@ScriptDir & "\Settings.ini", "Settings", "CurrentPosition", "0")  ; we read the current position, in case value doesn't exist it takes zero as default

$StepSize = IniRead(@ScriptDir & "\Settings.ini" , "Settings" , "StepSize", "5")  ; read step 

$newteasingposition = $newteasingposition + $StepSize ;the new position will be the current degree plus step

If $newteasingposition >= IniRead(@ScriptDir & "\Settings.ini", "Settings", "MaxTeasingposition", "180") Then    ;If the current position is less that the max positioon allowed in the .ini file then...

Exit

Endif

 IniWrite(@ScriptDir & "\Settings.ini", "Settings", "CurrentPosition",$newteasingposition) ; we store the new position in the .ini file for the next time we execute the pogram

   _CommSendString(StringFormat("A%03d", Int($newteasingposition))); we send this position to the Arduino board

   sleep (1000) ; we wait this amount of miliseconds until the servo reaches the position.


Exit ; as we do not want the servo to come back to zero.


EndFunc
with the ini file as

Code: Select all

[Settings]
Port=4
Sleeptime=1000
Startposition=0
MaxTeasingposition=100
CurrentPosition=0
StepSize=5
I need to tidy the code and remove some parts not needed ....any thing I have missed before I try it out ?
Stephanie
User avatar
qwerty212
Moderator
Posts: 1064
Joined: 23 Mar 2010, 20:24

Re: Incremental servo

Post by qwerty212 »

It's 6am in Barcelona, but taking a quick look you are going to move the servo to zero and then to the new teasing position each time that you are going to be teased.

That is not really necessary if you do not want. You just can be at (as example) at 30 degrees and move to 35 degrees without having to go to zero (maybe you want it that way).

But, it looks fine for me. I will try it this afternoon.
Post Reply