Shop OBEX P1 Docs P2 Docs Learn Events
Servo Loop subroutine help — Parallax Forums

Servo Loop subroutine help

ClineCline Posts: 36
edited 2006-11-01 20:19 in BASIC Stamp
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

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2006-11-01 14:35
    The 'servo' control signal is a 1 to 2 mSec pulse, repeated every 20 mS to 50 mSec. The 1 to 2 mSec represents the desired position of the servo, and the 'refresh' is done to insure the servo holds position.

    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.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-11-01 20:19
    This is a duplicate post...Please see the original at the following link.

    http://forums.parallax.com/showthread.php?p=612786

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.