Robotics
← Roadmap/Control & Motion

Control Theory (PID / LQR / MPC)

Making the robot actually do what you want.

Progress0/5 questions
hardControl & MotionSkip to practice questions ↓

Prerequisites

Why it matters in robotics

Control turns a planned trajectory or desired state into stable, executable motor commands, so it sits under everything that moves: arms, drones, legged robots, and self-driving stacks. A feedback loop tuned from error, its accumulation, and its rate of change is the workhorse, one method gives mathematically optimal gains for well-behaved linear systems, and another earns its extra compute by planning ahead while respecting constraints like joint limits, obstacles, and actuator saturation. The math of stability and cost functions connects directly to practical failure modes such as runaway accumulated error, steady-state error, and model mismatch.

What to study

  • Geometric path-tracking controllers: Pure Pursuit (lookahead-point curvature law) and the Stanley controller (cross-track + heading error law) — simple, model-light alternatives to full feedback control
  • PID fundamentals: P/I/D terms, tuning intuition, steady-state error, and integrator anti-windup
  • State-space modeling and stability: poles/eigenvalues, controllability/observability, pole placement
  • LQR as optimal full-state feedback: the quadratic cost, Q/R weighting tradeoffs, and the Riccati equation
  • MPC: receding-horizon optimization, handling state/input constraints, and the cost of online computation

Where to study

Cheatsheet

Symbols used below

eeerror (setpoint minus measured value)
Kp,Ki,KdK_p, K_i, K_dproportional, integral, derivative gains
uucontrol input
xxstate vector
A,BA, Bstate-space system matrices (x˙=Ax+Bu\dot x = Ax+Bu)
KKfeedback gain matrix
Q,RQ, Rstate and input cost weighting matrices
PPsolution to the Riccati equation
LdL_dlookahead distance (Pure Pursuit)
α\alphaangle from vehicle heading to the lookahead point
κ\kappacommanded path curvature
LLvehicle wheelbase (bicycle model)
δ\deltafront-wheel steering angle
θe\theta_eheading error (Stanley)
kkStanley gain (scalar — distinct from the feedback gain matrix KK)
vvvehicle speed

Stanley controller (geometric control)

δ=θe+arctan ⁣(kev)\delta = \theta_e + \arctan\!\left(\dfrac{k\,e}{v}\right)

The first term aligns the heading with the path's tangent; the second steers proportionally to the cross-track error ee, softened by speed vv. A bigger gain kk corrects harder but risks oscillation, and the term jumps sharply as v0v \to 0.

Pure Pursuit (geometric control)

κ=2sinαLd\kappa = \dfrac{2\sin\alpha}{L_d}

Fit a circular arc from the vehicle to a lookahead point a distance LdL_d ahead on the path; α\alpha is the angle between the vehicle's heading and the line to that point. For a bicycle model, the steering angle is δ=arctan ⁣(2LsinαLd)\delta = \arctan\!\left(\dfrac{2L\sin\alpha}{L_d}\right).

A larger LdL_d smooths the path but cuts corners; a smaller LdL_d tracks tighter but can oscillate, especially at speed.

PID control law

u(t)=Kpe(t)+Ki0te(t)dt+Kdde(t)dtu(t) = K_p e(t) + K_i \displaystyle\int_0^t e(t')\,dt' + K_d \dfrac{de(t)}{dt}

P reacts to current error, I eliminates steady-state error by accumulating it over time, D damps overshoot by reacting to the error's rate of change.

Integrator windup

If the actuator saturates, the integral term keeps accumulating error it can't act on, then overshoots badly once the actuator unsaturates.

Anti-windup clamps or back-calculates the integral term so it stops growing while the actuator is saturated.

State-space and stability

x˙=Ax+Bu\dot x = Ax + Bu

The system is stable (state decays to zero with no input) exactly when every eigenvalue of AA has negative real part. Controllability asks whether some input can drive the state anywhere; observability asks whether the state can be reconstructed from the outputs alone.

LQR: optimal state feedback

Minimize the quadratic cost J=0(xQx+uRu)dtJ = \displaystyle\int_0^\infty \big(x^\top Q x + u^\top R u\big)\,dt

subject to x˙=Ax+Bu\dot x = Ax+Bu. The optimal control is linear state feedback u=Kxu = -Kx, with K=R1BPK = R^{-1}B^\top P where PP solves the algebraic Riccati equation. QQ penalizes state error, RR penalizes control effort — their ratio sets how aggressive vs. gentle the resulting controller is.

MPC: constrained, receding-horizon control

At each step, solve a finite-horizon optimization for the best sequence of future controls given the current state, apply only the first control, then re-solve at the next step with updated measurements.

Unlike PID or LQR, MPC can directly enforce constraints (joint limits, obstacle avoidance, actuator saturation) inside the optimization — at the cost of solving an optimization problem online, every control cycle.

Σsetpoint rKpKi ∫Kd d/dtΣPlantoutput ymeasured output (feedback)
In a PID loop the integral term accumulates error over time, so it keeps driving the actuator until steady-state error reaches zero — P and D alone cannot remove a constant offset.
 GeometricPIDLQRMPC
Model neededVehicle kinematics only (bicycle model)None (pure feedback on error)Linear state-space modelModel (often linear or linearized), re-solved online
OptimalityNone — a geometric heuristic lawNone — hand-tuned gainsOptimal for the given linear model and quadratic costOptimal over the horizon, re-planned every step
ConstraintsNot handled (no dynamics awareness)Not handled natively (saturation is ad hoc)Not handled directlyHandled explicitly (state/input limits)
Compute costLowest (closed-form geometry)Very lowLow (gains computed offline, once)High (online optimization every cycle)
referenceprediction horizon Nnowapply first step only, then slide →
MPC re-optimizes a trajectory over a finite look-ahead horizon each step, applies only the first control, then slides the horizon forward — letting it honor constraints and preview the reference, unlike LQR's fixed infinite-horizon gain.

Application focus

Select an application above.

Practice questions (5)