Study notes

Intro to Servomotor

Servo basics for robotic design: command, feedback, and control loop behavior.

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

Position and angle awareness

Servo control quality depends on how accurately you track joint position and angle.

Typical conversion from encoder counts to angle is:

θ = 2π c - c0N

where c is current encoder count, c0 is zero-offset count, and N is counts per revolution.

Interactive illustration: <a href="/science/interactive/ro/encoder-counts-to-angle">Encoder Counts to Angle</a>.

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 θ_{text{target}} with the measured angle θ_{text{measured}} and computes an error:

e = θ_{text{target}} - θ_{text{measured}}

A standard PID-style controller uses:

u(t) = KP e(t) + KI int e(t) dt + KD de(t)dt

where u(t) is the motor command and KP, KI, and KD are proportional, integral, and derivative gains.

Motor selection specs

Use the following specification checklist when selecting a servo motor for a robotic joint:

Common motor types for small-scale prototyping

TypeTypical torque rangeControl interfaceNotes
Hobby RC servo0.1–3 N·mPWM (50 Hz)Self-contained gearbox and feedback; simplest integration
DC brushed motor + encoder0.01–0.5 N·m (at shaft)PWM H-bridgeLow cost, easy to drive; brushes wear over time
Brushless DC (BLDC) + encoder0.05–2 N·mESC or FOC driverHigher efficiency and lifespan; requires more complex driver
Stepper motor0.05–1 N·mStep/direction or UARTOpen-loop positioning without encoder; can miss steps under overload
Coreless DC motor< 0.1 N·mPWM H-bridgeVery low inertia; suited for high-speed, light-load joints
Geared DC motor (N20/TT)0.01–0.3 N·mPWM H-bridgeCompact and inexpensive; common in tabletop and education robots
Smart serial servo (e.g., Dynamixel)0.3–3.5 N·mRS-485 / TTL serialIntegrated 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:

Kinematics

Once single-joint position control is stable, connect servo angles to end-effector pose through forward kinematics.

Multi-axis coordination

Once individual joints are stable, multi-axis systems need coordinated timing and trajectory management.

references