How robots follow trajectories, respond to disturbances, and interact safely with the physical world. From classical PID to modern optimal and adaptive control.
Robot control is the science of commanding a robot to perform desired motions while handling real-world disturbances: gravity, friction, payload changes, sensor noise, and model uncertainty. A controller computes the actuator commands (motor voltages, torques, or pressures) needed to track a desired trajectory or maintain a desired force/position relationship.
Given a desired trajectory q_d(t) (joint positions over time), the controller must compute torques tau(t) so that the actual joint positions q(t) track q_d(t) as closely as possible. The tracking error e(t) = q_d(t) - q(t) should converge to zero quickly, without oscillation, and stay bounded even under disturbances.
A standard feedback controller has: a reference signal r(t) (desired value), a plant (the robot), a sensor measuring the output y(t), and a controller C that computes the control signal u(t) based on the error e(t) = r(t) - y(t). The closed-loop transfer function is G_cl = C*G / (1 + C*G), where G is the plant transfer function.
A system is stable if, for any bounded input, the output remains bounded (BIBO stability). For linear systems, stability is determined by the poles of the closed-loop transfer function: all poles must have negative real parts (in the left half of the s-plane for continuous time, inside the unit circle for discrete time). Key analysis tools:
The Proportional-Integral-Derivative (PID) controller is the most widely used control algorithm in the world. Over 95% of industrial control loops use some form of PID. It computes the control signal as a weighted sum of three terms based on the tracking error.
The P term produces a control signal proportional to the current error: u_P = Kp * e(t). Higher Kp means faster response but can cause oscillation and instability. P-only control always has steady-state error for a constant disturbance (it needs a non-zero error to produce a non-zero output). In a robot joint, this is like a spring pulling toward the desired angle โ stiffer spring (higher Kp) = faster but more oscillatory.
The I term accumulates past errors: u_I = Ki * integral(e(t) dt). It eliminates steady-state error by building up a correction signal even for small persistent errors. Essential for compensating gravity in robot arms: without I, a joint under gravity load will sag to a position where the P term balances gravity, leaving a static error. The downside: too much Ki causes overshoot and slow oscillation ("integral windup").
The D term responds to the rate of change of error: u_D = Kd * de(t)/dt. It provides damping, anticipating the error trend and braking before the setpoint is reached. In robot control, this is viscous damping โ it opposes rapid joint motion. Essential for stability with high Kp. The practical challenge: differentiating a noisy signal amplifies noise. Real implementations use a filtered derivative (low-pass filter on the D term) or differentiate the measurement rather than the error.
| Gain | Rise Time | Overshoot | Settling Time | Steady-State Error |
|---|---|---|---|---|
| Increase Kp | Decreases | Increases | Small change | Decreases |
| Increase Ki | Decreases | Increases | Increases | Eliminates |
| Increase Kd | Small change | Decreases | Decreases | No effect |
For a robot joint with gravity compensation, PD control is often sufficient. The equation of motion for a single joint is: I*q'' + b*q' + mgl*sin(q) = tau. A PD controller with gravity feedforward gives:
The gravity term handles the static load; the PD terms handle trajectory tracking. This is Lyapunov-stable: the error converges to zero if the desired trajectory is constant (regulation), though tracking errors persist for time-varying trajectories.
// Discrete PID controller (runs every dt seconds)
error = setpoint - measurement;
integral += error * dt;
integral = clamp(integral, -max_integral, max_integral); // anti-windup
derivative = (error - prev_error) / dt;
derivative = alpha * derivative + (1-alpha) * prev_derivative; // filter
output = Kp * error + Ki * integral + Kd * derivative;
output = clamp(output, -max_output, max_output); // actuator saturation
prev_error = error;
prev_derivative = derivative;
Choosing Kp, Ki, and Kd values is an art informed by theory. Several systematic methods exist.
The classic tuning method, developed by John G. Ziegler and Nathaniel B. Nichols at Taylor Instruments. Two variants:
Oscillation method (closed-loop):
| Controller | Kp | Ki | Kd |
|---|---|---|---|
| P only | 0.5 * Ku | 0 | 0 |
| PI | 0.45 * Ku | 0.54 * Ku / Tu | 0 |
| PID | 0.6 * Ku | 1.2 * Ku / Tu | 0.075 * Ku * Tu |
This method produces an aggressive controller (quarter-decay ratio: ~25% overshoot). It is a starting point, not a final tuning. Real robots need refinement based on actual performance.
Step response method (open-loop):
A refinement of Ziegler-Nichols for processes with large dead time (L/T > 0.25). Uses the same step response measurements but different formulas that give less aggressive tuning.
Uses the ultimate gain Ku and period Tu like Ziegler-Nichols but with more conservative formulas: Kp = Ku/3.2, Ti = 2.2*Tu, Td = Tu/6.3. Produces less overshoot, commonly used in process control.
Design the controller by shaping the open-loop frequency response (Bode plot). Place the crossover frequency at the desired bandwidth, ensure adequate gain and phase margins. Loop shaping is the method of choice for sophisticated single-loop controllers and is taught in every graduate control course.
Modern industrial controllers (Siemens, ABB, Beckhoff) include auto-tuning: the controller automatically performs a relay test (oscillation method variant), identifies the process dynamics, and computes PID gains. Relay auto-tuning (introduced by Karl Astrom and Tore Hagglund in 1984) uses a relay (bang-bang) controller to induce oscillation at the ultimate frequency, which is safer than increasing gain to marginal stability.
State-space representation describes a system using first-order differential equations. It is more general than transfer functions (handles MIMO systems, nonlinear systems, and time-varying systems) and is the foundation for modern control.
where x is the state vector (dimension n), u is the input vector, y is the output vector, A is the system matrix (nxn), B is the input matrix, C is the output matrix, D is the feedthrough matrix (often zero).
A single revolute joint with motor inertia I, viscous friction b, and no gravity:
If all states are measurable, we can use u = -K*x + r, where K is a gain matrix. The closed-loop system becomes x_dot = (A - B*K)*x + B*r. The eigenvalues of (A - B*K) determine stability and performance. Pole placement: choose desired eigenvalues (closed-loop poles) and compute K using Ackermann's formula or the place() function in MATLAB/Python.
If not all states are directly measurable (e.g., velocity from position-only sensors), a state observer (Luenberger observer) estimates the full state from partial measurements:
The observer gain L is designed so that the estimation error converges quickly (observer poles faster than controller poles by a factor of 2-5x). The separation principle guarantees that observer and controller can be designed independently for linear systems.
LQR is the most elegant result in optimal control: it finds the state-feedback gain K that minimizes a quadratic cost function, balancing tracking performance against control effort.
Q (positive semi-definite) penalizes state deviations; R (positive definite) penalizes control effort. Large Q/R ratio = aggressive tracking. Small Q/R ratio = energy-efficient but slower.
The optimal gain is K = R^{-1} * B^T * P, where P is the unique positive-definite solution of the algebraic Riccati equation:
This is solved numerically by MATLAB's lqr(A,B,Q,R) or Python's scipy.linalg.solve_continuous_are(). The resulting closed-loop system is guaranteed stable (assuming controllability).
Also called inverse dynamics control or feedback linearization. This model-based approach uses knowledge of the robot dynamics to cancel nonlinear terms, then applies linear control on the linearized system.
The equations of motion for an n-DOF robot manipulator (Euler-Lagrange formulation):
where M(q) is the inertia matrix (nxn, symmetric, positive definite), C(q,q') contains Coriolis and centrifugal terms, g(q) is the gravity vector, and tau is the vector of joint torques.
Substituting into the dynamics equation, the nonlinear terms cancel exactly (assuming perfect model), leaving:
This is a linear, decoupled second-order system for each joint. Choose Kp and Kd to place poles as desired (e.g., critically damped: Kd = 2*sqrt(Kp)).
Adding a robust term to handle model uncertainty: tau = M_hat * (q_d'' + Kd*e' + Kp*e) + C_hat*q' + g_hat + u_robust, where u_robust is a sliding-mode or H-infinity term that bounds the effect of model errors. Spong (1992) and Slotine & Li (1991) provide thorough treatments.
MPC (also called receding-horizon control) is the most powerful framework for robot control when constraints matter. At each time step, it solves a finite-horizon optimal control problem online, applies the first control action, then re-solves at the next step.
Linear MPC (with quadratic cost and linear constraints) reduces to a Quadratic Program (QP), solvable in milliseconds with solvers like OSQP, qpOASES, or ECOS. Nonlinear MPC requires solving a Nonlinear Program (NLP) at each step โ much harder but feasible for moderate-dimensional systems using CasADi, ACADOS, or Crocoddyl.
| Library | Language | Specialty |
|---|---|---|
| ACADOS | C / Python | Fast NMPC, code generation for embedded |
| CasADi | C++ / Python / MATLAB | Symbolic framework for NLP formulation |
| Crocoddyl | C++ / Python | Contact-aware optimal control for legged robots |
| OSQP | C / Python | Fast QP solver for linear MPC |
Traditional position control commands the robot to a position and resists any deviation. But for contact tasks (assembly, polishing, human-robot interaction), the robot must comply with external forces rather than fight them. Impedance and admittance control define the dynamic relationship between force and displacement.
The robot behaves as a mass-spring-damper system: when pushed, it deflects proportionally. The desired impedance relationship is:
where M_d, B_d, K_d are the desired inertia, damping, and stiffness (chosen by the designer), and x_d is the reference trajectory. The controller computes joint torques to realize this dynamic relationship.
The inverse approach: measure external forces (via force/torque sensor) and compute position corrections. The admittance relationship is x - x_d = (1/Z) * F_ext, where Z is the impedance. Used when the inner loop is a stiff position controller (typical for industrial robots) and adding compliance on top.
| Aspect | Impedance Control | Admittance Control |
|---|---|---|
| Inner loop | Torque control | Position control |
| Sensor needed | Position/velocity | Force/torque sensor |
| Best for | Torque-controlled robots (KUKA iiwa, Franka Emika) | Position-controlled robots (UR, FANUC) |
| Free motion | Good tracking | Excellent tracking |
| Contact | Naturally compliant | Requires good force sensing |
Adaptive control adjusts controller parameters in real-time to compensate for unknown or changing system dynamics. Essential when the robot picks up unknown payloads, wears out over time, or operates in varying conditions.
Define a reference model that specifies the desired closed-loop behavior. The adaptive law adjusts controller gains so that the actual system tracks the reference model. Lyapunov-based design ensures stability. Used in aerospace (first practical application: X-15 flight control, 1960s).
The robot dynamics are linear in the dynamic parameters (masses, inertias, center of mass locations, friction coefficients): M(q)*q'' + C(q,q')*q' + g(q) = Y(q,q',q'')*theta, where Y is the regressor matrix and theta is the parameter vector. An adaptive law updates theta_hat based on tracking error:
where Gamma is a positive-definite adaptation gain matrix and s is a filtered tracking error. This guarantees convergence of the tracking error to zero even with unknown parameters. The result from Slotine and Li (1987) is one of the most important in adaptive robotics.
Inject a chirp signal (sine sweep from 0.1 Hz to 100 Hz) and measure the response. Plot gain and phase vs frequency. This gives the actual closed-loop bandwidth, identifies resonances (flexible modes), and validates that gain and phase margins are adequate. Every serious robot commissioning includes this step.
Chapters 8-12 cover joint-space control, task-space control, force control, and impedance control. The most complete treatment in one textbook.
The definitive reference for sliding mode control and adaptive control of robot manipulators. Chapter 9 covers adaptive robot control specifically.
Details the model predictive control approach for quadrupedal locomotion. Convex MPC with simplified dynamics model running at 30 Hz.
The original paper introducing the Ziegler-Nichols tuning rules. Published in Transactions of the ASME. One of the most cited papers in control engineering.
Chapter 11 covers robot control: PID, computed torque, motion/force control. Free PDF and companion Coursera course. Good blend of theory and practice.
Oussama Khatib's lectures on robot control, including operational space control (task-space dynamics control). The operational space formulation unifies motion and force control.