Shop OBEX P1 Docs P2 Docs Learn Events
Controlling 3 Servos With 3 Potentiometers — Parallax Forums

Controlling 3 Servos With 3 Potentiometers

mspicermspicer Posts: 8
edited 2013-04-15 14:59 in BASIC Stamp
I'm part of my high school's Robotics team and we're trying to build a robotic arm that makes use of three 180 degree rotation servos very similar to the ones from the "What's a Microcontroller" kit. I've been trying to write a program that allows me to control the three servos independently using three different potentiometers, and so far I've been unsuccessful.

Here's my latest attempt:

' {$STAMP BS2}
' {$PBASIC 2.5}


time1 VAR Word
time2 VAR Word
time3 VAR Word


DO


GOSUB GETtime1
PULSOUT 13, time1


GOSUB GETtime2
PULSOUT 14, time2


GOSUB GETtime3
PULSOUT 15, time3


LOOP


'
GETtime1:


HIGH 11
PAUSE 10
RCTIME 11, 1, time1
LOW 11
time1 = time1 */ 185
time1 = time1 +500




RETURN


'


GETtime2:


HIGH 7
PAUSE 10
RCTIME 7, 1, time2
LOW 7
time2 = time2 */ 185
time2 = time2 +500




RETURN


'


GETtime3:


HIGH 0
PAUSE 10
RCTIME 0, 1, time3
LOW 0
time3 = time3 */ 185
time3 = time3 +500


RETURN

