Servo Loop subroutine help
Cline
Posts: 36
Hello all,
I am having difficulty keeping a servo "powered" while the main program is running.
I have built a tracking camera on a tripod where pin 15 is rotation and pin 14 is elevation. It works well but the servos relax,
this is part of the camera program,
' Track and follow logic
IF Function = 3 THEN
· IF RCVData(2) > 65 AND RcvData(9) > 25 THEN RotateLeft
· IF RCVData(2) < 25 AND RcvData(9) > 25 THEN RotateRight
· IF RCVData(7) > 120 AND RcvData(9) > 25 THEN Bwd
· IF RCVData(7) < 60· AND RcvData(9) > 25 THEN Fwd
ENDIF
Example of the servo command,
RotateLeft:
· SHIFTOUT 4,8,LSBFIRST,[noparse][[/noparse]4]
· FOR n = 1 TO 10
··· PULSOUT 15,500 ' **
· NEXT
GOTO TopTrack
I am unsure how to have a subroutine run, also unsure of how to loop servo even if it is in different positions during the main tracking program
Thanks for all the help,
Ive attached the whole program,· If anyone can help me on loosing the other not needed functions. I want the camera to auto adjust light, then track the first color it sees,·without having to push any keys,(now i have to push the selection keys, and since i want it in the housing i cant push keys,,)· later hopefully i can tweak the tracking logic,,
thanks
Cline
CEO
ISS Corporation
I am having difficulty keeping a servo "powered" while the main program is running.
I have built a tracking camera on a tripod where pin 15 is rotation and pin 14 is elevation. It works well but the servos relax,
this is part of the camera program,
' Track and follow logic
IF Function = 3 THEN
· IF RCVData(2) > 65 AND RcvData(9) > 25 THEN RotateLeft
· IF RCVData(2) < 25 AND RcvData(9) > 25 THEN RotateRight
· IF RCVData(7) > 120 AND RcvData(9) > 25 THEN Bwd
· IF RCVData(7) < 60· AND RcvData(9) > 25 THEN Fwd
ENDIF
Example of the servo command,
RotateLeft:
· SHIFTOUT 4,8,LSBFIRST,[noparse][[/noparse]4]
· FOR n = 1 TO 10
··· PULSOUT 15,500 ' **
· NEXT
GOTO TopTrack
I am unsure how to have a subroutine run, also unsure of how to loop servo even if it is in different positions during the main tracking program
Thanks for all the help,
Ive attached the whole program,· If anyone can help me on loosing the other not needed functions. I want the camera to auto adjust light, then track the first color it sees,·without having to push any keys,(now i have to push the selection keys, and since i want it in the housing i cant push keys,,)· later hopefully i can tweak the tracking logic,,
thanks
Cline
CEO
ISS Corporation
Comments
Typically your problem is solved by having a 'ServoPos' variable, which is adjusted by your program. Then, you have a subroutine:
ServoRefresh:
PULSOUT RotServoPin, RotServoPos
PULSOUT ElevServoPin, ElevServoPos
RETURN
which 'refreshes' the servo positions to the servos. Then, you insure that you:
GOSUB ServoRefresh
Every 20 mSec or so. This serves both to 'refresh' the servos with the current position, or to send the 'new' position to the servos if "ServoPos" has been changed since the last time.
http://forums.parallax.com/showthread.php?p=612786
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support