Left Half-Plane
state feedback · LQR

Stable is Still

Four numbers hold a pole upright while the gusts grow. One of them points the way nobody expects.

world —runs today 0best today —Riccati par —

Tune the four gains · Run 30 s, lower is better · click the canvas to poke

time—
cost J—
battery100%
gusts—
Where you stand today

The controller is u = kθθ + kωθ̇ + kxx + kvẋ, nothing more. The score is thirty seconds of lean, drift and effort, and a fall is expensive. Riccati par is the LQR for the nominal model, run in today's world; the button sets it, and the world has things the model does not know.

The trick

Which way does the position gain point?

To move the cart left, the pole must first lean left, and the only way to lean it left is to push the cart right for a moment. So the position term carries the same sign as the lean term: when the cart drifts right, the controller pushes it further right, the pole tips left, and the lean gain then drives the whole thing home. With the sign every intuition asks for, the ghost keeps its pole perfectly upright all the way off the end of the track. Every balancing machine does this, from a Segway to a bicycle steered right to go left: the transfer function from force to cart position has a zero in the right half-plane.

Cards
Linear state feedback: the force is a weighted sum of the state.state-feedback
u = −K x, x = [x, ẋ, θ, θ̇]ᵀ, ẋ = (A − BK) xfour gains, four closed-loop poles: with (A, B) controllable they go anywhere

Measure the whole state, multiply each component by a gain, add. Nothing about pendulums appears in the rule; the physics is entirely in the four numbers, and choosing them is the design.

More gain is not more stability. A delay τ costs ωτ of phase at every frequency, so the loop's phase budget is spent near ω ≈ 1/τ, and gains that ask for a faster loop than that oscillate. Here τ is 10–40 ms, hidden until the run ends. Sensor noise enters multiplied by the same gains, and the force limit clips whatever they ask for.

Where this game, four states · the homepage lab, six states and u = −Kx · Kick
Deeper Åström & Murray, Feedback Systems, ch. 7 · Franklin, Powell & Emami-Naeini, ch. 7

A pendulum has to lean before it can travel.lean-to-travel
X(s)/U(s) = (l′s² − g) / ( s² (M l′ s² − (M + m) g) ), zeros at s = ±√(g/l′)force to cart position, linearised about upright; one zero sits in the right half-plane

A right-half-plane zero means an inverse response: to end up left, the cart first goes right. No controller removes it, because it belongs to the plant, not to the loop. It is why kx shares the sign of kθ, and why the naive sign sends the cart off the track while the pole stays perfectly upright.

The zero also sets a speed limit. Repositioning the cart faster than about √(g/l′) radians per second costs a bigger lean and a bigger excursion the wrong way, so the fastest cart response is not the best one. The same zero, with the whole body as the pole and the wheels as the cart, is countersteering on a bicycle.

Where this game · Countersteer · every balancing robot
Deeper Åström & Murray ch. 14, right-half-plane zeros · Stein, Respect the Unstable, 2003

A bowl that only goes down proves stability without solving the motion.lyapunov
V(x) = xᵀPx > 0, V̇ = xᵀ((A − BK)ᵀP + P(A − BK)) x < 0 for x ≠ 0a positive bowl, always descending: every trajectory ends at the bottom

Lyapunov's idea, 1892: you need not solve the differential equation. Find a function that is zero at the equilibrium, positive elsewhere and decreasing along every trajectory, and the equilibrium is asymptotically stable. For a linear loop a quadratic bowl always exists, and the LQR's Riccati solution P is one.

The inset draws the θ, θ̇ slice of the level sets of that P. On the nominal loop, without delay, saturation or noise, V decreases exactly; on today's plant it mostly does, which makes the inset a picture, not a proof. The same ellipse, V < c, is the hand-over region in Swing-Up.

Where the inset here · the catch in Swing-Up · the lab's catchable
Deeper Khalil, Nonlinear Systems, ch. 4 · Slotine & Li, ch. 3

For a linear model and a quadratic cost, the best gains are known exactly.lqr
J = ∫ (xᵀQx + uᵀRu) dt, AᵀP + PA − PBR⁻¹BᵀP + Q = 0, K = R⁻¹BᵀPthe algebraic Riccati equation; here Q = diag(1, 0.1, 10, 0.5), R = 0.01 and K = [9.9, 12.5, 83.7, 21.0]

Say how much you dislike lean, drift and effort; solve one matrix equation; the gains fall out, and they minimise the cost from every initial state at once. That is the linear quadratic regulator, and on the nominal loop it comes with guarantees: for one input, at least 60° of phase margin and infinite gain margin.

Optimal for the model is not best for the world. Par can be beaten here for four reasons: the actuator delay, the force limit, the sensor noise, and a cost mismatch (this R is eight times the scored one, and the scored cost ignores the velocities). The guaranteed margins are spent by the delay the model never saw. Where the world differs from the model, hand tuning has room, and that room is the game.

Where par in every game · the lab's stiffness knob scales Q and re-solves Riccati in your browser · pole placement is the same act by hand
Deeper Anderson & Moore, Optimal Control · Åström & Murray ch. 7.5 · Kalman, 1960