02 / An interactive engineering note
Three ways to
close the loop.
Give three controllers the same motor, target and load. Tune PID, place the poles of a state-feedback controller, or change what an LQR controller values. Compare tracking with the voltage and current it takes to get there.
New educational demonstration · 2026
Two-state DC motor · no historical test data
Reference comparison
Defaults: PID Kp 2.4, Ki 6, Kd 0.04; poles −5 and −50 s⁻¹; LQR weights 10 / 1 / 1. Target 5 rad/s, load 0.15 N·m. Enable JavaScript to tune the experiment.
The selected speed response is emphasized; its voltage and current appear below. All three controllers face the same experiment.
Swipe or use arrow keys to explore the full plots.
| Controller | Error at 7 s rad/s | ∫ |error| dt rad | ∫ voltage² dt V²·s | Saturated s |
|---|
Shading marks the load pulse from 2.5–4.5 s. Voltage-squared effort is a control metric, not electrical energy. A smaller error can require more effort; no architecture wins every objective.
Model and verification note (PDF) · Portable source package. The new numerical study checks sample timing, independent reference solutions and 45 plant-sensitivity runs. It also retains a load that exceeds the voltage-limited equilibrium.
Plant, controller equations, and what “optimized” means
The shared plant is J dω/dt = Kt i − bω − τload and L di/dt = u − R i − Ke ω. States are speed ω (rad/s) and armature current i (A). J = 0.02 kg·m², b = 0.04 N·m·s/rad, Kt = 0.10 N·m/A, Ke = 0.10 V·s/rad, R = 2 Ω, L = 0.05 H. Voltage is limited to ±12 V. The target steps from rest; the run lasts 7 seconds.
PID: u* = Kp(r − ω) + z − Kd dωfiltered/dt, with dz/dt = Ki(r − ω). Derivative acts on measured speed, avoiding a reference-step derivative kick, with a 0.02 s filter. Kp has units V·s/rad, Ki V/rad, and Kd V·s²/rad. Conditional anti-windup pauses integration only when it would push further into saturation.
State feedback: u* = N r − kω ω − ki i. Sliders place the poles of the continuous, unsaturated closed-loop model. N supplies nominal reference tracking. Both states are known exactly. No integral action is included, so a constant load or model error can leave a steady offset.
LQR: a discrete algebraic Riccati equation gives optimal state feedback for the nominal linear model. Deviations from the no-load target equilibrium are normalized by 10 rad/s, 1 A and 12 V. The discrete infinite-horizon objective is Σ Δt [qω ((ω − r)/10)² + qi (i − 0.4r)² + ρ ((u − 0.9r)/12)²]. The no-load target equilibrium is ω = r, i = 0.4r A and u = 0.9r V. The weights penalize speed error, current deviation and voltage deviation. Multiplying all three weights by the same factor leaves the ideal gains unchanged. Voltage saturation is applied afterward: this is an unconstrained linear-quadratic optimum, not constrained optimal control. LQR uses nominal reference feedforward and has no integral state.
Ideal feedback and fixed parameters make this a limited educational comparison. Electrical dynamics are included; noise, estimators, current protection, nonlinear friction, heating and backlash are omitted. Signed speed allows back-driving. This new model uses no employer data or recovered academic code.
Controllers update every 0.001 s and hold their voltage command between updates. The linear motor states propagate with an exact zero-order-hold step for voltage and load. PID integration and its measurement-derivative filter update at the same period. LQR solves the Riccati equation for this sampled model.
Control-theory reference: Russ Tedrake, MIT — Linear Quadratic Regulators, including the discrete-time Riccati formulation. The motor parameters and demonstration implementation here are newly authored.