[2] a TowerPro micro servo motor, often used in Arduino robotic projects
[2] a TowerPro micro servo motor, often used in Arduino robotic projects
[1] A servomotor (or servo motor or just servo) is a rotary or linear actuator allowing precise angular/linear position control, velocity, and acceleration in mechanical systems, constituted part of a servomechanism, and consists of a motor coupled to a sensor (for position feedback) and a controller (often a dedicated module designed for servos).
[3] A servos is used for precise controls, via a controller. In contrast to a DC or other motors, which spin constantly with voltage applied, a servo's position is controlled via a controller or program to precisely adjust the its position via a signal applied.
[3]
[D1]
[3] A servo is protected by its main housing with often wires of orange (output connection), red (positive connection), and brown (negative connection) colors, but varies from manufacturers.
The orange wire can connect to a microntrollers like ESP32 or Arduino to be controlled through codes.
[3]
[D1]
[3] A servo has a splined gear at its top which attaches to another component like a horn.
A gear train on the inside outputs the force to the splined gear
splined (mechanical engineering): shaft/gear with ridges/teeth (splines) parallel along its length
The potentiometer is the position sensor that provides real-time feedback of the shaft's position.
[4] A gear train reduces the RPM and increase the motor's torque.
[D1]
[D1] The applied DC signal is sent to the control unit's comparator amplifier IC (integrated circuit) to control the DC or AC motor (depending on the applied voltage used).
The control unit comprises of:
The pulse width disciminator/monostable multivibrator, which translates the control signal (a PWM pulse) often from a micontroller into a proportional internal DC voltage.
The comparator/error amplifier, which compares the reference voltage (often a PWM signal) which carries the target position against the feedback voltage from the output shaft potentiometer. I.e., these are the inputs to the comparator. The comparator then outputs a DC/AC signal motor to correct the position.
The H-bridge/motor drive stage converts the error output from the comaprator into directional DC current to drive the motor left/right til the position error drops to zero.
The control unit (using the comparator) compares the motor's current position (provided by the potentiometer connected to the output shaft) to the target position (represented as the inputted voltage signal) to detect the error offsets.
[4] At the servo's motor shaft's initial position, the potentiometer's position knob is such that there is no electrical signal generated at the potentiometer output port. Now, an electric signal is given to another input terminal of the error detector amplifier. Now in the difference between 2 signals, one comes from the potentiometer and the other from other sources, is processed in a feedback mechanism, and the output is given as error signals, which serves as the motor's input, and the motor starts rotating
[4] Now the motor shaft connects to the potentiometer, and as it rotates so the potentiometer will generate signals.
As the potentiometer’s angular position changes, its output feedback signal changes. After some time, the position of the potentiometer reaches a position where the output of the potentiometer is the same as the external signal provided. Under these conditions, there will be no output signal from the amplifier to the motor input, as there is no difference between the externally applied signal and the signal generated at the potentiometer, and in this situation motor stops rotating.
[D1] 2 signal types of a controller are:
The setpoint signal is the desired/target position, speed, and torque being sent as a voltage signal to the comparator from the output shaft.
The feedback signal is the (either analog or digital) signal provided from the potentiometer, which connects to connects to the output shaft, being the actual desired positoin, torque, and speed of the output shaft.
Control signal A servo motor is controlled by a PWM control signal, specifically the signal's duty cycle or high pulse width. The signal's period is always 20 ms or 50 Hz.
The motor is driven at its center (default) position of 90° at 1.5 ms.
At 0° or its leftmost position at 0.5 ms.
At 180° or its rightmost position at 2.5 ms.
A PID algorithm control can process the error signal by generating a control signal to determine and adjust the actual motor specifications.
Anything in PID control centers on the error (e(t)), the difference between the output shaft's actual position (process variable (PV)) and the desired position (setpoint): e(t) = SP - PV
The PID controller calculates 3 terms based on this error and sums them up to determine the total motor drive signal u(t):
u(t) = Kp · e(t) + Ki ∫e(t)dt + Kd · de(t)/dt, where
Kp · e(t) = present error:
P produces an output directly proportional to how far away the servo is from its target. If the error is large, P applies a strong voltage to turn the motor quickly. As the motor gets closer to the target, P decreases so the motor slows down.
Limitation: Pure P-control often suffers from Steady-State Error (the motor stops just short of the target because the remaining error is too small to overcome friction) or overshoot if Kp is too high.
Ki ∫e(t)dt = past accumulation: I sums the error over time even if the error is tiny as long as it persists terms increases. This eliminates Steady-State Error. If the servo gets stuck 1° away from its target due to heavy mechanical load or friction, the I term accumulates over milliseconds until the combined force pushes the shaft into exact alignment. The limitation is that too much integral action causes Integral Windup and severe overshoot/oscillation.
Kd · de(t)/dt = future trend: D looks at how fast the error is changing (rate of change/velocity). It acts as an electronic brake or damper. If the servo is moving toward its target at high speed, the error is decreasing rapidly, so D produces a negative force to decelerate the motor before it overshoots the target.Limitation: D is sensitive to high-frequency sensor noise, which can cause jitter if not filtered properly.
[D1] A servo's controller also implements various control algorithms, like like PID (proportional-integral derivative) control, fuzzy logic control, adaptive control, to optimize its motor performance.
[3] This 25 kg servo can apply 25 kg to a lever.
[3]
Weight [3] A servo often has a weight value indicating its torque, i.e., how much force it can apply on an object of certain weight (not the weight of the component itself).
The weight can also be displayed in units of weight per length, like kg-cm or oz-in, which indicates that for each length of a value of one of that unit, that weight can be applied. E.g., a 25 kg servo applies 25 kg on 1 cm, 25/2 = 12.5 kg on 2 cm, or 25/3 = 8.33 kg on 3 cm.
[3] The higher voltage applied to a servo, the higher torque is given.
[3] E.g., this servo's datasheet indicates a safe voltage range of 4.8 to 7.2 V, where it can push 9 kg-cm at 4.8 and and will stall at 2.5 A and 6 V.
The
Note: The stall torque isnt' a voltage limit, but the max mechanical force the motor produces under a heavy load at a given voltage.
[3] A servo's physical size increases with its torque rating due to larger internal gears and motors to achieve this.
[3]
[3] A servo can be used in robotics, automations, and steerings ofo remote cars.
[3] Most servos rotate only 180°, which uses an internal pin to block it from moving any further, called closed loop types, which more often used and have the best controls. Those that rotate 360° are open loop types.
Many languages control servo motors, like Python, Java, Ladder Logic, C++, or C language. Any language that can generate a Pulse Width Modulation (PWM) signal or communicate with a microcontroller/driver board can operate a servo.
Programming through C language can furthermore done in Arduino microcontroller and IDE, an open-source hardware and software ecosystem.
Exclusive functions to control/read the state of/configure a Servo in Arduino By dowloading the Servo library in the Arduino IDE and including it it in the program (having '#include <Servo.h>' at the top), the following functions are provided and be used to control the intended servo.
Servo <Servo name>: We must include this at the top of the program to configure the name of the servo to be used beside the functions to control the servo, separated by only a dot.
E.g., if Servo myServo; is used, we must write myServo.attach();, or myServo.write();, or myServo.writeMicroseconds(); throughout the program.
The attach() function links the servo to the physical signal pin on the Arduino microntroller. It must be inside the setup() function in Arduino IDE.
Syntax: myServo.attach(pin) or myServo.attach(pin, min, max)
pin: The digital pin number connected to the servo signal wire.
min(optional): The pulse width in microseconds corresponding to 0° (defaults to 544).
max (optional): The pulse width in microseconds corresponding to 180° (defaults to 2400).
The write(angle) function is most common one commanding the motor's position.
For positional servos, such servos accept an integer from 0-180°.
For continuous rotation servos, these servos treat values below 90° as full-speed reverse, 90° as stopped, and values above 90° as full-speed forward.
E.g., myservo.write(90); //Moves to 90° (center position) (or stop continuous servo)
The writeMicroseconds(value) controls a servo's position/speed by specifying the control pulse width in microseconds IO in degrees, providing accurate granular adjustments standard degree integers can't achieve. Standard servos often accept pulse width of 544-2400 µs, where:
[5]
0° (far left): 544 µs or 1000 µs (1 ms)
90° (center): 1500 µs (1.5 ms)
180° (far right): 2400-2000 µs (2.4 ms)
E.g., myservo.writeMicroseconds(1500); // Standard midpoint pulse width
Advantages Higher precision: write(angle) is restricted to integer values of 0-180° , giving only 181 precision steps. Whereas, writeMicroseconds() allows to control a servo across 1800 individual microsecond steps, providing smoother, continuous, fine-grained movements.
Direct hardware control: Bypasses any internal degree-to-microsecond scaling calculations, eliminating rounding errors.
E.g., suppose the following program:
#include <Servo.h>
Servo myServo;
void setup() {
myServo.attach(9); // Attaches the servo on pin 9
}
void loop() {
// Move to center position (1500 us = ~90 degrees) for 1 s
myServo.writeMicroseconds(1500);
delay(1000);
//Then does fine adjustments (e.g., precise 90.5-degree equivalent) for 1 s
myServo.writeMicroseconds(1505);
delay(1000);
}
The read() function reads the servo's current logical angle. Note that this doesn't read the hardware's physical feedback; it pulls the last successfully written value from the Arduino's memory buffer.
E.g., int currentAngle = myservo.read();
The attached() returns true if the specific servo instance is currently assigned to an active pin, and false if it is unassigned. Helpful for debugging dynamic setups.
Note: Some first lines of the program are omitted.
int Angle[24] = { 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40 }; //24 arrays are used to command the sequence the servo must control its which angle it'll position at
void setup() {
Serial.begin(9600);
delay(300);
pinMode(TRIGGER_PIN, OUTPUT);
pinMode(8, OUTPUT);
myservo.attach(22);
}
void loop() {
for (int a = 0; a < 24; a++) {// starts servo at 0° (via "a = 0;"), then increments angle value by 1 (via "a++;") as long as the angle is under 24° (via "a < 24") - the for() function is active as long as the condition in its bracket is true
myservo.write(Angle[a]);// actively updates angle through line 1's array value
digitalWrite(26, HIGH);
delayMicroseconds(10);
digitalWrite(26, LOW);
duration = pulseIn(27, HIGH);
distance = duration / 2.0 * 0.0343;
Serial.print(millis());
Serial.print("\t");
Serial.println(distance, 1);
delay(50);// it takes 50.01 ms (delayMicroseconds(10); for 10 µs plus delay(50) for 50 ms) for servo to turn from a position to another, thus taking 50.01ms * 2 steps = 100.02 ms to turn from 30 to 40° (0° to 30°, then 30° to 40°), and taking 50.01ms * 24 steps *2 = 2350.47 ms or 2.4 s
if (distance > 22)
digitalWrite(8, HIGH);
if (distance < 15) {
digitalWrite(8, LOW);
}
}
}
Note: We don't need to omit one less step from the total number of steps before multiplying each duration between 2 angles since note that the servo first moves from 0 to 30°, not starting from 30° then turning to 40°.
If the servo motor were to scan from 30 to 150° and back to 30°, then it'll take:
From 30 to 150°, there are 13 array values.
50.01ms * 13 arrays = 650.13 ms or 0.65 s