Left Half-Plane
Game 04 · energy shaping · linearisation

Swing-Up

The motor is weaker than gravity, so the pendulum cannot simply be lifted. Draw the swing you want, angle against time. A tracking controller follows your line as well as the motor allows, and a linear controller takes over the moment the pendulum enters the region it can hold.

world runs today 0best today energy shaping
Where you stand today

The torque limit is 4 N·m against a gravity torque of 9.8 N·m at the horizontal, so energy has to be pumped in over several swings. Cost is the time until the pendulum is caught and held, in seconds, plus a fiftieth of the control energy; a run that never catches scores eighteen plus energy. The catch happens when the state enters V(x) < c, the same kind of Lyapunov ellipse as in game one. The textbook reference is an energy-shaping controller: three lines of code that swing it up every time. Today's joint friction is hidden, and it moves the best swing period.

What is going on

Why you cannot simply lift it

The motor can hold the pendulum at about twenty-four degrees from the bottom and no further; beyond that gravity wins. So the pendulum must be swung up the way a child pumps a swing: push in the direction of motion, and each pass adds a little energy. The timing is everything. Push with the swing and the amplitude grows; push against it and you undo your own work. And the period of a pendulum lengthens as it swings higher, so the rhythm that works at the start is wrong by the end. Your line has to know that.

E = ½ m l² θ̇² + m g l (1 − cos θ), Etop = 2 m g lswing-up is the problem of bringing E to E_top with θ̇ ≈ 0

Two controllers and a switch

Far from the top, the pendulum is a nonlinear thing, and there the game hands control to your drawing: a tracking controller pulls the angle toward your line as hard as the motor allows. Near the top, the pendulum looks like the one in game one, an inverted pendulum with a small angle, and a small angle is exactly where linear models are true. So a linear controller, designed by the same Riccati equation as before, waits in the wings. The switch fires when the state enters an ellipse the linear controller is proven to handle, V(x) < c, and from that instant the hard problem is over.

This is hybrid control, and it is how most real swing-ups work, from lab pendulums to the way a gymnast approaches a handstand. The elegant part is not either controller. It is knowing where the simple one applies.

Energy shaping

The reference you are measured against does not track any trajectory at all. It looks only at the energy: if there is less than the top requires, push with the motion; if more, push against it. One line of feedback on a single scalar, and the pendulum rises as if it knew the way.

u = k (Etop − E) sign(θ̇)add energy when short, remove it when in excess; then let the linear controller catch

It is beautiful and it is not optimal. It cannot see the clock, so it never hurries, and it wastes torque near the turning points where the pendulum is barely moving. A drawn line can shape the whole trajectory, hurry when hurrying pays, and arrive at the top a swing earlier. That is the gap you play in.