Let's Make Robots!

Servos going to first position in a violent way.

This is an open question on the problem of the violent twitch/swing servos have when they are first turned on and when they get their first position command. The obvious answer is to always finish a "session" by centering all your servos and then turning off, but this assumes that nothing is going to get bumped or creep out of "centered" while waiting for the next time it will be turned on. One could also center all the servos by hand (with the servo unpowered) but I have never cared for moving servos by hand if I can avoid it.

So the question is: How can you get your servos from "off" to "first position" without that full-speed, violent swing?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I intentially stayed out of this conversation. I have to admit, I sorta had an answer in my head when I asked and so when I started seeing some of the anwers coming in, I kept my mouth shut --mostly because some of the answers were A) a lot better than what I had and B) probably would work (as my idea would probably not have). I think we have enough here so we can start on test beds... I will get a test set-up and start seeing if anything will work in real life. I will keep you up with any results. Thanks bunches guys.

Here is the perfect solution:

http://www.pololu.com/catalog/product/2111

This is a step down switching voltage regulator (I wish they would make one for 6V output) that is capable of supplying 7A. But the most interesting fact is that it has an Enable pin that will actually turn On or Off the output! So, send your PWM pulses to the servos, then Enable the regulator and Bingo! The servos will not violently move at start, unless of course, they are way out of position. But that can be dealt in software.

P.S. I made a product suggestion on their forum, a similar regulator with 6V output for servo use. I hope they will make it soon!

I think the root of your question is "if the servo moves while the system is off, how can a violent swing be avoided?"  You definately need a sensor connected to your servo such as a potentiometer.  Read the pot value using an ADC and interpolate as a PWM value.  I also found this servo hack to add feedback to a standard servo using the servo's internal potentiometer:

http://www.instructables.com/id/Servo-Feedback-Hack-free/

Would it help to slowly ramp up the servo supply voltage after MCU booted? Would it be possible even? Using PWM?  Would the servo's own controller be bothered by 3 V where 6V was expected?

This is a possible solution which I suspect may work better for some servos than others.  However I think it would be healthy to give this a try CtC.  A lower voltage will result in a slower speed, so only give the servos half the voltage at startup.  Question remains if this might damage the servo.

Maybe this is not the issue Chris is describing, but my problem with servos on initial power up is that they get power before they receive any command from the micro. This often results in the servo jerking to an extreme position during power up. I REALLY see this problem on the Picaxe during software download to the micro. I often hold down the reset button until the PC has started the download, and then release the reset button to avoid the problem.

A separate power switch for the servos (maybe for the motors too, just for convenience) would help with this scenario. Another solution might be a variation of the Power On Reset (POR) circuit, which would delay power for the servos for a second or two while the micro boots up.

I realize this might not directly address CtC's question, but it is sort of related so I included it.

I have the same problem with my MiniEric robot. But I make sure the servos get back to the home position after every move, so at shutdown they are in the proper place. But, at power up, they jolt, sometimes a bit, sometimes a lot. Then they receive the home position signal and rush to get there with the risk of tearing the gears if something is caught in the way. I have a few servos broken this way.

The solution I was thinking was to have a relay that will switch power on to servos after the home position signal was issued by the controller, so the servos will not jolt randomly. But the relay will consume power, so I am looking to get a Reed relay or something like that, provided its contacts support some high amperage (about 8-10A) at 6V for the servos. Perhaps this one, that has a coil that works at 5V and needs 10mA (so it can be tied directly to a microcontroller pin) and supports 0.5A at 200V (16A at 6V). (Remember, some Reed relays have a built in clamping diode, if not, you must use an external fast switching diode in parallel with its contacts.) However, this solution does not account for the servos being out of home position at shutdown.

A software solution, as it was already suggested, is to write the servo positions in EEPROM, but there are only a limited number of writes to this memory, so I try to avoid it, that's why I try to get the servos in the home position every time after a move. If something goes wrong, I have to manually move them. This would not work with a hexapod or humanoid that get easily out of position when not powered. Oh well, perhaps you guys will figure something out...

I see there three different types of solutions, a hardware solution, a couple of software solutions and a hybrid solution.  As with all solutions, your mileage may vary depending on skills, luck and Mr Murphy.

The hardware solution would be to put a potentiometer, varistor, encoder of some sort, or other sensor on the servo to send back the position of the servo to the microcontroller.  If you know the present position you can increment to the 'home' or 'start' position, with the presumption that your sensor is correct of course.  This involves using hardware and software, hardware to sense the position and software to decide what to do about it.

The software solution comes with it's own caveats of course. Yes, software is cheaper but has it's own drawbacks when it's only used.  There are two different solutions that can be used singularly or combined with each other and/or with the hardware solution aforementioned as well.  My personal recommendation would be to implement the hardware solution with the second software solution, since the first software solution is mainly a virtual version of the hardware solution to an extent.

The first software solution would be to keep track of the the last position sent and write it to an SD or an EEPROM. During the init function/procedure these values would be read from the card or chip and the servos slowly incremented to their home positions.  This goes along with the presumption of course that between shutdown and restart that nothing or nobody has physically moved the servo or what it's attached to change it's position, of course. If the servo has been turned from an extreme compared to it's last saved position and has a load on it that is more than half it's recommended max load, you could kill some gear teeth. I would suggest hardening up the servo with brass gears or such if you go this route.

Now for the second software solution, which is the one that I prefer of the two, which is basically a shutdown procedure. This one has two major caveats, one which is that the robot shuts itself down and the other is that the robot doesn't suddenly lose power to it's servos.  This would also mean that the on/off switch is a soft switch, ie a sensor that tells the robot that a human or other outside physical entity wants the robot to shut down, and upon sensing such the robot starts a shutdown procedure, i.e. moving all it's servos to their home position, etc.  Think of the robots in movies as they shut down when the master controller is destroyed or they are shut off.

Alas, we come upon the hybrid solution which is a combination of the hardware solution and the second software solution. Some might think that including both software solutions with the hardware solution would be ideal, but if you are gathering data of the present position and comparing it with the last known position and doing nothing with it, then you are wasting code, space and your time. With this solution the robot should go into a shutdown mode, and if it doesn't the microcontroller knows what positions the servos are currently in and can increment them to either their home positions or their next position.  

As with all solutions, there are drawbacks and caveats and should take in consideration the variables and environment of which the problem occurs.  Remember, if it's hailing you might need more than an umbrella if you are outside and if you bandaid a problem instead of fixing it, then it will be still be healthy to make more problems than if you had spayed/neutered it the first time.

MechGeek out

P.S. This post has been brought to you by lack of sleep and pyrat rum and coke lol.

Use "liveshow" for questions you want mentioned on the live show!

I see two challenges with this problem:

  1. The power to the servo comes before the PWM signal.
  2. The position or necessary PWM value must be known so the proper PWM signal can be applied.

If there was a delay in powering the servo such as through a relay or transistor switch, problem 1 could be avoided by initializing the MCU and setting the PWM signal before enabling power to the servo.

If the last used PWM value is stored in non-volatile memory it can be accessed again when the MCU starts.  This value can set the PWM Hopefully need.  If this doesn't work there would need to be a way to obtain the position of the servo, calculate the corresponding servo position PWM signal, and set that value.

I don't think they normall move on powerdown, but I could be wrong.  This will require either a special power switch, or a way to sense depleting power when a power switch is turned off (using an ADC).  A capacitor large enough should be used to give sufficient time for the PWM value to be saved in memory.  Hope my 2 cents can help solve this problem.