Control Systems
Four live simulations. Tune a PID controller on a mass-spring, a ball-balancing tilt table, and a nonlinear aircraft autopilot. On the inverted pendulum on a cart, set the four gains of a state-feedback (LQR) controller instead. Then add transport delay and sensor noise to see what breaks it. Every demo starts in Manual, so drag the plant yourself to feel how hard the job is, then switch to the controller and let it try. The plots under each sim show the plant's states and what each term of the controller is contributing. For a problem past what PID can do, swing up a double pendulum by hand, or hand it to a reinforcement-learning policy.
Controller
Manual: drag the mass up or down. Delay and noise apply to PID only.
Reference
Stuck? A good solution is Kp = 40, Ki = 5, Kd = 6. A high Kp tracks the sine closely, Kd stops the spring from ringing, and a little Ki removes the offset.
PID Gains
Disturbances
About this demo
A PID controller pushes a lightly damped mass on a spring (ζ ≈ 0.1) to track a reference: a slow sine wave, or a step that jumps to the opposite position every half period. The line ahead of the mass shows where the reference is going. The proportional term reacts to the current error, the integral term removes steady-state offset, and the derivative term damps oscillation. The score is RMSE over the last 5 s. Start with Kp alone, add Kd to cut the overshoot, then a small Ki to remove what's left. Then add a transport delay to the command or sensor noise to the measurement: delay eats phase margin, and the derivative term amplifies noise the most. In Manual mode, drag the mass to follow the reference yourself. → PID controller - Wikipedia
Controller
Manual: drag the beam ends to tilt it. Delay and noise apply to PID only.
Reference
Stuck? A good solution is Kp = 3, Ki = 0, Kd = 2. Enough Kp to chase the reference, and Kd to brake the ball before it overshoots.
PID Gains
Disturbances
About this demo
A PID controller tilts a beam so a rolling ball tracks a reference position: a sine wave, or a step that jumps to the other side of the beam every half period (the dashed ring on the beam is where the ball should be). The run restarts if the ball rolls off an end. The controller outputs a commanded tilt, and a servo turns the beam toward it at no more than 60 °/s, so a big correction takes time. Watch θ̇ saturate in the state plot. Kp alone makes the ball oscillate, Kd damps it, and a small Ki removes any leftover offset. In Manual mode, drag either end of the beam to tilt it. The same servo limit applies to you. → Ball and beam - Wikipedia
Controller
Manual: drag up to pitch the nose up, down for nose down; release to return to trim. Delay and noise apply to PID only.
Reference
Stuck? A good solution is Kp = 0.5, Ki = 0.1, Kd = 0.35. Kd damps the climb rate, and Ki holds the altitude against drift.
PID Gains
Disturbances
About this demo
A nonlinear longitudinal aircraft model with six states (V, γ, α, q, h, x) and a smooth stall: CL rises linearly up to about 16° angle of attack, then drops sharply. A PID autopilot tracks an altitude reference, a sine wave or a step that jumps up and down every half period, by moving the elevator away from trim. Altitude error goes in, and a nose-up elevator command in degrees comes out. The aircraft can only change altitude through its pitch and flight-path angle, so Kp alone oscillates. Kd acts on climb rate, and it is what damps the oscillation. Push too hard and the wing stalls. Delay and sensor noise work as in the other demos, with noise σ in metres. In Manual mode the canvas is a control stick: drag up to pitch the nose up, and let go to return to trim. → Flight dynamics - Wikipedia, Autopilot - Wikipedia
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.
Controller
Manual: drag the cart. Delay and noise apply to the controller only.
Reference
Stuck? A good solution is kx = 3.1, kẋ = 5.9, kθ = 43.5, kθ̇ = 18.1. These are the LQR gains. The pole terms keep it up and the cart terms pull it back to the middle.
State-feedback gains
Disturbances
About this demo
The cart-pole is the classic unstable plant: a pole hinged on a cart that can only be pushed left or right. Each trial starts with the pole upright, tilted 1–4° at random, and with no control it falls within a second or two. One force has to hold two things at once, the pole angle and the cart position, so this demo uses full-state feedback instead of a single PID loop: the force is a weighted sum of cart position, cart velocity, pole angle and pole rate. Start with kθ and kθ̇. They keep the pole up, but the cart then drifts away and eventually the pole falls. Adding kx and kẋ makes the cart follow the reference position (the dashed marker on the rail), which is a sine wave or a step that jumps to the other side every half period. Their sign looks backwards at first: to bring the cart left, it must first be pushed right so the pole tips left. Hand-tuning four gains is hard, so Load LQR gains fills in the optimal set, found by solving a Riccati equation for this plant. LQR picks the gains by trading off state error against force use (here Q = diag(1, 0.1, 10, 0.1), R = 0.1). The rail is 8 m long with hard stops, and running into an end ends the trial. Sensor noise perturbs all four measurements the controller sees (sigma degrees on the angle, sigma centimetres on the cart position, and the same amount per 0.2 s on the two rates), never the force. The score is the RMS position error over the last 10 s. Switch to Manual and drag the cart to balance the pole yourself. → Inverted pendulum - Wikipedia
Equations of motion & control law
Linearised 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.