Shop OBEX P1 Docs P2 Docs Learn Events
Servo stops in different place depending on travel direction — Parallax Forums

Servo stops in different place depending on travel direction

The DoctorThe Doctor Posts: 37
edited 2007-08-25 12:18 in Robotics
I am trying to get a servo to stop in the center of it's travel.· Assuming 180 degrees, I want the servo to stop at 90.· The servo is connected to pin 14 of a basic stamp, and I am using this routine:

X·VAR Byte
FOR·X = 1 TO 20
···· PULSOUT 14, 720
···· PAUSE 20
NEXT

What happens is this - If the servo is traveling counter-clockwise, the above·routine will stop it right at 90 degrees.· However, if the server is traveling clockwise, it will stop about 95 degrees.· I have to change the PULSOUT duration to 800 to get the servo to stop at 90 when traveling clockwise, but that will make it stop about 85 when traveling counter-clockwise.

Tried this with two separate servos, one a Futaba and one an Airtronics.··I also tried varying the pause statement.· Same result.· Any idea what would cause this, and how I can compensate for it?

confused.gif·confused.gifconfused.gifconfused.gif
«1

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-08-19 19:02
    Depending on where the servo is starting, twenty times through the loop may not be enough. That said, however, all mechanical linkages exhibit backlash. Compounding this, there's likely to be some hysteresis (electronic "backlash") in the servo's logic that keeps it from constantly correcting when it's "close enough" to its target. The solution would be to position the servo to one known position, say 820, then move it to 720. That way you will always be approaching the target location from the same direction.

    If you really need to end up at the target without any overshoot in either direction, then you need to compute the amount of backlash in your servo ('sounds like about 80) and use this as a compensating factor when you change the direction of movement.

    There's nothing wrong with your servos or the electronics. Backlash and hysteresis are a fact of life that we just have to deal with. For something that costs less than $20, five degrees really isn't all that bad.

    -Phil
  • The DoctorThe Doctor Posts: 37
    edited 2007-08-19 20:42
    Sorry to disagree with you, PhiPi, but when using servos like this in a remote controlled airplane, the movements are always precise, regardless of what direction the servo is moving. If what you are saying about backlash and hysteresis were true, it would be impossible to trim an airplane for level flight. Since I fly R/C, and I have trimmed airplanes for level flight, I must therefore assume that the error is in your statement.

    Any other ideas?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-08-19 21:55
    A couple things come to mind:

    1. When you're trimming the control surfaces, you're making adjustments with the transmitter by hand. It could be that you're compensating for any backlash/hysteresis subconsciously. It seems reasonable that having to deal with the actual numbers makes manifest a condition of which you were heretofore unaware. You can test this theory by using your BASIC Stamp and PULSIN to measure the pulse widths going to the servo as you trim from both directions.

    2. In flight, the servos that operate the control surfaces are acting against aerodynamic forces, not just flapping around without resistance. This extra force may be enough to take up and counteract any inherent slack in the total system linkage. You can test this theory with your BASIC Stamp servo by attaching a rubberband to the servo horn to keep tension on it. Then run your experiment again.

    I might be completely off base, and it won't be the first time (or the last), but at least now you have a way to verify it one way or the other.

    One other thing you could try, to make your scenario more similar to trimming an RC plane, is to change the pulse width gradually to reach the target value, rather than just setting to that value all at once.

    -Phil
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-08-19 22:51
    A couple other things worth checking:

    1. What battery voltage do your RC servos operate from? If it's more than 5V, you might try to match that with your BASIC Stamp servo to see if it helps. If a servo is close to its destination, it will be merely "tickling" the motor to nudge it into position. If the battery voltage is too low, that tickling may be ineffective.

    2. What is the relative quality/cost of your Stamp servo vs. your RC servo? Some servos are simply built better than others. The RC enthusiasts I know spare no cost in getting the lightest, highest precision servos they can get their hands on. You might try controlling one of your RC servos with the Stamp to see if behaves better than the one you're trying to use.

    -Phil
  • LilDiLilDi Posts: 229
    edited 2007-08-20 00:09
    Doc,
    A couple of things here. PULSOUT is different, depending on which Stamp you are using. The BS1 is 10 microseconds for each unit. The BS2, BS2e,BSpe its 2 microseconds per unit. The BS2sx, BS2p, Bs2px its 0.8 microseconds per unit.

    Servos maximum angle of travel is about 90 degrees, not 180 degrees. The pulse width must be between 1 millisecond and 2 milliseconds. 1 millisecond being one maxumum end of travel and 2 milliseconds being the other max end of travel.

    If you have the BS2 then PULSOUT 14, 500 is a 1 ms pulse width and PULSOUT 14, 1000 is a 2 ms pulse width. In this example, you will need to keep the PULSOUT statement between those values.

    Finally, you should have a LOW 14 statement ahead of any PULSOUT statement to ensure the pulse is positive going.
  • FranklinFranklin Posts: 4,747
    edited 2007-08-20 00:10
    Doc, if you have onr of those airplane servos you could try it with the stamp and see if it in fact more preceise.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • D FaustD Faust Posts: 608
    edited 2007-08-20 00:54
    I'm sorry if somebody else already posted this, but I think PhiPi's first thought of the servo being farther away and the loop not running enough.
    Try:
    X VAR Byte
    DO
         PULSOUT 14, 720
         PAUSE 20
    LOOP
    
    

    If this works, then that was your problem.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    LOOKDOWN ThisThread, [noparse][[/noparse]Your_?, My_?, Cool_Thing], looknum
    LOOKUP looknum, [noparse][[/noparse]1, 2, 3], subnum
    ON subnum GOTO Hope_this_helps, Thanks!, WOW!!
    END 
    
  • LilDiLilDi Posts: 229
    edited 2007-08-20 01:44
    I don't understand this loop business. A single 1.5 millisecond positive going pulse will command the servo to the center position. If the servo is under a heavy load, the pulse should be every 20 ms to keep the load from pulling the servo out of position.
    Is there something I'm missing here?
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-08-20 02:22
    No, a "single 1.5 mSec positive pulse" will NOT move the servo to the commanded position (unless it's a digital servo). It takes multiple repetitions of a 1.5 mSec positive pulse, repeated every 20 mSec, to reach the commanded position. The exact number of repetitions depends on where the servo was before you commanded it to center position.

    Otherwise, you are correct, having REACHED the center position, if it's not under load, and you stop giving it pulses, it won't move out of that position. But that's a different situation from expecting it to reach center position in the first place with one pulse. It really can't move very far in 20 mSec.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-08-20 02:58
    I think LILDI is correct for a standard servo, mainly using a loop would be to increment its position·to control its speed at attaining a position.·Sending only one pulse is as fast as you get. For a continuous rotation servo then generally the command is in a loop.

    Jeff T

    EDIT looking at the specs for the standard servo it states 1.5sec to travel 180 deg so one pulse may move the servo very quickly ,close , but probably not to the intended position hence a loop.

    Post Edited (Unsoundcode) : 8/20/2007 3:09:39 AM GMT
  • LilDiLilDi Posts: 229
    edited 2007-08-20 03:06
    I just read 4 articles about digital vs analog servos. Every article says the same thing. They behave the same way. The differences are in torque, speed and current draw. internally they are differences, but thats behind the·scene and·not anything for the outside world be be concerned about.
  • D FaustD Faust Posts: 608
    edited 2007-08-20 13:35
    If the servo turns 180 deg. and takes 1.5 sec to move that 180 deg (as unsoundcode posted) then it would take about·38 loops to travel from all the way one direction to the center.· I also have read a few things on digital vs. analog servos and have not found a difference in how pulses are sent, just the torque they produce.· Where is "The Doctor"?· A test with the code·I posted and the set-up of "The Doctor" will determine if·the value of "X" (from the original code)·is the problem.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    LOOKDOWN ThisThread, [noparse][[/noparse]Your_?, My_?, Cool_Thing], looknum
    LOOKUP looknum, [noparse][[/noparse]1, 2, 3], subnum
    ON subnum GOTO Hope_this_helps, Thanks!, WOW!!
    END 
    
  • The DoctorThe Doctor Posts: 37
    edited 2007-08-20 14:42
    Sorry about the absence, folks. The Doc is back.

    PhiPi, when trimming a servo, you are simply adjusting the center position of the POT in the transmitter to center the servo when the control stick is centered. There is no "unconcious" adjustments going on. Once trimmed, whether I move the control stick up or down, moving the servo either clockwise or counter-clockwise, when I center the stick the servo returns to center.

    PhiPi, the servos run at either 4.8V or 6V depending on if you are using NiCad or Alkaline batteries. My testing is being done at 5V.

    PhiPi & Franklin, this is one of my aircraft servos. I commandered parts from an unused plane to build this.

    LILDI, this is a BS2, so my 720 is 1.44 MS. Also, a standard servo will turn a little over 1/2 circle from one extreme to the other, which is 180 degrees.

    D Faust, no, it is not a timing issue. Even if I increase the number of time through the loop to 40, I still get the differing positions depending on servo travel direction.

    Good discussion, folks. Any other ideas?
  • D FaustD Faust Posts: 608
    edited 2007-08-20 14:51
    Do you have any standard parallax servos?· If so, you should try the same program with one of them connected to see if your problem is in the servo or programming.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    LOOKDOWN ThisThread, [noparse][[/noparse]Your_?, My_?, Cool_Thing], looknum
    LOOKUP looknum, [noparse][[/noparse]1, 2, 3], subnum
    ON subnum GOTO Hope_this_helps, Thanks!, WOW!!
    END 
    
  • The DoctorThe Doctor Posts: 37
    edited 2007-08-20 15:00
    No, I do not have any standard Parallax servos, but as previously mentioned I tried this with two different servos and go the same result on both.
  • D FaustD Faust Posts: 608
    edited 2007-08-20 15:19
    Okay, I'm stumped.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    LOOKDOWN ThisThread, [noparse][[/noparse]Your_?, My_?, Cool_Thing], looknum
    LOOKUP looknum, [noparse][[/noparse]1, 2, 3], subnum
    ON subnum GOTO Hope_this_helps, Thanks!, WOW!!
    END 
    
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-08-20 16:29
    Compensating with code is not difficult if that is what it takes

    Joy_stick_left:
    pulse_value=720
    GOSUB move_servo

    Joy_stick_right:
    pulse_value=800
    GOSUB move_servo

    move_servo:
    PULSOUT,14,pulse_value

    put the pulsout in a loop that·gives the desired effect

    Jeff T.
  • The DoctorThe Doctor Posts: 37
    edited 2007-08-20 16:42
    I am trying to avoid having to compensate with code. I take it nobody else has observed this behavior?
  • MightorMightor Posts: 338
    edited 2007-08-20 16:52
    The Doctor said...
    I am trying to avoid having to compensate with code. I take it nobody else has observed this behavior?
    I must say, I have seen something similar with my radar module programmed in SPIN. This graph shows it quite clearly. You can ignore the last two graphs in the series, they're averages. The odd ranges are values taken by the PING))) sensor when the servo was moving from right to left and the even ones from left to right. You can see a serious shift. The pulses sent to the servos are static and defined in an array which is merely traversed from right to left or left to right, depending on the direction.

    attachment.php?attachmentid=48800

    Gr,
    Mightor

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    | To know recursion, you must first know recursion.
    483 x 290 - 20K
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-08-20 17:04
    I think to center the servo you should be using a pulse of 750 the two extremes are 500 and 1000.

    Jeff T
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-08-20 22:02
    Doc,

    I tried your experiment using a Parallax servo and the following code:

    ' {$STAMP BS2pe}
    ' {$PBASIC 2.5}
    
    servo PIN 8
    
    DO
      FOR B0 = 1 TO 50
        PULSOUT servo, 1000
        PAUSE 20
      NEXT
      FOR B0 = 1 TO 100
        PULSOUT servo, 750
        PAUSE 20
      NEXT
      FOR B0 = 1 TO 50
        PULSOUT servo, 500
        PAUSE 20
      NEXT
      FOR B0 = 1 TO 100
        PULSOUT servo, 750
        PAUSE 20
      NEXT
    LOOP
    
    
    


    Attached is a movie of the result. Short story: I don't see what you're observing.

    What, exactly, are you using for servo power? I know you said 5V, but at what current capacity, and how is it being filtered? Can you measure the voltage as the servo is moving or, better yet, observe it on a 'scope?

    -Phil
    _____________________________________________

    P.S. Mightor, were the readings you've graphed taken with the servo in motion? Or stopped at each station? It will make a difference, independent of the servo's characteristics, for two reasons:

    1. If in motion, there will be a delay between the pulse width you're sending and the servo reaching that position.
    2. There's an additional delay for the echo to return.

    Both will conspire to make the commanded angle seem different from the actual angle.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-08-20 23:40
    Thats impressively acurate for a less than $13 servo. The thing that crossed my mind earlier was what effect would it have if believing the center to be at 720 you were trying to drive the servo 90 deg to either side of that point. One direction is going to be hard against the mechanical stop. Is it possible for the pot to get misaligned when this happens?

    Jeff T.
  • The DoctorThe Doctor Posts: 37
    edited 2007-08-21 10:44
    PhiPi, excellent test! One thing I noticed, however, is that when your servo was travelling counter-clockwise, it would actually travel slightly beyond the center point, then rotate back to center.

    I will try your code as-is when I get home tonight and let you know what I find.

    On an additional note, I was reading through one of my other robotics books last night and found a note about Futaba servos, stating that Futaba used a 1.5 ms pulse width instead of a 2.0 ms. Anyone out there working with Futaba servos that can test PhiPi's code?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-08-21 17:12
    I'm not sure what you mean by "instead of a 2.0 ms". Every servo I've ever seen uses 1.5mS for the center position. Also, by the way, Parallax's servos (like the one I used) are made under private label by Futaba.

    -Phil
  • The DoctorThe Doctor Posts: 37
    edited 2007-08-22 10:07
    Well, after extending the loop count to 100, I got the servo to center traveling both ways. Like in PhiPi's video, the servo travels beyond the center point then returns, only mine is much more pronounced. I will try to get a video today.

    PhiPi, I will quote the appropriate passage this afternoon.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-08-22 19:11
    Doc,

    You probably wouldn't see the bounce-back if you approached the stopping point with pulse widths that ramp to the destination, rather than sending the destination pulse widths from the start.

    -Phil
  • LilDiLilDi Posts: 229
    edited 2007-08-22 19:59
    I wanted to thank all of you people for educating me about servos. You have busted some myths I held about servos. This has been a really great discussion.

    One more question/myth about servos. Shouldn't the servo slow down on its own as it approaches its destination from a far away position?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-08-22 20:49
    It would be hard for a servo to know by what rate to slow down, since it has no way of knowing (without a really fancy self-tuning PID controller) what kind of static and inertial loads it's moving. To keep the cost down, this chore is left as as exercise for the user.

    -Phil
  • The DoctorThe Doctor Posts: 37
    edited 2007-08-22 21:23
    Regarding the statement I made earlier regarding Futaba servos, this is a quote from "123 Robotics Experiments for the Evil Genius" by Myke Predko, copyright 2004, which is the book that got me started in robotics.· It states:

    "I am assuming you are going to use standard and not Futaba servos.· Standard servos are controlled by a 1 ms to 2 ms pulse (with 1.5 being the center), whereas Futaba servos are controlled by a 1 ms to 1.5 ms pulse.· If you are using Futaba servos with the application, make sure you change the data values accordingly."

    My Futaba servos, however, do not agree with this.· I am wondering if anyone else has more details, or if Myke was wrong in this statement?

    Attached is my test video using the following code:
    '·{$STAMP·BS2}
    '·{$PBASIC·2.5}

    servo·PIN·8

    DO
    ··FOR·B0·=·1·TO·50
    ····PULSOUT·servo,·1000
    ····PAUSE·20
    ··NEXT
    ··FOR·B0·=·1·TO·100
    ····PULSOUT·servo,·750
    ····PAUSE·20
    ··NEXT
    ··FOR·B0·=·1·TO·50
    ····PULSOUT·servo,·500
    ····PAUSE·20
    ··NEXT
    ··FOR·B0·=·1·TO·100
    ····PULSOUT·servo,·750
    ····PAUSE·20
    ··NEXT
    LOOP
    Note that this is PhiPi's earlier code, just modified for a BS2.· Note how my servo travels beyond it's stop point then comes back, but only when traveling counter-clockwise.· Also notice that although I am using the supposed full range of 1 to 2 ms, the servo only travels a total of 90 degrees.· I have to increase the up side to 1200, and the down side to 360, to get a full 180 degrees.· And, once·I do that,·I am back to the servo not returning to the same place· depending on travel direction.· I even tried raising the loop count to 200.· There is an obvious pause, so I know the loop is long enough.

    PhiPi, in your earlier video I noticed your servo only traveling 90 degrees, 45 each way.· You were using the code you posted, right?· What happens if you lower your numbers below 500 or above 1000?· Do you get longer travel?· Do you still hit center both ways?
  • D FaustD Faust Posts: 608
    edited 2007-08-22 21:32
    I think that the servo for my ping (parallax servo) travels the 180 deg with a 1048 pulse and 452 (on a BS2). Center still seemed to be reached. As for what LILDI said, I thought servos do slow down when getting closer to their final position. That is what gives you speed control with a CR one. My guess for why the overshoot occurs is because the servo only notices that it reached its desire point when it went to far. I am not sure, just guessing.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    LOOKDOWN ThisThread, [noparse][[/noparse]Your_?, My_?, Cool_Thing], looknum
    LOOKUP looknum, [noparse][[/noparse]1, 2, 3], subnum
    ON subnum GOTO Hope_this_helps, Thanks!, WOW!!
    END 
    
Sign In or Register to comment.