Shop OBEX P1 Docs P2 Docs Learn Events
Having trouble with servo control — Parallax Forums

Having trouble with servo control

skatjskatj Posts: 88
edited 2008-01-11 01:22 in BASIC Stamp
I need to move a servo a very very short distance forward, and then make the horn go back up to its original position, and keep doing that every 50 seconds. (it's to push a digital camera shutter button)

I wrote the program to input pulse duration and number of pulses so I ran many trials and I still can't figure out how those two variables relate to servo position. (The book is a little vague)

Here's what I kinda concluded so far:
Long duration (close to 1,000) = Shorter distance traveled?
Low number of pulses (1-100) also = Shorter distance traveled
Short duration (close to 500) = Horn turns a full 180 degrees.
High number of pulses (300+) = Servo attempts to rotate beyond its limit
Pause 20 = No idea what happens if I change this


If I pulse a servo to move, can I always make it go to a set position (i.e., a certain combination of duration and pulse number will ALWAYS make a servo move to 12 0 clock, regardless if its current position). Or, do the pulses make it move to a location that is relative to its current location? (for example, if will always move 45 degrees left of where it currently is)


I still can't figure out how to make it go backwards. Can someone help me out, I'm totally lost here shocked.gif

I'm using the Parallax standard servo, BS2, and BOE development board Rev C.

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-12-30 12:46
    skatj -

    Although standard R/C servos may APPEAR to operate in two directions (forward and reverse), they don't in reality. They will operate clockwise and counter-clockwise around a CENTER POINT, thus making them APPEAR to be truly reversible.

    An R/C servo responds to positive going pulses from 1.0 to 2.0 ms in width. Thus, the "center point" is defined around a pulse duration of approximately 1.5 ms in width. This may vary slightly servo to servo, but should be near that point. Anything less than that, the servo will move one side of center, and anything more, the other side of center.

    An R/C servo will also not maintian its position unless it is told to do so. Every pulse meant to maintain a servo in a given position MUST occur EVERY 20 ms or sooner. Barring receipt of such a pulse, the servo will return to the extreme-most direction, closest to the 1.0 ms side.

    The PBASIC command to cause this pulse to occur is PULSOUT. PULSOUT needs the pin port number, and the width of the pulse to operate correctly. In PBASIC the pulse width is determined in units of time. The units of time differ between the various Stamp models. Check the PBASIC Reference Manual, or the PBASIC Help File for the appropriate time unit for the particular Stamp you are using.

    I suspect you may have been using the PWM command which is NOT appropriate for this usage. PULSOUT is what you need here.

    All that being said, if this were my project, I'd consider using a miniature DC solenoid to operate the shutter button, such as the one shown at the link below, rather than using an R/C servo, but that's just me. Such a solenoid would need to be driven by an external transistor, and NOT directly from a Stamp pin port, due to the current requirements.

    http://www.allelectronics.com/cgi-bin/item/SOL-102/search/MINIATURE_12VDC_PUSH-TYPE_SOLENOID_.html

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • sdysdy Posts: 40
    edited 2007-12-30 16:23
    This will make your horn sweep from one end to the other:


    FOR Position= 350 TO 1150 STEP 200
    FOR x = 0 TO 5
    PULSOUT Servo, Position
    PAUSE 20
    NEXT
    NEXT
  • skatjskatj Posts: 88
    edited 2007-12-30 21:02
    Brucebates - Thanks for the explanation about the pulse times, I am indeed using PULSOUT, but I did not know about the relation of pulse time to servo position.


    Alright couple things, thanks for the code but I also wanna learn how it works
    sdy said...

    FOR Position= 350 TO 1150 STEP 200
    FOR x = 0 TO 5
    PULSOUT Servo, Position
    PAUSE 20
    NEXT
    NEXT
    I am a little confused, what are the two for loops for? From what I can tell, the outer loop runs four times, where each time it does five pulses for a certain duration. I assume the position is specified by me, right?
  • FranklinFranklin Posts: 4,747
    edited 2007-12-30 21:24
    The inner loop is to give the servo time to get to the desired position. The outer loop sweeps the servo as a demonstration and you would set the value of the pulsout position to get the position you wanted. This value will to some extent be a guess that you will need to adjust for the exact position you want because all servos are a bit different.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • slamerslamer Posts: 52
    edited 2007-12-31 01:44
    If you wish for the servo to go to the same predictable position everytime. You should consider using the PSC servo control board it will take care of the timing and original position and the desired position problem for you.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    undefinedundefinedundefinedundefinedSteven Kirk Nelson (slamer)

    Team K.I.S.S
    Build Safe, Build Mean, Build Strong!
  • Wolverine69Wolverine69 Posts: 31
    edited 2008-01-11 01:09
    Sdy,

    · I noticed that you have min. & max.·values for the servo positions of 350 & 1150.· I was working with my new BASIC Stamp Discovery Kit for the first time today, and noticed that while the servo will physically·sweep more than 180 degrees if I move it by hand, it will only move about 90 degrees using PULSOUT duration values of 1000· & 500.

    · Those two duration values should correspond to 1 & 2 msec respectively and command the servo to it's max. CCW & CW sweep postions should it not?

    · By experimenting with the duration values I was able to make the servo sweep 180 degrees and ended up with values close to what you have in the code that you posted.
    sdy said...
    This will make your horn sweep from one end to the other:


    FOR Position= 350 TO 1150 STEP 200
    FOR x = 0 TO 5
    PULSOUT Servo, Position
    PAUSE 20
    NEXT
    NEXT
  • Mike GreenMike Green Posts: 23,101
    edited 2008-01-11 01:22
    As mentioned, the "official" range of servo pulses is 1ms to 2ms. There's a lot of variation from servo to servo and from manufacturer to manufacturer. Best thing to do is to test your particular servo to see what the actual range is. On the BS2, the PULSOUT value is based on 2us units so 1ms to 2ms is a value from 500 to 1000. Try values as low as 300 and as high as 1200. If the servo bumps up against its mechanical stop, stop the program and change the lowest or highest value until the servo goes over its full range.
Sign In or Register to comment.