Notes on: Servos and controlling them - RichardChambers/raspberrypi GitHub Wiki

Notes on: Servos and controlling them

A servo is a device which contains an electrical motor with gears to rotate a shaft to a particular angular position. Two other components are used in the control of the servo shaft. A servo shaft position feedback circuitry determines the current angular position of the shaft. A servo shaft position request circuitry receives an analogue signal indicating a current desired shaft angular position in the form of periodic pulses whose width indicates the desired position.

The electrical motor of a servo is typically a small DC motor that has high RPM but low torque and gears are used to gear down the speed at which the servo shaft is turned by the motor while increasing the torque applied to the motion of rotating the shaft.

The servo shaft feedback circuitry for cheaper servos is normally in the form of a potentiometer attached to the servo shaft which indicates the current shaft position with a particular voltage level, from zero to the maximum reference voltage indicating where in the range of angular motion the shaft is currently positioned.

The servo shaft position request circuitry is connected to a source of pulses in which the pulses are repeated at 50 Hz or 50 times per second. The width of the pulse indicates the desired servo shaft angular position.

Within the servo there is circuitry which compares the servo shaft angular position as reported by the potentiometer against the requested shaft angular position as reported by the pulse width. A difference is reduced by using the motor of the servo to rotate the shaft in one direction or the other until the difference between the two signals, the potentiometer and the pulse circuitry is reduced to an acceptable amount of difference, the accuracy or allowable error factor of the positioning circuitry.

Different servos have different ranges of motion. The SG90 servo is a fairly standard component of most hobbyist kits and has a range of 180 degrees. The range of motion of different servos may vary and the method used to limit the range of motion may also vary from electrical devices to mechanical devices. The method used in the SG90 and many other servos is a physical limit stop built into the gears which is hit when the range limit is reached.

Control servo position with PWM signaling

Most servos require a steady 50 Hz input signal with a periodic pulse from low to high for a specified time and back to low. The width of the pulse, the amount of time the signal is high, indicates the rotational position of the shaft which is desired. As long as the pulse is seen 50 times a second with a specified width, the servo will maintain that shaft rotation position. If the width of the pulse changes then the shaft rotation position will be changed to match the position indicated by the new pulse width.

A servo may have a rotation angle limiter which may be a physical nub or stop in the gearing to limit the range of angular rotation available with the servo. The SG90 has such a rotation angle limiting stop.

Warning: Do not attempt to rotate the shaft of an SG90 outside of the range of -90 degrees to +90 degrees by using a pulse outside of the range of 1ms to 2ms. The SG90 is designed for a 180 degree arc.

Warning: Do not play with the servo shaft by rotating it by hand. You run the risk of rotating the shaft far enough that the limit stop is hit. If the limit stop is struck with sufficient force it can break off with the loose piece interfering with the servo gears.

Warning: A servo motor draws current based on the amount of work that it is doing and the amount of torque the motor is exerting to rotate the shaft. The current draw of an SG90 can easily exceed the limits of the power supply of a Raspberry Pi when the servo motor is rotating the servo shaft against a load. Doing so can cause the Raspberry Pi to fail.

Resources for further reading

Raspberry Pi StackExchange Control Hardware PWM frequency: https://raspberrypi.stackexchange.com/questions/4906/control-hardware-pwm-frequency

Raspberry Pi StackExchange Servo position with no pulse https://electronics.stackexchange.com/questions/68562/servo-position-with-no-pulse with an answer that has an interesting point:

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.

Servomechanism | Theory and Working Principle of Servo Motor: https://www.electrical4u.com/servo-motor-servo-mechanism-theory-and-working-principle/

Fundamentals of working with servos https://www.princeton.edu/~mae412/TEXT/NTRAK2002/292-302.pdf

RASPBERRY PI LESSON 28: CONTROLLING A SERVO ON RASPBERRY PI WITH PYTHON: http://www.toptechboy.com/raspberry-pi/raspberry-pi-lesson-28-controlling-a-servo-on-raspberry-pi-with-python/

Positioning servo design example http://www.me.unm.edu/~starr/design

Raspberry Pi and the IoT in C -- Pulse Width Modulation, Servos And More -- Controlling a Servo: https://www.iot-programmer.com/index.php/books/22-raspberry-pi-and-the-iot-in-c/chapters-raspberry-pi-and-the-iot-in-c/60-raspberry-pi-and-the-iot-in-c-pulse-width-modulation-servos-and-more?showall=&start=4