Below, I've also attached a picture of my breadboard wiring. I'd really appreciate it if someone could guide me in the right direction!
2013-04-09 21.17.10.jpg
1024 x 614 - 71K

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-04-09 20:38
    The problem is that servos require control pulses every 20ms or they turn off and your routines for measuring the potentiometer position take much longer than that. Theoretically, you could figure out an RC combination that would take less than 2ms to charge and discharge. That's a bit more than 12ms for the three of them plus 2ms each for the maximum pulse width for the servo for a total of 18ms which leaves a little bit for the actual Basic statements to execute. You'd need to shorten the PAUSEs appropriately and the RCTIME result value range would be different.

    It's probably easier to use an external ADC (analog to digital converter) like the MCP3204 which has 4 channels and can be easily controlled by the Stamp and has some example programs (see the webstore page for a link for that).
  • mspicermspicer Posts: 8
    edited 2013-04-10 17:59
    Thank you so much!
  • ercoerco Posts: 20,256
    edited 2013-04-10 19:10
    Or for just $6.66 (MWA HA HA!) you can get three of these $2.22 servo testers, which will do exactly what you want instantly. But where's the fun in that? :)

    http://www.ebay.com/itm/CCPM-Servo-Consistency-Master-Servo-tester-/140928657367?pt=US_Radio_Control_Control_Line&hash=item20d000a7d7#ht_2690wt_1208

    http://www.youtube.com/watch?v=t5AyBeMdtMk demo
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-04-10 19:11
    If you want to take the easy way out, you could use three of these servo testers. For the mark of the beast worth of pennies you'd be set.

    Edit: Dang you erco! You bet me by one minute. I may not have been as fast, but I think my reply was funnier (so there).:tongue:
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-04-10 19:20
    Yea, I bought a half dozen of them the first time @erco mentioned them. They work great.
  • mspicermspicer Posts: 8
    edited 2013-04-13 11:02
    Thanks everyone for your suggestions. For now, I'm trying to solve the problem using the MCP3204. I have the part wired on my board of education breadboard with two of the channels occupied by potentiometers. To begin, I modified the demo program to scale the results0 variables to between about 500 and 1000 for the first channel and then send pulses to a servo wired to P12 in the servo header. When I run the program, I can move the servo with the potentiometer. However, it twitches back and forth constantly when I'm not turning the knob, and I'm not sure why. I can see that the value of results0 and its scaled version remain constant in the debug window when I'm not touching the potentiometer.

    Any suggestions for getting my servo to turn more smoothly?

    Here's my code if that helps..,

    '
    [ I/O Definitions ]


    CS PIN 8 ' Chip Select (MCP3204.8)
    Clock PIN 11 ' Clock (MCP3204.11)
    DataOut PIN 4 ' Dout on ADC (MCP3204.10)
    DataIn PIN 6 ' Din on ADC (MCP3204.9)


    '
    [ Constants ]


    Cnts2Mv CON $0139 ' x 1.22 (To Millivolts)


    '
    [ Variables ]


    result0 VAR Word ' Conversion Result CH0
    result1 VAR Word ' Conversion Result CH1
    result2 VAR Word ' Conversion Result CH2
    result3 VAR Word ' Conversion Result CH3
    mVolts0 VAR Word ' Result0 --> mVolts
    mVolts1 VAR Word ' Result1 --> mVolts
    mVolts2 VAR Word ' Result2 --> mVolts
    mVolts3 VAR Word ' Result3 --> mVolts
    please VAR Word
    '
    [ Init Setup ]


    DEBUG CLS, "ADC CH 0 : ", CR, "Volts :", CR,
    "ADC CH 1 : ", CR, "Volts :", CR,
    "ADC CH 2 : ", CR, "Volts :", CR,
    "ADC CH 3 : ", CR, "Volts :", CR


    '
    [ Program Code ]


    DO


    LOW CS
    SHIFTOUT DataIn, Clock, MSBFIRST, [%11000\5 ] ' Select CH0, Single-Ended
    SHIFTIN DataOut, Clock, MSBPOST, [result0\13] ' Read ADC
    HIGH CS ' Disable ADC
    mVolts0 = result0 */ Cnts2Mv ' Convert To Millivolts


    LOW CS ' Enable ADC
    SHIFTOUT DataIn, Clock, MSBFIRST, [%11001\5] ' Select CH1, Single-Ended
    SHIFTIN DataOut, Clock, MSBPOST, [result1\13] ' Read ADC
    HIGH CS ' Disable ADC
    mVolts1 = result1 */ Cnts2Mv ' Convert To Millivolts


    LOW CS ' Enable ADC
    SHIFTOUT DataIn, Clock, MSBFIRST, [%11010\5] ' Select CH2, Single-Ended
    SHIFTIN DataOut, Clock, MSBPOST, [result2\13] ' Read ADC
    HIGH CS ' Disable ADC
    mVolts2 = result2 */ Cnts2Mv ' Convert To Millivolts


    LOW CS ' Enable ADC
    SHIFTOUT DataIn, Clock, MSBFIRST, [%11011\5] ' Select CH3, Single-Ended
    SHIFTIN DataOut, Clock, MSBPOST, [result3\13] ' Read ADC
    HIGH CS ' Disable ADC
    mVolts3 = result3 */ Cnts2Mv ' Convert To Millivolts


    DEBUG HOME, CRSRXY, 11, 0, DEC result0, CLREOL, ' Displays voltages & digital value
    CRSRXY, 11, 1, DEC mVolts0 DIG 3, ' for all four channels
    ".", DEC3 mVolts0,
    CRSRXY, 11, 2, DEC result1, CLREOL,
    CRSRXY, 11, 3, DEC mVolts1 DIG 3,
    ".", DEC3 mVolts1,
    CRSRXY, 11, 4, DEC result2, CLREOL,
    CRSRXY, 11, 5, DEC mVolts2 DIG 3,
    ".", DEC3 mVolts2,
    CRSRXY, 11, 6, DEC result3, CLREOL,
    CRSRXY, 11, 7, DEC mVolts3 DIG 3,
    ".", DEC3 mVolts3, CR, CR, CR
    GOSUB Send_Pulses
    PAUSE 100
    LOOP


    Send_Pulses:


    result0 = result0 */ 52
    result0 = result0 + 500
    PULSOUT 13, result0


    DEBUG DEC5 result0


    RETURN

    It may also be worth noting that nothing is connected to channels 2 or 3. Anyway, thanks again for the help!
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-04-13 11:17
    Your "PAUSE 100" is likely causing the problem.

    Each servo needs a pulse every 20ms in order to hold its position. You want time of each loop through your program to add up to 20ms and you want to make sure each servo gets pulsed each loop.

    I'm betting with your debug statements you don't need to add any pauses at all since your loop probably takes longer than 20ms without a delay. If the loop is just a little longer than 20ms, you shouldn't have a problem but if the loop takes a lot longer than 20ms, you may need to remove the debug statement.
  • mspicermspicer Posts: 8
    edited 2013-04-13 11:56
    I timed out my loops to 20ms and everything seems to be working fine now. Thanks for bearing with my beginner questions!
  • mspicermspicer Posts: 8
    edited 2013-04-14 10:18
    So I may have spoken too soon...

    I was able to control parallax standard servos from the What's a Microcontroller Kit using the MCP3204. However, the servos that I'm actually using for the project are Traxxas 2075 waterproof digital servos which came in today. When I swap in these servos to the same circuit ADC circuit in which the parallax servos were working, I get no response from them. When I run simple test programs, I can sometimes get them to turn but they seem to function very inconsistently.

    According its spec sheet (http://www.servodatabase.com/servo/traxxas/2075) the Traxxas 2075 should run on the same 6 VDC as the parallax standard servo (https://docs.google.com/viewer?url=http%3A%2F%2Fwww.parallax.com%2FPortals%2F0%2FDownloads%2Fdocs%2Fprod%2Fmotors%2F900-00005-StdServo-v2.2.pdf).

    Is it just that the pulse cycle and pulse width of the 2075 is different? If so, how would I find out what those values would be?
  • Mike GreenMike Green Posts: 23,101
    edited 2013-04-14 11:13
    The Traxxas servo should work essentially the same as the Parallax servo, operating from the same power supply and responding to the same control signals. Some servos may move over a slightly wider mechanical range or slightly smaller range for the same control pulse widths, but that's all you should be able to see. Check your connections and check your power supply.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-04-14 11:38
    The Traxxas servos have a lot more torque than the Parallax servos. While the communication requirements shouldn't be any different, you may need a more powerful power supply to keep them happy and to keep the uC from being reset when the servos start to move.
  • mspicermspicer Posts: 8
    edited 2013-04-14 18:41
    Thanks for the suggestions! I'll have on update on my progress tomorrow.
  • ercoerco Posts: 20,256
    edited 2013-04-14 21:09
    +1 to Duane's power comment. See www.futaba-rc.com/servos/digitalservos.pdf for Futaba's take on analog vs digital servos.
  • mspicermspicer Posts: 8
    edited 2013-04-15 13:58
    I'm continuing to have trouble with the traxxas 2075 servos. Since they are plugged into the Board of Education, I set the servo header to Vin to up the voltage. As my program was running, I measured a voltage of 7-8 volts across the red and black wires and across the white and red wires which should be more than enough according the spec sheet. I also unscrewed the servo casing and measured the same 7-8 volts on the actual contact points within the circuitry of the servo where the outside wires connect.

    Even though my connections and power source all seem to be fine, the servos do not so much as flinch when I turn the power switch to position 2. Yet, like I said, the parallax standard servos function completely fine when they are plugged into the exact same pins as the traxxas servos.

    One other thing I tried was to connect the red and black wires straight to the positive and negative terminals of a nine volt battery while wiring only the white wire to the BOE. When I did this and tried to turn the servo shaft, I definitely felt some resistance. But other than that, I can't seem to get these servos functioning. Is there any further testing I can do to determine what the problem is? Thanks again everyone for your advice!
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-04-15 14:50
    Are the Traxxas servos designed to take 7 or 8 volts? If not, they may be severely damaged by using that high of voltage.

    Servos can draw a lot of current as they start to move. This can cause the voltage to drop which can cause the uC to reset. You are unlikely to see this voltage drop with a multimeter.

    What are you using as a power source?

    I think a good power source for your servos would be four (maybe five) AA NiMH batteries. Many wall-wart power supplies don't provide enough current for servos. 9V batteries do not provide enough current for many/most servos.

    If you use a second power source for your servos you need to make sure the ground connections on both supplies are connected together.

    I hope your servos still work after your 9V experiment. IMO, it wasn't a good idea since 9V is too high of a voltage for the servo.

    BTW, We see lots of servo problems on the forum. Power supply issues are at the top of the list as the cause of the problem. It's also very common for the person looking for help to initially not believe it's a power supply issue.
  • mspicermspicer Posts: 8
    edited 2013-04-15 14:59
    Thanks Duane! Yeah, I think it's starting to look like I may have simply fried the servos like the beginner I am haha. I guess you live and learn. I'll try using four to five of those AA NiMH batteries.
Sign In or Register to comment.