Shop OBEX P1 Docs P2 Docs Learn Events
How do you control length of servo time? — Parallax Forums

How do you control length of servo time?

hmillerhmiller Posts: 17
edited 2011-07-09 20:54 in BASIC Stamp
When I go to run my servo, I find it very confusing that when I put "PULSOUT (pin #), 500" it goes clockwise, and then when i put "PULSOUT (pin #), 1000" it goes counter clockwise...

Why is this? is there any way to control the length of time i want it to run in the direction i want it to run also. I know this is probably a real noobie question.

Here's the code i'm using, (your probably getting sick of looking at my code mike lol):

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

DEBUG ? IN1

counter VAR Word


IF IN1 = 0 THEN


DEBUG "Vending...", CR

FOR counter = 1 TO 150
PULSOUT 2, 1000
PAUSE 20
NEXT

SEROUT 15, 84, [17, 22]
SEROUT 15, 84, ["vending..."]
PAUSE 3000
SEROUT 15, 84, [12]

SEROUT 15, 84, [17, 22]
SEROUT 15,84, ["Thank you!"]
PAUSE 5000
SEROUT 15, 84, [12]

DEBUG "Thank you!", CR

SEROUT 15, 84, [12]

ENDIF

Thanks!

Comments

  • $WMc%$WMc% Posts: 1,884
    edited 2011-07-09 20:47
    Take a look at Experiment# 26 in the Stamp Works manual.
    '
    http://www.parallax.com/Portals/0/Downloads/docs/books/sw/Web-SW-v2.1.pdf
    '
    Most servos use 1mSECONDs for full left. 1,5mS for stop or centered. A 2mS for full right.
    '
    But if you have already read the above download, You now this already.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-07-09 20:54
    You should read the Robotics with the BoeBot tutorial that you can download from Parallax. It has some good explanations of how servos work and how they're controlled from a Stamp. There's also a Wikipedia article on R/C servos and you should look at that.

    Essentially, the width of the control pulse controls the servo. If you have a standard servo, the control pulse specifies the desired end position of the servo. If you have a continuous motion servo, the control pulse specifies the speed and direction of the servo with 1.5ms (a PULSOUT of 750 on a BS2) being stopped and something like 1ms being full speed in one direction and 2ms being full speed in the other direction. For standard servos, the range is still roughly 1ms to 2ms corresponding roughly to 0 and 180 degrees. Some servos have a wider range (as much as 0.5ms to 2.5ms).

    You repeat the control pulse every 20ms for some period of time. For a standard servo, the time depends on how far the servo has to move from its old position to its new position. The FOR loop with the PAUSE provides the timing. In your program, the 150 x 20ms = about 3 seconds. If that's not long enough, you can change the FOR statement. Some fancy programs calculate how many pulses (at 20ms intervals) are necessary for the amount of movement expected. For this, you need to keep track of where the servo was at in addition to where it's supposed to go and you need to know how fast it moves.
Sign In or Register to comment.