A pendulum that would rather fall
Balance a broomstick upright on your palm and you're solving, by reflex, one of control theory's canonical hard problems. The system has two degrees of freedom — cart position and pendulum angle — but only one control input, the horizontal force on the cart. That mismatch has a name: an underactuated system. You cannot push the pendulum directly; every correction has to arrive indirectly, through the cart's motion coupling into the pendulum's angular dynamics.
The nonlinear equations of motion for a cart of mass M and a pendulum of mass m, length l, angle θ measured from vertical, driven by force F, are:
(M + m)ẍ + m l θ̈ cosθ - m l θ̇² sinθ = F
l θ̈ - g sinθ + ẍ cosθ = 0
Near the upright equilibrium (θ ≈ 0) these linearise, with sinθ ≈ θ and cosθ ≈ 1 and dropping the θ̇² term, into a linear state-space model amenable to everything from PID to LQR. But linearising throws away exactly the behaviour that makes the swing-up problem hard, so it is only valid in a narrow cone around vertical — a few tens of degrees at most.
Why this is an unstable equilibrium, precisely
Hanging straight down is a stable equilibrium: perturb it and gravity restores it, the same way a pendulum clock behaves. Standing straight up is an unstable equilibrium: perturb it and gravity accelerates the deviation instead of correcting it. Linearise the dynamics about θ = 0 (upright) and the open-loop system has a real, positive eigenvalue — a pole in the right half of the s-plane, growing exponentially with no feedback at all. This is the textbook demonstration that open-loop stability and closed-loop stabilisability are entirely different questions: the plant itself is unstable, but it is controllable, so a feedback law exists that stabilises it even though nothing about the uncontrolled system wants to stay upright.
Why plain PID struggles, and what actually works
A single PID loop closed directly on θ can, with careful tuning, hold the pendulum near vertical for small disturbances — but it's fighting an uphill battle for two reasons. First, PID only sees one signal (θ, or its derivative and integral); it has no direct knowledge of cart position or velocity, so it can inadvertently let the cart drift or run off its rail while it's busy zeroing the angle. Second, PID gains are tuned around the linear approximation, so performance degrades and eventually fails as θ grows beyond that narrow linear cone — which is precisely what happens during any large disturbance or during startup, when the pendulum begins hanging down, 180° away from where PID wants it.
That gap between hanging and standing is the swing-up problem, and it needs a genuinely different controller, because near θ = 180° the system is nowhere close to linear. The classical solution is energy-based swing-up: rather than trying to regulate angle directly, pump energy into the pendulum by driving the cart in a way that always adds to the pendulum's mechanical energy, until that energy approaches the energy of the upright equilibrium — then switch controllers, handing off to a linear stabiliser (PID, pole placement or LQR) once θ is inside its small linear basin of attraction. The Åström–Furuta swing-up controller is the reference version of this idea, and the switch between the two controllers is itself a small piece of decision logic layered on top of continuous feedback.
energy of the pendulum: E = ½ m l² θ̇² - m g l cosθ energy at upright: E_top = m g l swing-up: accelerate the cart to increase |E - E_top| toward 0 stabilisation: once |θ| and E are both small, hand off to LQR / PID
Why the state-space view earns its keep here
Once linearised, the cart-pole is the textbook example for LQR: four states (cart position, cart velocity, angle, angular velocity), one input. Weighting angle heavily in Q gives a stiff, twitchy stabiliser that corrects fast but burns actuator effort; weighting cart position in Q keeps the cart centred on the rail instead of drifting to a limit switch while the angle stays upright — a trade-off no single-loop PID on θ alone can express, because PID never sees cart position at all. This is the concrete reason the inverted pendulum shows up in nearly every state-space control course: it is small enough to compute by hand, yet it exposes underactuation, linearisation limits, and the real payoff of multivariable feedback all at once.
Frequently asked questions
Why is the inverted pendulum called "underactuated"?
Because it has two degrees of freedom — cart position and pendulum angle — but only one control input, the horizontal force on the cart. You cannot apply a force directly to the pendulum; you can only influence its angle indirectly, through how cart motion couples into the pendulum dynamics.
Can PID alone swing the pendulum up from hanging down?
Not reliably. Standard PID is tuned around the linearised dynamics near θ = 0 (upright), which breaks down as θ approaches 180° (hanging). Swinging up from hanging typically needs a separate energy-based controller that pumps mechanical energy into the pendulum until it's close to the upright equilibrium, then hands off to a linear stabiliser like PID or LQR.
Why does the pendulum fall if you tune the PID gains wrong?
The upright position is an open-loop unstable equilibrium — any deviation grows exponentially without correction. If the gains are too low, feedback can't outrun that exponential growth; if they're too aggressive or badly damped, the loop overshoots and oscillates until the angle leaves the narrow linear region the gains were tuned for, at which point the linear approximation itself stops being valid and the controller loses authority.
Try it live
Everything above runs in your browser — open Inverted Pendulum and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.
▶ Open Inverted Pendulum simulation