servo programming
jdnphoto
Posts: 5
Can anyone tell me if there is a way of programming a servo to change position by one increment each time through a loop. Example first time through loop pulsout 14, 750 next time through loop pulsout 14, 800 and so on until loop is completed by counting. Thanks for you help.
Comments
FOR i = 750 TO 2000 STEP 50
PULSOUT 14,i
PAUSE 20
NEXT i
Here is part of my program so you can see the total picture. Please look at the "'TILT"
PULSOUT HB25D, 500 + 129 ' FORWARD MOTION
PAUSE 20
PULSOUT HB25H, 500 + 50 ' UP MOTION
PAUSE 20
SEROUT 10, BAUD, ["[E159}"] ' ROTATE
GOSUB CHECKBUSY2
PAUSE 10
CHECKBUSY2:
PAUSE 10
CB_LOOP2:
IF IN8 = 1 THEN CB_LOOP2
PAUSE 100
FOR TiltPrevPosition = 750 TO 1000 STEP 4 'TILT
PULSOUT 15, TiltPrevPosition
NEXT
PAUSE 3000
LOOP UNTIL (COUNTER = 62)
Routine2:
DEBUG "Routine 2 is running", CR
'
Initialization
DO: LOOP UNTIL HB25D = 1 'Wait for HB25 Power up
LOW HB25D 'Make I/Opin Output/Low
PAUSE 5 'Wait for HB25 to Initialize
PULSOUT HB25D, 750 'Stop Motor 1
'
Initialization HB25H
DO: LOOP UNTIL HB25H = 1 'Wait for HB25 Power up
LOW HB25H 'Make I/Opin Output/Low
PAUSE 5 'Wait for HB25 to Initialize
PULSOUT HB25H, 750 'Stop Motor 2
PAUSE 1000
'
Program Code
UpCounter = 0
DO
UpCounter = UpCounter + 1
PULSOUT HB25D, 500 + 129 'Forward 1/4"
PAUSE 5000
PULSOUT HB25H, 500 + 50 'Up 1/2"
PAUSE 5000
SEROUT 10, baud, ["{E-150}"] 'Rotate
GOSUB checkbusy2
PAUSE 5000
checkbusy2:
PAUSE 10
CB_loop2:
IF IN8 = 1 THEN CB_loop2
PAUSE 100
FOR TiltPrevPosition = 750 TO 1000 STEP 4
PULSOUT Tilt, TiltPrevPosition 'Tilt
PAUSE 5000
NEXT
DEBUG BELL
PAUSE 3000 'Hold for 3 seconds
LOOP UNTIL (UpCounter = 62)
GOSUB Routine3:
Your existing FOR loop won't work particularly well. You have a PAUSE 5000 in the loop which means that the servo will get one control pulse every 5 seconds. That won't work. Servos need control pulses every 20ms or they'll shut themselves off. That causes mechanical jitter and slippage.
I think you need to back up and talk about what your program is supposed to do. Go back to a flowchart or some similar sort of diagram, even a written list of actions and when they occur.