x0.00v0.00θ0.00ω0.001k = [-6.1, -7.8, -49.3, -10.9]2x, v, th, w = state3u = -(k[0]*x + k[1]*v4 + k[2]*th + k[3]*w)0 N
012345-404812time (s)degreesLEAN θno controlu = −Kx012345-40481216time (s)cmCART POSITION xu = −Kx-6-4-20246-202real part (1/s)imaginaryPOLES (s-plane)stableunstable×2+4.65−2, −3, −4, −5
Lit wire with moving dashes: a signal or the belt's pull is flowing along itBlocks: motor, cart, encoders and the state cells; the controller is the code cardPlots: lean, cart position and poles, computed from the modelThe pole and cart move exactly as the simulation saysAn inverted pendulum on a cart: a motor and belt (the actuator), the cart and pole (the plant), encoders (the sensors), the state [x, v, θ, ω] and the controller u = −Kx. The cart and pole move with the full nonlinear simulation; the plots below are computed from the same run. Pole placement works only if the system is controllable: the matrix [B, AB, A²B, A³B] must have full rank, here 4. The lessons "Controllability and observability" and "State feedback and pole placement" explain why. In python-control, control.place(A, B, p) returns K such that A − BK has the eigenvalues p.

Why it falls

  1. 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.

Handle and state

The controller

Balancing

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.