03 Control Systems · #17 of 46

Capstone: Inverted Pendulum

The falling broomstick that every control engineer learns to catch

Stand a broom upright on your palm. It does not want to be there. The instant you stop paying attention, it topples, and yet you can keep it up almost indefinitely, twitching your hand a few times a second to catch each fall before it becomes a fall.

That twitchy little dance is the inverted pendulum, and it is the single most-loved toy problem in all of control theory.

A normal pendulum hangs down and settles: disturb it and gravity quietly pulls it home. Flip it over and balance it above its pivot, and the whole logic inverts: gravity now amplifies every error. Lean a hair off vertical and it leans harder, faster, until it slams flat. There is no resting on it. The only way to keep an inverted pendulum upright is an active controller measuring the tilt and shoving the base back under the falling tip, over and over, forever.

Catch the broom yourself

Below is the textbook version: a pole hinged on a cart that can only slide left and right. The controller watches four numbers (cart position, cart speed, pole angle, pole angular speed) and computes one number back: how hard to push the cart. Grab the pole tip, yank it sideways, and let go. Watch the cart dart under it to catch the fall.

Drag the pole, let go, watch it recover

x (cart)
θ (angle)
u (force)
status balanced
what to try
  • First, leave defaults alone and click small knock a few times. The pole wobbles but the controller pulls it back. Status stays "balanced." This is stabilizing an open-loop-unstable plant.
  • Drag the pole tip sideways and release. With defaults you can usually recover from ~25° tilt. Push past that and it falls. The linearization breaks down too far from upright, and the controller can't catch it.
  • Click "no derivative (watch it ring)" to set Kθ̇ = 0. Now knock the pole. It oscillates uncontrollably and falls. This is classical "P without D": the controller knows where the pole is, but not where it's going. Restore Kθ̇ and the ring vanishes.
  • Set Kx and K to 0. Knock the pole. It balances but the cart slides off-screen. The controller doesn't care about cart position, only the pole. Add both gains back; the cart returns home while the pole stays vertical.
  • Set Kθ = 0. The pole has no feedback at all. It falls immediately. Reset.

The controller here is the simplest thing that works: a linear feedback law. Multiply each of the four state numbers by a gain, add them up, and that sum is the force on the cart. The four sliders are those four gains, and a bigger gain means the controller cares more about that one thing. Two of the gains watch the pole (angle and its rate), and two watch the cart (position and its rate) so it does not balance the broom beautifully while wandering off the edge of the world.

The magic word is unstable equilibrium. Upright is a balance point, but a knife-edge one. The controller's whole job is to manufacture stability that the physics refuses to provide: to take a plant that diverges on its own and bend it back toward the point it keeps trying to leave.

Honda's ASIMO humanoid robot standing on two legs.
Honda's ASIMO is an inverted pendulum that learned to walk. Every step is a controlled fall: the robot tips forward, then swings a foot out to catch itself, balancing its whole mass above the ankle exactly the way the broom balances above your palm. · Gnsin, CC BY-SA 3.0
A self-balancing two-wheeled personal transporter (Segway-style) with a rider.
A Segway is a real inverted pendulum: it stays upright only because a controller corrects its fall about a hundred times a second. · Soar Boards (www.soarboards.com), CC BY 2.0

This is not an academic curiosity dressed up as one. The same falling-broom math is what keeps a Segway under its rider, what holds a rocket balanced on its own thrust as it lands tail-down, and what stops a humanoid robot from face-planting the moment it lifts a foot. Each one is a top-heavy mass that wants to fall, with a controller frantically moving its base to stay underneath.

What the sliders teach you

Each gain is a different kind of attention, and you can break the controller in instructive ways:

The math: cart-pole dynamics and the linear feedback law

The cart-pole has four states: cart position and velocity, pole angle and angular rate.

s=(x, x˙, θ, θ˙)\mathbf{s} = (x,\ \dot{x},\ \theta,\ \dot{\theta})

With cart mass MM, pole mass mm, pole half-length ll, and gravity gg, Newton's laws give the nonlinear dynamics the demo integrates with Runge–Kutta. Writing sθ=sinθs_\theta = \sin\theta and cθ=cosθc_\theta = \cos\theta:

x¨=u+msθ(lθ˙2gcθ)M+msθ2\ddot{x} = \frac{u + m\,s_\theta\,(l\,\dot{\theta}^2 - g\,c_\theta)}{M + m\,s_\theta^2}θ¨=ucθmlθ˙2sθcθ+(M+m)gsθl(M+msθ2)\ddot{\theta} = \frac{-u\,c_\theta - m\,l\,\dot{\theta}^2\,s_\theta\,c_\theta + (M + m)\,g\,s_\theta}{l\,(M + m\,s_\theta^2)}

The control input uu is the horizontal force on the cart. The controller is a single linear feedback law on all four states:

u=Kxx+Kx˙x˙+Kθθ+Kθ˙θ˙u = K_x\,x + K_{\dot{x}}\,\dot{x} + K_\theta\,\theta + K_{\dot{\theta}}\,\dot{\theta}

The four sliders are exactly Kx, Kx˙, Kθ, Kθ˙K_x,\ K_{\dot{x}},\ K_\theta,\ K_{\dot{\theta}}. Choosing those four gains so the closed-loop system drives every state to zero is the heart of state-feedback design: pole placement and the linear-quadratic regulator are just principled recipes for picking them. The demo also saturates uu at ±35N\pm 35\,\text{N}, because real actuators cannot push infinitely hard, and resets if the pole passes 90°90° from vertical, where the small-angle assumptions behind the linear law have long since stopped being true.

The cheat: balance a pendulum upside down with no controller at all

Everything so far says you need an active controller. There is one weird exception. Take an inverted pendulum and, instead of moving the base sideways, just shake it straight up and down fast enough. The pole will stand upright on its own and snap back when you nudge it, with no sensor and no feedback law anywhere. This is Kapitza's pendulum, named for the Russian physicist Pyotr Kapitza, who worked out the math for it. If the base wobbles as a simple sine wave, the pole's motion obeys this driven equation:

θ¨gsinθ=Aω2sin(ωt)sinθ\ddot{\theta} - \frac{g}{\ell}\sin\theta = -\frac{A}{\ell}\,\omega^2 \sin(\omega t)\,\sin\theta

Here AA is how far the base shakes and ω\omega is how fast. For small swings this is closely approximated by the famous Mathieu equation. Shake slowly and the pole falls like you would expect. Shake fast enough and that rapid ω2\omega^2 term averages out into an effective force that pulls the pole back toward vertical. The stability is not from a brain reacting to error, it is baked into the physics of the fast wiggle. It is the closest thing control theory has to a free lunch, and it is a useful reminder that "unstable" is a statement about a system in a particular setting, not a life sentence.

You are the most common inverted pendulum on Earth. Stand up straight and you are a top-heavy mass balanced on two small feet, and you never actually stop moving: your body sways a little the whole time, and tiny muscle tweaks catch each lean before it grows. The controller doing this is your nervous system, and it is reading more sensors than the demo above ever gets.

Key takeaways

A broom on your palm: your hand is the cart, your eyes the sensor, your brain the controller. You have been solving the inverted-pendulum problem since you were a toddler, hundreds of times a second, without a single equation.

Everything in this chapter (measuring the gap, predicting the fall, pushing back in proportion) converges here, on the simplest machine that genuinely cannot stand on its own. Teach a controller to catch the broom, and you have taught it the one trick that lets rockets land and robots walk.

full glossary →