Shop OBEX P1 Docs P2 Docs Learn Events
Servomotor [Help] — Parallax Forums

Servomotor [Help]

PivotnewbPivotnewb Posts: 18
edited 2011-09-28 23:14 in General Discussion
This is the first time I use Basic Stamp; but I have knowledge in other programming languages.
Well; what I'm trying to do is simply rotate the Servomotor for 15 seconds, Pause for 5 Seconds, then I need to rotate it in reverse for 10 seconds.
' {$STAMP BS2}
' {$PBASIC 2.5}
i VAR Word    'This is our counter'
i = 0         'Start it off at 0'

DO
i = i + 1     'Every time it loops add 1 to the counter'
IF i = 2  THEN    'If our counter reaches 2 then it ends the program'
GOTO finish
ENDIF
FOR i = 1 TO 1
PULSOUT 14, 250 'Rotate"
PAUSE 5000    'Pause for 5 seconds'
PULSOUT 14, 1250 'Rotate in reverse"
PAUSE 1000
NEXT
LOOP
finish:
END
That is what I came up with; however, I'm not sure if it's going to work or not yet; and I couldn't figure out how to work with the PULSOUT command that well yet as well as figure out how to make it rotate for a certain duration/direction.

Can I get some help here?

Cheers. :cool:

Comments

  • W9GFOW9GFO Posts: 4,010
    edited 2011-09-26 22:25
    Servos need the pulse to be sent at 50 times a second - one pulse every 20 milliseconds. What you are doing is sending one single pulse. If you want to rotate for 15 seconds, that would be 50 * 15 pulses.
    Forward_15_sec:
    
    FOR i = 1 to 750
    PULSOUT 14, 250
    Pause 19                  ' approx 1 millisecond is used in the FOR...NEXT loop and sending the pulse (PAUSE 20 is typically used for simplicity)
    NEXT
    
    RETURN
    
  • PivotnewbPivotnewb Posts: 18
    edited 2011-09-26 22:39
    W9GFO wrote: »
    Servos need the pulse to be sent at 50 times a second - one pulse every 20 milliseconds. What you are doing is sending one single pulse. If you want to rotate for 15 seconds, that would be 50 * 15 pulses.
    Forward_15_sec:
    
    FOR i = 1 to 750
    PULSOUT 14, 250
    Pause 19                  ' approx 1 millisecond is used in the FOR...NEXT loop and sending the pulse (PAUSE 20 is typically used for simplicity)
    NEXT
    
    RETURN
    

    Thank you for clarifying!
    How about rotating in reverse though?

    Would this work:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    i VAR Word
    DO
    Forward_15_sec:
    FOR i = 1 TO 750
    PULSOUT 14, 250
    PAUSE 20
    NEXT
    PAUSE 5000
    Backward_10_sec:
    FOR i = 1 TO 500
    PULSOUT 14, 1250
    PAUSE 20
    NEXT
    LOOP
    END
    
  • W9GFOW9GFO Posts: 4,010
    edited 2011-09-26 23:14
    That looks close. You should look up subroutines and the syntax for them.
  • PivotnewbPivotnewb Posts: 18
    edited 2011-09-26 23:18
    W9GFO wrote: »
    That looks close. You should look up subroutines and the syntax for them.

    Thank you for all your help!
    I appreciate it.

    Now how would this work if I were to try to Rotate "2" Servomotors at the same time?
  • Spiral_72Spiral_72 Posts: 791
    edited 2011-09-27 08:21
    Pivotnewb wrote: »
    Thank you for all your help!
    I appreciate it.

    Now how would this work if I were to try to Rotate "2" Servomotors at the same time?

    If they both need to go the same direction at the same time and speed, you'd just add the second servo on the same output pin :)

    If NOT, you could add a second PULSOUT for the second servo inside the loops. Keep in mind, the second PULSOUT takes time to execute, so you'll need to adjust your PAUSE time to compensate, correcting your freq back to 50Hz.
  • PivotnewbPivotnewb Posts: 18
    edited 2011-09-27 21:07
    Spiral_72 wrote: »
    If they both need to go the same direction at the same time and speed, you'd just add the second servo on the same output pin :)

    If NOT, you could add a second PULSOUT for the second servo inside the loops. Keep in mind, the second PULSOUT takes time to execute, so you'll need to adjust your PAUSE time to compensate, correcting your freq back to 50Hz.

    Thanks; I think that all I need to do for now is run them at the same time and speed.
    Thank you all for your help.
  • ercoerco Posts: 20,259
    edited 2011-09-28 22:21
    Continuous rotation servos, yes?
  • PivotnewbPivotnewb Posts: 18
    edited 2011-09-28 23:14
    Continuous rotation servos, yes?

    That is correct; but the problem here has been solved.
    Thank you anyway.
Sign In or Register to comment.