Shop OBEX P1 Docs P2 Docs Learn Events
Servo Control — Parallax Forums

Servo Control

dcgalldcgall Posts: 3
edited 2010-08-06 17:15 in Robotics
I've got a simple servo issue. Please see the code below - when I run this code, my expectation is that the servo will rotate X degrees clockwise, then X degree counterclockwise (back to it's original position). What is happening is that it returns more to the counter-clockwise position so that it's ultimate rotation slowly rotates backwards. I'm new to this so I'd appreciate any help discovering what my issue is. thanks,

do
pulsout 12, 650
pause 10
pulsout 12, 850
pause 10
loop

Comments

  • ercoerco Posts: 20,256
    edited 2010-08-05 20:13
    It takes time and multiple identical pulsouts to get a servo to any particular position, you're only sending one to each position. Patience, my young Padawan!

    Try this:

    a:for b0=1 to 20 ' first loop 20X
    pulsout 12,650
    pause 20
    next' end first loop

    for b0=1 to 20' second loop 20X
    pulsout 12,850
    pause 20
    next' end second loop

    goto a'··········· lather, rinse, repeat

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • Martin_HMartin_H Posts: 4,051
    edited 2010-08-06 17:15
    The other thing you can do is ramp the servo by having the pulse value itself be the loop variable. So the code would look something like this:

    FOR Pulses = 650 TO 850 STEP 5
    PULSOUT Servo, Pulses
    PAUSE 20
    NEXT

    This results in smooth movement between 650 to 850.
Sign In or Register to comment.