Shop OBEX P1 Docs P2 Docs Learn Events
Two servos opposite direction with potentiometer — Parallax Forums

Two servos opposite direction with potentiometer

Scott BScott B Posts: 5
edited 2012-02-17 02:25 in BASIC Stamp
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

Comments

  • ercoerco Posts: 20,256
    edited 2012-02-16 16:53
    You say "to control two servos moving opposite direction at the same speed", which implies constant rotation servos, but later you mention a robot arm, implying regular 180-degree servos. Which are you talking about?

    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.
  • Scott BScott B Posts: 5
    edited 2012-02-16 21:21
    Thanks for the help. As for the same speed I really just meant one clockwise and the other counter clockwise as I will have them on yoke-type robot arm. I was wondering if they would be fighting each other, good call. I will just build flexibility into one of them then. I was trying to calculate the scaling from the pot for both clockwise and counter clockwise and send two different pulses. But I think your other methods will be easier, and thanks for the site hobby king.
  • ercoerco Posts: 20,256
    edited 2012-02-17 02:25
    Check this guy: http://www.youtube.com/watch?v=V2a3qy08d-c&feature=endscreen&NR=1

    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.
Sign In or Register to comment.