A servo interprets a 1ms pulse as far left, a 1.5ms pulse as centre and a 2ms pulse as far right, usually. But what if there is no pulse? Will a servo hold its position if it is just commanded once and never commanded again for a few minutes?
Electronic – Will a servo hold its position without a signal
servo
Related Solutions
A specific type of servo motor, a latching servo, is required for holding position after the control signal is removed.
Depending on the specific servo in use (see caveats below), an alternative "poor man's latching servo" can be implemented thus:
- Control the power supply line for the servo with a high side switch, either a P-MOSFET or for high power servos, an SSR.
- Low side switching is not suggested, as disconnecting the ground path may cause unpredictable behavior due to the control signal losing ground reference.
- After allowing the servo time to achieve desired position, disable the servo power before removing the control signal.
- For changing position, start the control signal, then enable power to the servo.
Caveats:
- The servo needs to be of a high reduction ratio / high torque type, so that small forces applied to the arm while it is unpowered, do not cause the arm to rotate.
- Not all servos can tolerate a control signal arriving while supply power is absent. While some will suffer damage to the internal electronics (not too likely), I have at least one servo that tries powering its motor from the control signal, ergo microcontroller pin damage.
Side Note:
Servo control signals are not actually PWM but a variant, pulse duration modulation: Servo position is not defined by the PWM duty cycle (i.e., ON vs OFF time) but only by the duration of the pulse. As long as it is anywhere in a range of (typically) 40 Hz to 200 Hz, the exact value of the frame rate is irrelevant. The servo expects to see a pulse every so many ms, this can vary within a wide range that differs from servo to servo.
This is relevant because the OP's requirement can be meet by generating consecutive pulses of desired durations for each driven servo, with a lot of flexibility in the time taken between a pulse for Servo A, and a pulse for Servo B, for example. The servos would thus be fed their control pulses in round Robin fashion.
As pointed out by Dave Tweed in comments, using the acronym PDM can be confusing, as that is also applied to Pulse Density Modulation, yet another special case variant of PWM.
Hobby servos are controlled by a pulse width, but this is not the same kind of pulse width modulation that is done by pi-blaster
.
Hobby servos use a periodic pulse at a relatively low rate (50 Hz is typical, but the rate is not critical). Each frame contains a nominal 1.5ms pulse to set the server at its nominal 0° position. Varying that pulse width from 0.5ms to 2.5ms moves the servo over its full mechanical range. If the servo is able to move 90° each way by varying the pulse width by up to 1ms, that is the same as 11.1 µs per degree.
So precise control of that servo requires high resolution control of that pulse, and a relatively long dead time to the next pulse.
PWM as done by pi-blaster
is designed to control power by adjusting a pulse from 0% to 100% duty cycle of a 100 Hz clock. To use this to control a hobby servo you need to start by turning the base clock frequency down to something in the 50 Hz ballpark. Some servos may accept control as fast as 100 Hz, but that isn't the usual practice.
Next, you need to limit yourself to the PWM range of 0.025 to 0.125, assuming a 50 Hz PWM clock.
The later limit means that of the default precision of 1000 steps from 0% to 100% duty, you can only use 100. For a 180° motion, that would give you a precision of 1.8° per step.
The better answer is to use software designed to control hobby servos. pi-blaster
notes that it was derived from ServoBlaster. Use that. It will be a little trickier to interface with because it is just a kernel driver and doesn't provide the slick ASCII FIFO.
One other caution: don't wire a hobby servo directly to your RPi. The RPi has 3.3V I/O, but the hobby servo will want to be driven at 5V or more. You should use a suitable level shifter to get the right drive voltage, and to introduce something less expensive than your entire RPi to burn out when something goes wrong.
Related Topic
- Electronic – Staggering PWM waveforms for servos to minimize current spikes
- Electronic – arduino – Checking the understanding of how hobby servo motors operate
- Best way to simultaneously control two servos positioned horizontally and vertically
- Servo does not rotate to the absolute minimum position
- Electronic – Controlling servo
Best Answer
It is very doubtful that it would stay in the same location.
The way I understand servo motors to work is that there is a constant feedback loop that is comparing the position to your pulse. Something like this:
To explain a bit more, the pulse is feed into what I called a low pass filter. It turns your pulse into a voltage that is in the range that the position sensor should also be outputting. It is also designed so that the voltage is maintained during your pulses 20ish ms off time. This voltage is then compared to the position sensor output. If they are equal then the motor doesn't need to run, but if they are different then the motor will run forward or backward to attempt to make the error be 0.
Now this is a very simplistic way of looking at a servo as most have more complicated control systems to insure stability with fast response, low overshoot, and high position accuracy.
There is a chance that there are servos out there that have "memory" of the last pulse so you don't have to keep sending it a pulse train, but none of the ones I have used do this.