Intro to Servomotor#
A servo is an actuator with a built-in control loop that tracks a command target, usually position.
This note introduces the core ideas behind servo-based robotic joints: command targets, angle feedback, motor selection, and basic closed-loop control.
Core ideas#
Command: the target position (or sometimes speed/torque) sent by the controller.
Feedback: measured output from an encoder or potentiometer.
Error: difference between command and measured output.
Control law: typically PID, converting error into motor drive.
Position and angle awareness#
Servo control quality depends on how accurately you track joint position and angle.
Absolute angle: current joint angle in degrees or radians relative to a known zero.
Incremental position: change in encoder counts since last sample.
Wrapped angle: angle mapped into a fixed range, usually \([-\pi, \pi]\) or \([0, 2\pi)\).
Joint limits: safe minimum and maximum angles enforced in software.
Typical conversion from encoder counts to angle is:
where \(c\) is current encoder count, \(c_0\) is zero-offset count, and \(N\) is counts per revolution.
Interactive illustration: Encoder Counts to Angle.
Use a homing or calibration step at startup so angle references are meaningful.
Basic control model#
The simplest position servo loop compares the target angle \(\theta_{\text{target}}\) with the measured angle \(\theta_{\text{measured}}\) and computes an error:
A standard PID-style controller uses:
where \(u(t)\) is the motor command and \(K_P\), \(K_I\), and \(K_D\) are proportional, integral, and derivative gains.
Proportional control reacts to present error.
Integral control removes steady-state bias.
Derivative control damps fast changes and can reduce overshoot.
Motor selection specs#
Use the following specification checklist when selecting a servo motor for a robotic joint:
Rated torque and peak torque: verify both continuous and transient load requirements.
Rated speed at load: check achievable speed under expected torque, not no-load speed only.
Voltage and current envelope: confirm supply compatibility, peak current, and startup current.
Thermal rating: validate continuous operation temperature and required cooling margin.
Gear ratio and backlash: balance torque multiplication with positioning precision.
Encoder resolution: ensure angle feedback resolution is sufficient for control accuracy.
Duty cycle: verify repetitive motion profile does not exceed continuous ratings.
Mounting and shaft interface: match frame size, flange pattern, and coupler constraints.
Environmental rating: include ingress protection, vibration tolerance, and humidity limits.
Communication/control interface: PWM, serial, CAN, or fieldbus compatibility with controller.
Common motor types for small-scale prototyping#
Type |
Typical torque range |
Control interface |
Notes |
|---|---|---|---|
Hobby RC servo |
0.1–3 N·m |
PWM (50 Hz) |
Self-contained gearbox and feedback; simplest integration |
DC brushed motor + encoder |
0.01–0.5 N·m (at shaft) |
PWM H-bridge |
Low cost, easy to drive; brushes wear over time |
Brushless DC (BLDC) + encoder |
0.05–2 N·m |
ESC or FOC driver |
Higher efficiency and lifespan; requires more complex driver |
Stepper motor |
0.05–1 N·m |
Step/direction or UART |
Open-loop positioning without encoder; can miss steps under overload |
Coreless DC motor |
< 0.1 N·m |
PWM H-bridge |
Very low inertia; suited for high-speed, light-load joints |
Geared DC motor (N20/TT) |
0.01–0.3 N·m |
PWM H-bridge |
Compact and inexpensive; common in tabletop and education robots |
Smart serial servo (e.g., Dynamixel) |
0.3–3.5 N·m |
RS-485 / TTL serial |
Integrated driver, encoder, and temperature sensing; daisy-chainable |
For prototype work, hobby RC servos and smart serial servos reduce wiring and driver complexity at the cost of some tunability. Brushed or brushless motors with separate drivers offer more control flexibility once the mechanical design is stable.
A common sizing rule is to target at least a 20% to 30% continuous torque margin over expected steady-state load, with higher margin for shock-loaded or high-acceleration motion.
Basic control code#
Example Python-style control loop for a position servo:
import math
import time
COUNTS_PER_REV = 4096
ZERO_OFFSET = 128
DT = 0.01
KP, KI, KD = 2.0, 0.4, 0.02
THETA_MIN = -math.radians(90)
THETA_MAX = math.radians(90)
CMD_MIN, CMD_MAX = -1.0, 1.0
integral = 0.0
prev_error = 0.0
def clamp(value, low, high):
return max(low, min(value, high))
def counts_to_angle(counts):
return 2.0 * math.pi * (counts - ZERO_OFFSET) / COUNTS_PER_REV
def angle_error(target, measured):
err = target - measured
return math.atan2(math.sin(err), math.cos(err))
while True:
target_theta = math.radians(30)
target_theta = clamp(target_theta, THETA_MIN, THETA_MAX)
encoder_counts = read_encoder_counts() # hardware-specific
theta = counts_to_angle(encoder_counts)
error = angle_error(target_theta, theta)
integral += error * DT
derivative = (error - prev_error) / DT
prev_error = error
command = KP * error + KI * integral + KD * derivative
command = clamp(command, CMD_MIN, CMD_MAX)
write_motor_command(command) # hardware-specific
time.sleep(DT)
Practical notes:
Keep angle commands inside mechanical joint limits.
Saturate the motor command so software cannot demand unsafe output.
Start with a low-gain controller and tune on a safe bench setup.
Add anti-windup logic if the actuator spends long periods at saturation.
Kinematics#
Once single-joint position control is stable, connect servo angles to end-effector pose through forward kinematics.
Joint space: vector of commanded angles.
Task space: Cartesian position and orientation.
Jacobian: local mapping between joint velocity and end-effector velocity.
Multi-axis coordination#
Once individual joints are stable, multi-axis systems need coordinated timing and trajectory management.
Synchronize loop timing across all axes.
Use trajectory profiles to limit jerk and reduce mechanical stress.
Watch accumulated latency across controller, bus, and actuator.
Reserve margin for coupled loads, especially when one joint carries another.