Two servos opposite direction with potentiometer
Scott B
Posts: 5
I have used the potentiometer to control one servo using the method in the "What's a Microcontroller". But I would like to use the potentiometer to control two servos moving opposite direction at the same speed. The reason is, I want to connect two servos to the same robot arm and thus would have to move opposite directions. For some reason I can't figure out the scale for the opposite direction. Any help is appreciated, thanks. Here is the regular code for one servo from the book.
' What's a Microcontroller - ControlServoWithPotUsingDirectives.bs2 ' Read potentiometer in RC-time circuit using RCTIME command.
' Apply scale factor and offset, then send value to servo.
' {$STAMP BS2}
' {$PBASIC 2.5}
rcPin PIN 7 ' I/O Pin Definitions
servoPin PIN 14
scaleFactor CON 185 ' Constant Declarations
offset CON 500
delay CON 10
time VAR Word ' Variable Declaration
PAUSE 1000 ' Initialization
DO
' Main Routine
HIGH rcPin ' RC decay measurement
PAUSE delay
RCTIME rcPin, 1, time
time = time */ scaleFactor ' Scale scaleFactor.
time = time + offset ' Offset by offset.
PULSOUT servoPin, time ' Send pulse to servo.
DEBUG HOME, DEC5 time ' Display adjusted time value.
LOOP
' What's a Microcontroller - ControlServoWithPotUsingDirectives.bs2 ' Read potentiometer in RC-time circuit using RCTIME command.
' Apply scale factor and offset, then send value to servo.
' {$STAMP BS2}
' {$PBASIC 2.5}
rcPin PIN 7 ' I/O Pin Definitions
servoPin PIN 14
scaleFactor CON 185 ' Constant Declarations
offset CON 500
delay CON 10
time VAR Word ' Variable Declaration
PAUSE 1000 ' Initialization
DO
' Main Routine
HIGH rcPin ' RC decay measurement
PAUSE delay
RCTIME rcPin, 1, time
time = time */ scaleFactor ' Scale scaleFactor.
time = time + offset ' Offset by offset.
PULSOUT servoPin, time ' Send pulse to servo.
DEBUG HOME, DEC5 time ' Display adjusted time value.
LOOP
Comments
Numerous ways to reverse servos:
1) Modify a servo to work in reverse. Open up the bottom. Reverse your 2 motor wires. Also reverse the 2 outer wires on your pot.
2) Buy a servo reverser from Hobby King for $2: http://www.hobbyking.com/hobbyking/store/uh_viewItem.asp?idProduct=17033
3) Calculate and send two different pulses for each servo, centered at 1.5 ms, AKA pulsout 750. For instance, these pairs would give fairly matched speeds for two CR servos or positions for two regular servos:
750 750 stop
800 700 very slow
850 650 slow
900 600 medium
950 550 medium fast
1000 500 fast
So once you have one pulsout value P, the other value (for a BS2) is (1500-P)
Note that if you're trying to make a yoke-type robot arm joint by mounting 2 servos back to back to have a rotating servo horn on both sides, the servos will probably be slightly out of sync and constantly flighting each other, unless you build some compliance (flexibility) into the yoke joining them.
He uses 2 servos at the shoulder (neither reversed) and the whole arm joint is his U-shaped yoke, which can flex a bit and let each servo do its own thing. Nice way to do it.