← Kybernetes

The Broomstick Problem

Balance an upside-down pendulum on a cart. Try it by hand first (←/→). It's the broomstick-on-your-palm trick, and it's brutal. Then let a PID controller watch the angle alone: it saves the pole and quietly loses the cart. Fixing that needs the whole state at once. Enter LQR, with its gains computed live in your browser from how much you price errors vs effort. In LQR mode, drag the flag: the same controller that balances also drives.

Who's balancing?

Hold ←/→ (or A/D) to push the cart. Catch the pole by driving under it. Space pokes it, R resets.

Disturb it

Or click above the track to poke the pole from that side.

Scoreboard

Balanced streak0.0 s
Best streak0.0 s
Cart position0.00 m
Wall hits / drops0 / 0

Rule of the game: survive. Try manual until you've dropped it a few times, then 📐 PID. Keep an eye on where the cart ends up.

One knob is not enough

PID and why it drops the ball

PID on the pole angle keeps the pole up beautifully and says nothing about the cart. Every recovery leaves the cart somewhere new, and it random-walks to the wall. One sensor, one knob can't govern a two-variable machine.

State: the whole picture

The machine's full state is four numbers: [x, ẋ, θ, θ̇]: where the cart is, how fast it moves, where the pole leans and how fast it falls. Full-state feedback u = −Kx reads all four and mixes them into one push.

LQR: pricing your errors

Where do the four gains come from? You write a bill: Q prices being in the wrong state, R prices pushing. LQR solves the Riccati equation for the gains that minimise the total bill. That makes them optimal, not hand-tuned. Move the prices, watch K follow.