Why it falls
A 0.5 m pole stands on a free pivot on a cart. Our job: keep it upright by pushing the cart left and right. To start, it leans 0.1 rad, about 5.7°, to the right.
With no control, gravity pulls the bob further the more it leans. The lean passes 30° after 0.51 s, and the pole lies flat after 0.76 s. Upright is an unstable equilibrium: balanced, but any nudge grows.
Near upright, sin θ ≈ θ (0.17% off at 0.1 rad). The equations turn linear: θ̈ = 21.582·θ − 2u. With u = 0, one system pole (a growth rate, not the rod) is +4.65 /s. Positive means growth: the lean doubles every 0.15 s.
Handle and state
A motor drives the cart along the track with a belt, pushing with force u. Push the cart right and the pivot moves under the bob, swinging the pole back to the left. The cart is the only handle we have.
Two encoders count how far the motor and the pivot have turned, giving the cart position x and the lean θ. Their rates give the speeds v and ω. These four numbers are the state: given the force u, they fix everything that happens next.
The controller
Feed all four back: u = −K·s. Each gain moves the closed-loop poles. We choose −2, −3, −4 and −5, all in the left half, and match coefficients to get K. This is pole placement.
At the start only θ is non-zero, so u = 49.3 × 0.1 = 4.93 N: push right, towards the lean. The controller reads the state and recomputes u every millisecond.
Balancing
The cart darts right under the bob. The lean crosses zero after 0.28 s, swings to −2.5° at 0.6 s, then settles. The same start that fell over in 0.76 s now stands.
Catching the pole carried the cart 14 cm to the right (most at 0.7 s). The position gains then ease it back, slowly, because −2 is the slowest pole we chose. It is back within 1 mm after 3.8 s.
The gains came from the linear model, yet they balance the full nonlinear one here. That holds only for small leans. Real rigs also have motor force limits, friction, noise and unmeasured speeds, which an observer can estimate.
What is happening
# step 1/10 · upright # about: Pole, Cart (plant) cart M = 1 kg on a straight track pole a light rod, l = 0.5 m bob m = 0.1 kg at the top pivot free: nothing holds the pole up lean θ = 0.1 rad (5.7°), + = to the right The only thing we can touch is the cart.
The rig is a model with illustrative numbers: a 1 kg cart, a 0.1 kg bob on a light 0.5 m pole, no friction. Every curve and number in the figure is simulated from the full nonlinear equations with a 1 ms time step, with the controller updating once per step. The Python on the step "Catch the lean" is plain Python 3 with the math module. It runs the same RK4 integration as the figure and prints the lean after 1 s.