Servo programing
Thirteeneven
Posts: 11
hi
I just bought a parallax standard servo and board of education with a basic stamp 2 in it. I need to rotate clockwise 30 degrees and then rotate back counterclockwise 30 degrees what would be a good code for the Basic Stamp Editor
Thank you
Josh
I just bought a parallax standard servo and board of education with a basic stamp 2 in it. I need to rotate clockwise 30 degrees and then rotate back counterclockwise 30 degrees what would be a good code for the Basic Stamp Editor
Thank you
Josh
Comments
'Initialization
Temp··· VAR···· Word
Reset:
FOR temp = 200 TO 200························ 'Reset the cate to closed'
PULSOUT Servo_pin,temp
PAUSE 20
NEXT
Main:
IF (CloseGate = 1) THEN
FOR temp = Temp TO 200········ 'Use currently stored word for TEMP as starting point.
PULSOUT Servo_pin,temp
PAUSE 20
IF (interlock = 0)THEN············ 'Break the loop when the gate reaches the latch.'
Gate = 2
GOTO main
ENDIF
NEXT
ELSEIF (OpenGate = 1) THEN
FOR temp = Temp TO 700
PULSOUT Servo_pin,temp
PAUSE 20
IF (interlock = 0) AND (closegate = 1) THEN············ 'Break the loop if the BOT reaks INTERLOCK while gate is closing.'
gate = 2
GOTO main
ENDIF
NEXT
ENDIF
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tia'Shar Manetheren
DO
FOR counter = 500 TO 1000 STEP 20
PULSOUT 14, counter
PAUSE 20
DEBUG DEC5 counter, CR, CRSRUP
NEXT
FOR counter = 1000 TO 500 STEP 20
PULSOUT 14, counter
PAUSE 20
DEBUG DEC5 counter, CR, CRSRUP
NEXT
LOOP
With the step size you've got, there are 25 steps. That comes out to a total time of 1/2 second. That's not much for the servo to move through its mostly full range. You might try changing your step size to 10 rather than 20. That would allow a whole second for the movement.
From some quick math, that makes 166.666666 repeating for 30 degrees of rotation. Since the BS2 chip doesn't support values after the decimal point, you'll round off to either 166 or 167 (your choice, not much of a difference). This is the difference between your "FOR counter" values (e.g. 500 to 667), just look at Manetheren or dylants examples. Then, it's simply a matter of figuring out the pause values to make it move at the right rate between the two positions. 20 will lock the servo in position, while obviously smaller pauses tend to equal faster motion. Make sure to constantly test the servo motion as you add code, as the increase in processing seems to mess with the servo's motion.
I hope this can help to clarify what you're looking at. I'm not the most well-versed in this field, but I had to do a LOT of work with the servo for my final project.