Control Systems
One problem, taken all the way through: a mass on a spring. Each lesson follows the same five steps (arrive, reactivate, inform, process, evaluate), and some of the ideas then return on a tilt table, an aircraft and a cart-pole. Past what these can do, control a double pendulum, or upload your own recording to fit a model and design an LQR for it.
1 · Arrive Tune a PID so the mass tracks the reference without ringing, then see what delay and noise do to it. about 10 min
2 · Reactivate You already know a spring pulls back and a damper slows things down. That is all this mass is, and a controller has to work with it.
3 · Inform About this demo
A PID controller tracks a reference with a lightly damped mass on a spring. The proportional term reacts to the error, the integral term removes offset, and the derivative term damps ringing. Start with Kp, add Kd, then a little Ki. Then add delay (it eats phase margin) or noise (the derivative term amplifies it). The score is RMSE over the last 5 s.
Try it
You can now: tune a PID by eye, and say what each term does.
1 · Arrive Read how stable the tuned loop is, and how much delay or gain it can take, from its frequency response. about 8 min
2 · Reactivate You tuned the loop by watching the response. A loop can look fine and still be a delay away from oscillating. Builds on: Tune
3 · Inform Cut the loop open
Cut the loop at the force. The loop gain L(s) = C(s)G(s) is one trip round the loop; if it comes back inverted at the same size (0 dB, −180°) the loop oscillates by itself. Phase, gain and delay margin say how far you are. Nyquist draws the same numbers as one curve that must keep clear of −1; Poles shows the closed loop's own motions, and you can drag one to place it.
Try it
You can now: read phase, gain and delay margin off a Bode plot and say what a Nyquist curve near −1 means.
1 · Arrive Recover the mass, damper and spring from nothing but a recorded force and position. about 8 min
2 · Reactivate On the tuning lesson the constants were handed to you. On real hardware they are not. Builds on: Is it stable?
3 · Inform Fit a difference equation by least squares
Record input and output, then find the difference equation that best predicts each output sample from the ones before it. That is linear in the unknowns, so one least-squares solve finds them. It is biased by sensor noise, so the fit is refined with instrumental variables. A 2nd-order fit reads back as m, c and k; a 3rd or 4th keeps its slowest oscillating pair (marked *); a 1st cannot oscillate, so there is nothing to read. A step barely excites the resonance, so try a chirp or random input.
Try it
You can now: fit a mass-spring-damper from data and say why the input signal and the model order matter.
1 · Arrive Build a state-space model from one tap, and see what its unseen states are. about 10 min
2 · Reactivate Least squares made you choose the model order and only ever used the measured position. Can the data tell you the order, and what the unseen states are? Builds on: Fit: least squares
3 · Inform Realize a state-space model from the impulse response
You can only see the position. But a mass on a spring has a second, unseen state, its velocity, and the position's future depends on both. Ho–Kalman (1966) says that if one tap gives you the whole ringing record, a state-space model that reproduces it is already hidden in the numbers.
1. Record the impulse response. The positions after the tap, h1, h2, …, are the Markov parameters. Any linear model x+ = Ax + Bu, y = Cx has hk = CAk−1B.
2. Stack them into a Hankel matrix, each row the one above shifted by one sample (the diagonal stripes in the heatmap). It factors into what the output can see of the states times what the input can reach, so its rank is the number of states. The singular values show that rank: two are large, the rest are noise.
3. Keep those and read off the model. The factors give B, C and, from the shifted matrix, A. The dashed curve is the model's own impulse response.
4. What the unseen states are. They are not position and velocity. Any invertible mixing T gives a model with identical input and output, so data alone cannot say which coordinates are “real”. Ho–Kalman returns one particular choice, a balanced one, where the states are equally easy to reach and to see. Switch the lower plot to Hidden states: each realized state is a fixed mix of the true position and velocity, and the model has the same poles. To read m, c and k the panel maps the model back to a second-order mass-spring form.
One limit: only the part of the system that is both reachable by the input and visible in the output can be recovered. A state that cannot be moved or cannot be seen leaves no trace in the tap.
Compare methods fits the same noisy recording three ways. With clean data, least squares and state-space least squares (measuring position and velocity) are exact, and Ho–Kalman starts a few percent off because its impulse response is truncated. Add sensor noise and the picture flips: least squares on noisy states is biased (its regressors carry the noise), the output-only ARX fit drifts, and Ho–Kalman, which keeps only the large singular values, barely moves.
The next lesson drives the change of basis directly; the aircraft and cart-pole lessons use it to read states that have no sensor.
Try it
Show the math
Impulse response: hk = C Ak−1 B.
Hankel matrix: H = [hi+j−1] = 𝔪 𝔞, with observability 𝔪 = [C; CA; CA²; …] and
controllability 𝔞 = [B, AB, A²B, …], so rank H = n.
SVD: H = UΣVT. Keep n values: 𝔪 = UnΣn1/2,
𝔞 = Σn1/2VnT. Then C is the first row of 𝔪, B the first column of 𝔞, and
A = Σn−1/2 UnT H2 Vn Σn−1/2, where H2 is H shifted by one sample.
Non-uniqueness: (A, B, C) → (TAT−1, TB, CT−1) has the same hk for every invertible T.
You can now: build a state-space model from one tap, find the order from the singular values, say why its states are only defined up to a change of coordinates, and say when Ho–Kalman beats least squares.
1 · Arrive See that a model's states are only a choice of coordinates, and what stays the same when you change them. about 8 min
2 · Reactivate Ho–Kalman returned states that were a mix of position and velocity. Is that a different system, or the same one in other coordinates? Builds on: Fit: Ho–Kalman
3 · Inform Same system, different axes
A basis is a set of axes. The motion of the mass does not depend on which axes you draw it in; only the numbers
that describe it do. The map x̃ = T x turns physical coordinates (position, velocity) into new ones. The left plot is the
path of the mass; the right plot is the same path in the new axes, with the images of the old axes drawn as arrows.
The model follows the same rule: A′ = T A T−1, B′ = T B, C′ = C T−1.
The output is y = C′ x̃ = C T−1 T x = C x, so it does not move when you drag T.
What changes: every number in A, B and C, and what each state means. What stays: the poles, stability, the output and the impulse response. So data about inputs and outputs cannot choose T. Ho–Kalman picks one (a balanced one), which is why its states are a mix of position and velocity and not the physical ones. To call a state “the angle of attack” you need one more piece of information: a physical model, or a calibration against a sensor, as the next lessons do.
Try it
You can now: say what a change of basis does to A, B and C, and why identified states do not line up with physical ones.
1 · Arrive Feed back both position and velocity, and let LQR choose the gains. about 8 min
2 · Reactivate PID reacted to the error and its slope. Here the controller uses the states themselves: position and velocity. Builds on: Is it stable?
3 · Inform u = K x
With both states measured, the force is a weighted sum: u = K x. LQR picks K by trading state error (Q) against force (R), by solving a Riccati equation for the plant, so you never tune it by hand. Load LQR gains fills in that K. In Poles the open-loop pair at −0.2 ± 2j moves left: the feedback added damping.
Try it
You can now: use LQR to set state-feedback gains and see them as pole placement.
1 · Arrive Control the mass with only a position sensor, estimating the speed you cannot measure. about 8 min
2 · Reactivate State feedback needed the velocity. Real sensors often give position only. Builds on: State feedback, Fit: least squares
3 · Inform Predict, then correct
Differencing estimates speed as (this reading − last reading) ÷ time step, which amplifies noise. A Kalman filter runs a model of the mass alongside it: predict with the force just applied, then correct toward the position reading. The trust slider trades smoothing against lag.
Try it
You can now: estimate an unmeasured state with a Kalman filter and say what the trust setting trades.
1 · Arrive See what a computer loses when it only reads a signal every T seconds. about 8 min
2 · Reactivate Is it stable? shook the mass at one frequency at a time. Now only look at it every T seconds. Builds on: Is it stable?
3 · Inform A computer only sees samples
A controller sees a number every T seconds (the dots) and nothing in between. It is sampled in time and quantized in value (try 2 bits), and its output is held until the next update: a zero-order hold. Push the signal past fs/2, the Nyquist frequency, and the dots trace a slower, wrong wave (dashed): aliasing. Only an analog filter before sampling can remove it.
Try it
You can now: say why a signal aliases and what has to happen before sampling to prevent it.
1 · Arrive Turn a continuous model into an update a computer can run, and see which methods keep it stable. about 8 min
2 · Reactivate A computer cannot integrate; it repeats an update every T seconds. Builds on: Sampling
3 · Inform Four ways to turn ẋ = f(x) into a step-by-step rule
Discretization turns a continuous model into an update every T seconds. A discrete system is stable when its poles are inside the unit circle.
- Zero-order hold: exact when the input is held between samples. The reference for the others.
- Forward Euler: at T = 0.2 s the poles leave the circle, so a stable plant becomes an unstable model.
- Backward Euler: always stable, but adds damping that isn't there.
- Tustin: stable stays stable, at the cost of a squeezed frequency axis. The usual choice for code.
At small T all four agree: sample fast and the method barely matters.
Try it
You can now: pick a discretization method and say why forward Euler fails at a large sample time.
1 · Arrive Find how slowly a PID can run before the loop falls apart. about 6 min
2 · Reactivate You can discretize a model. Now the controller itself runs once every T seconds with a hold between. Builds on: Discretize, Is it stable?
3 · Inform How slow can the controller run?
The PID now runs at period T with a zero-order hold, and the loop is analyzed exactly in discrete time. These gains are stable at 130 ms and fall apart at 140 ms. The "hold is half a sample of delay" shortcut predicts about 230 ms, so treat it as an upper bound. In practice run the loop 10–30 times per crossover period (the panel counts it).
Try it
You can now: set a controller rate from the crossover frequency instead of guessing.
1 · Arrive Write down what the controller must achieve, as numbers, before any design. about 5 min
2 · Reactivate In the Tune lesson you stopped when it looked good. Real designs stop when every line of a checklist is ticked. Builds on: Is it stable?
3 · Inform Say what good means
Write down what the controller must achieve, as numbers: overshoot, settling time, margins, force. Each becomes a picture: an envelope the step response must stay inside, and a region of the s-plane for the poles. The checklist is the contract for the test lesson.
Try it
You can now: turn a vague goal into measurable requirements and see them as a pole region.
1 · Arrive Find out what you are really controlling, because the textbook numbers are wrong. about 6 min
2 · Reactivate The requirements are set. A design needs a model of the plant, and the nominal one is not the real thing. Builds on: Fit: least squares, Design: requirements
3 · Inform Find out what you're controlling
The textbook says 1 kg, spring 4, damping 0.4. The real plant differs, and you only find out by measuring. Run the experiment, then press Design with this model. Later lessons use this model; the test runs on the real thing. (See Fit a model.)
Try it
You can now: identify the real plant before designing, and say why the test uses the real plant.
1 · Arrive Pick gains that meet the requirements, then prove the loop is stable with room to spare. about 10 min
2 · Reactivate You have requirements and a model. Drag poles into the allowed region and the gains follow; margins tell you how much room is left. Builds on: Design: model, State feedback
3 · Inform Design the controller
Three gains, three closed-loop poles: drag the poles into the shaded region from the requirements and the gains are solved (pole placement). Faster poles settle sooner but need more force. The step response is on the real plant.
Try it
You can now: place poles to meet requirements and use margins as a budget for model error.
1 · Arrive Run your design on the real plant with a force limit and delay, try some noise, and check every requirement. about 8 min
2 · Reactivate On paper the controller is perfect. On hardware it has noise, limits and delay. Builds on: Design: controller, Sample rate
3 · Inform Meet the real world
Add noise, a force limit and delay, and see what breaks first. The D term amplifies noise; a force limit makes the integrator wind up and overshoot (the cure is anti-windup); delay eats the margin you proved.
Try it
You can now: test a design against its requirements and decide which step to revisit when one fails.
1 · Arrive Record your own data and see which fit survives data it has never seen. about 10 min
2 · Reactivate Every method so far worked on a scripted experiment. Real data is messier, and you design the experiment yourself. Builds on: Fit: least squares, Fit: Ho–Kalman, Design: test
3 · Inform Collect your own data
Press Record and move the mass any way you like: drag it, tap it, switch on the shaker, or let the PID chase its reference. Then Identify: both methods fit the first 70% and are checked on the last 30%. Gentle pushes barely excite the resonance, and data recorded under PID control is closed-loop, which biases the fit unless the shaker also excites it.
Try it
You can now: collect and check your own identification data, and explain why closed-loop data is harder.
1 · Arrive Hold a rolling ball at a target on a tilting beam, with a servo that can only turn so fast. about 8 min
2 · Reactivate On the mass on a spring you tuned a PID. A ball on a beam has no spring pulling it back, and the servo can only turn so fast: what do you expect to change? Builds on: Tune
3 · Inform About this demo
A PID controller tilts a beam so a ball tracks a reference (the dashed ring). A servo turns the beam at no more than 60 °/s, so watch θ̇ saturate. Kp alone oscillates, Kd damps it, and a little Ki removes offset. The run restarts if the ball rolls off an end.
Try it
You can now: explain why a plant without a spring needs derivative action, and read the servo limit off the state plot.
1 · Arrive Make an aircraft hold or change altitude with the elevator, without stalling the wing. about 10 min
2 · Reactivate On the mass on a spring the plant answered the force directly. Here the elevator moves the nose, the nose moves the climb, and the climb moves the altitude. Builds on: Tune
3 · Inform About this demo
A PID autopilot tracks an altitude reference by moving the elevator away from trim. Altitude can only change through pitch and flight-path angle, so Kp alone oscillates; Kd on climb rate damps it. Push too hard and the wing stalls. In Manual the canvas is a control stick.
Try it
Show the math
Equations of motion
L, D, My from nonlinear aero (sigmoid stall ~16°). T = trim thrust. RK4 at 200 Hz.
PID autopilot
Elevator clamped ±15° and slew-limited to 40°/s. The run resets on a crash, a stall, a loop, or a climb past 590 m. The score is altitude RMSE over the last 6 s.
You can now: tune an autopilot against a lagging plant and spot when the wing is the limit, not the gains.
1 · Arrive Test the elevator loop and the throttle loop together instead of one at a time. about 6 min
2 · Reactivate On the mass on a spring one loop had margins to spare. Here two loops share one aircraft. Builds on: Tune the aircraft, Is it stable?
3 · Inform Both loops at once
Real hardware errs in every channel at once. Drag the dot to give each loop a gain error. The dashed box is what each loop's own margins predict; the colored map is the truth, both errors together. Where they disagree, the loops interact.
Try it
You can now: explain why single-loop margins are not enough on a plant with two loops.
1 · Arrive Balance an unstable pole on a cart using only two noisy sensors, and see what the estimator costs. about 12 min
2 · Reactivate On the mass on a spring you used state feedback and estimated the speed with a Kalman filter. Here the same two steps are applied to a plant that falls over without them. Builds on: State feedback, Estimate the speed
3 · Inform About this demo
The cart-pole is unstable: with no control the pole falls in a second or two. One force must hold the pole angle and the cart position, so the force is a weighted sum of four states (full-state feedback). Only the cart position and pole angle are measured, so the two rates are estimated: by differencing readings (noise gets amplified) or by a Kalman filter (a model of the plant corrected by the sensors, with a trust slider). Raise the noise and compare. Load LQR gains fills in the optimal set. Switch View to Bode, Nyquist or Poles: the filter is part of the loop, and LQR's guaranteed margins are gone (Doyle, 1978).
Try it
Show the math
Equations of motion & control law
Linearized about upright (small θ), with this cart-pole's numbers. Q and R weight state error against force; the Riccati solution for them gives K.
M = 0.3 kg cart, m = 0.3 kg pole, ℓ = 1.5 m half-length, b = 0.8 N·s/m cart friction, g = 9.81 m/s². Force saturates at ±10 N; LQR's K comes out negative in every entry (u = −Ks), so the sliders show −K and all four gains are positive. θ is in rad, measured from vertical. The trial ends when |θ| > 45° or the cart hits a rail end at ±4 m. RK4 at 200 Hz.
You can now: balance an unstable plant from two noisy sensors and read what the estimator does to its margins.
1 · Arrive Prove what a neural-network controller will do, instead of watching it balance and hoping. about 8 min
2 · Reactivate LQR gains are a short list of numbers you can analyze. A network that copies them is not. Builds on: Balance the pole
3 · Inform Proving what a network will do
The small network trained to copy the cart-pole's LQR. Verification proves something for every input in a region: can a sensor error up to ε on the angle move the force by more than δ? Interval bound propagation pushes the whole box through the network. The answer is proved, disproved (with a counterexample) or unknown; split the box and bound each piece to tighten it (branch and bound). The right map runs the proof at every state.
Try it
You can now: say what a verified bound promises and how branch and bound tightens it.