Shop OBEX P1 Docs P2 Docs Learn Events
servo timer using BOE with stamp2 — Parallax Forums

servo timer using BOE with stamp2

kyle_artellekyle_artelle Posts: 3
edited 2008-04-30 17:45 in BASIC Stamp
Hello. I'm new at this, but what I'm trying to do is use my board of education (with stamp2) to control a servo motor. I want to be able to control how fast it goes back and forth (ie 30 Hz, or 60 Hz, or something along those lines).

I believe Parallax's 'servo controller' has a ramp function that does something like this, but I was wondering if I could just write code for stamp to do the same thing.

I realize this is a very basic project, but I can't seem to find any examples of it on the net.

Thanks
-Kyle

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-30 03:46
    You could write code for the Stamp to ramp the servo position.

    You have to put out a servo control pulse about every 20ms. Normally this is done with a FOR / NEXT loop. All you have to do is to increase (or decrease) the width of the servo pulse a little bit every 20ms until it reaches the position you want. The number of times through the loop determines how long the ramp takes (in 20ms increments).
  • kyle_artellekyle_artelle Posts: 3
    edited 2008-04-30 04:16
    Great.. I've got it oscillating, now I just need some tweaking. Right now my code looks like this:

    Start:
    FOR i=1 TO 30
    PULSOUT 15, 500
    PAUSE 20
    NEXT
    FOR i=1 TO 30
    PULSOUT 15, 1000
    PAUSE 20
    NEXT
    GOTO start

    Is there a way to change that so that I'm not using the i counter, but instead it changes direction once the servo actually reaches the given position? This is probably a pretty silly question, but does the servo send positional information back to the stamp?
  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-30 04:33
    There are some special digital servos that can provide position information, but they are completely different from standard or continuous motion servos which only receive control pulses from the Stamp.

    Realistically, there's no way for the Stamp to be able to find out when the servo reaches the desired position. I think it was Paul Baker who did some experimenting with servos where the motor was "starved" for power and the Stamp would watch how much current was drawn as the control pulse width was changed. At the control pulse width corresponding to the current servo position, the current drawn would drop. This could provide position feedback.
  • AmaralAmaral Posts: 176
    edited 2008-04-30 12:14
    For continuous rotation servos the loop is open from the stamp to servo and is a continuous loop from the servo(inside) to the shaft ! it just sends the signal and dont expect anything back.

    for your variation of the speed you could use something like:

    FOR i = 500 TO 1500 STEP 10 'look here that I use the STEP to make the change faster
    PULSOUT 15,i 'and here I use a VARiable to send the pulse lengh
    PAUSE 20
    NEXT


    I'm thinking that you are using a regular continuous rotatior servo, what did you mean by variating 30Hz to 60Hz ???


    Amaral
  • kyle_artellekyle_artelle Posts: 3
    edited 2008-04-30 17:31
    Thank you both for all your help on this.

    For Hertz I just mean the frequency that it oscillates at.. 30 to 60 Hz would be ridiculously fast.. but more like 0.5 or something. So the servo would oscillate 0.5 times per second.

    And it is just a normal hobby servo. I haven't modified it in any way.. its range is limited to about 180 degrees etc.
  • AmaralAmaral Posts: 176
    edited 2008-04-30 17:45
    Ok so this is not a continuous rotation servo.

    For that you can assume that the servo will go to the "ASKED" position, and untill this is not there it will keep trying (until is been asked) ! ( from the BS to the servo you have an open loop, but from the servo to the shaft it is a closed loop)

    There's no way for the servo to send an information that it reaches the destination , you will have to guess by the time that you are requesting it ! what kind of load are you moving with this servo ( or thinking in moving) ?

    Amaral
Sign In or Register to comment.