Schedule a call

Motion & control · Interactive Simulation

Pendulum Swing-Up Simulator

Trajectory optimisation · Tracking control · Balance

Swinging a pendulum up from hanging and catching it upright is the oldest benchmark in control. With two links it stops being a trick, and with three it is a research problem: there is no rule of thumb that gets the upper links over the top. The motion has to be computed, and here it is computed in your browser, from the state the chain is actually in.

Interactive simulation Every assumption is an input No registration Runs in your browser

Three rods and two free hinges. The cart has to bring all three over the top together, through a motion that is chaotic almost everywhere — and arrive within a fraction of a degree. Once it is up, it is shoved.

50N

The most the four cables can pull the suspension with, in any direction. The planner keeps a fifth of it in reserve for the feedback to use.

0.40m

Pivot to the first hinge. A longer link is slower, and needs more travel to swing.

0.40m

The first hinge to the second, or to the tip of a two-link chain.

0.35m

The third hinge to the tip, when the chain has three links.

0.25kg

Carried at the end of the link, as a weight on a light rod.

0.20kg

The weight at the second hinge, or the tip of a two-link chain.

0.15kg

The tip weight of a three-link chain.

Advanced parameters3
20°

How far the chain is held out along x when the run starts.

10°

How far the chain is held out across x when the run starts. Together with the starting swing it sets the vertical plane the chain hangs in, and is swung up in; the cable cross is turned on its ring to suit.

1.5kg

What the motors have to accelerate before they move the chain at all.

Ready

Control system

PLANNER · FDDP IN A WORKER · AGAIN EVERY 60 MS first plan — s · re-plans — · last — ms path + forces, 3 s ahead TRACKING TIME-VARYING LQR ON THE WAY UP BALANCE LQR · 100 HZ AT THE TOP MOTORS · ±— N X — N Y — N CART & CHAIN INTEGRATED AT 500 HZ tip — m · energy — % links —° · —° · —° from vertical measured state The planner runs beside the loop, not in it: the chain keeps flying the last plan while the next one is being solved.
  • —mTip height
  • —sTime
  • —%Energy of standing up
  • —°First link from vertical
  • —°Second link from vertical
  • —°Third link from vertical
  • —NMotor X
  • —NMotor Y
  • —mCart along X
  • —mCart along Y
  • —sFirst plan took
  • —Re-plans in flight

This is a model, not a recording. Nothing is animated: the chain is integrated from its equations of motion, and the only thing driving it is the force the controller asks of the two motors under the cart.

Try this

  1. Run Three links, then Two links, then One link, and watch First plan took. One link is found in hundredths of a second, two in about a tenth; three can take a few seconds, because the planner is trying durations and directions until one ends standing — calmly.
  2. Watch Motor X and Motor Y as the chain swings up. Held out 20° along x and 10° across it, the chain hangs in a vertical plane at about 27° to x and is swung up in it, so the force on the suspension stays close to that line; the small departures from it are the sideways loop keeping the chain in its plane.
  3. Set the starting swing to 0 and the lean to 25°. The chain now hangs in the plane square to x, and the cable cross turns on the ring to suit before the run starts.
  4. Watch the strips a second after the chain is caught. The suspension is shoved with 10 N along y — at about 63° to the plane the chain was swung in, so mostly across it — and the balancing loop takes it out.
  5. Pick Three links, open Advanced parameters and make the third link 0.5 m. A long top link is the hardest chain to fly; the plan is the same kind of motion, but the planner and the tracking loop have far less room for error.
  6. Run an experiment twice. The second run usually plans almost instantly: it starts from the plan that worked last time, for the same chain.

What is on the machine

  1. Ring trackA circular track on eight posts, round the outside of everything the chain can reach. It is sized from the chain: the suspension's travel, the slack before a run is stopped, the chain's length, and a margin.
  2. Four winches and cablesFour carriages on the ring, each with a winch, in a cross at 90°. Winding some in and paying others out moves the suspension any way across the floor. Before each run the cross is turned on the ring so the plane of the swing runs between its cables.
  3. Gimbal suspensionA short bar square to the swing, with the cables at its ends; an outer ring turning about the bar, and a cross axle on the ring that the first link's hub is clamped to — a gimbal, like a gyroscope's, reduced to what a single link needs. The chain can go right round in its plane, and lean out of it.
  4. Cardan jointsEach hinge is a cardan joint: a fork on each link and a cross between them. The fork above holds the cross by the arm square to the plane of the swing — the bend the swing is made of — and the fork below, turned a quarter round, holds it by the other arm, which lets the link lean out of that plane. Nothing drives them.
  5. Tip trailWhere the tip has been in the last few seconds. On the way up, a fainter line shows where the current plan expects it to go.
  6. Signal stripsThe two motor forces and the angle of each link from vertical, recorded over this run.

What this model computes

The physics
behind the picture

The rig is a gimbal suspension held by four cables from winches on a ring track round the outside, as cameras are flown over stadiums; a chain of one to three rods hangs from the gimbal. Each hinge lets its link swing in any direction, so every link has two angles and the whole chain moves in space, not in a plane. The equations of motion come from the Lagrangian of point masses on light rods and are integrated with a fourth-order Runge–Kutta step; with the motors off and the hinges frictionless, a two-link chain's energy drifts by less than a nanojoule over ten seconds.

The swing-up is found by trajectory optimisation. A feasibility-driven DDP solver (FDDP) searches for the cart forces that end with the chain standing still upright, within the motors' limits. It starts from a rough picture of the motion — each link turning up over the manoeuvre, in a chosen direction — and is allowed to pass through physically impossible states on the way, closing the gaps as it converges. However the chain starts, it hangs in some vertical plane, and the swing is solved in that plane, on the planar equations: the same physics with the sideways coordinates taken out, several times faster.

Hanging straight down, the chain is swung up in a vertical plane at 45° to the axes; held out to one side, in the plane it hangs in. Gravity points down and the cart is the same in x and y, so the physics does not care which vertical plane the chain swings in: the swing is solved once, in that plane's own coordinates, and flown by the four winches, which can pull the suspension equally hard any way. The simulation itself runs in the frame of that plane — the full three-dimensional motion, only turned. What the plane does not do on its own is hold the chain in it — the inverted chain is unstable every way — so a second, sideways loop flies the chain's offset and lean across the plane, with gains recomputed along every new plan. Mirror symmetry about the plane keeps the two loops apart to first order.

With three links the search itself is the hard part. How long the swing should take and which way each link goes round are part of the answer, and only about a third of the combinations converge — a different third for every chain. So the planner tries them in two background workers at once, drops a try early when it is plainly not closing in, and keeps the first plan that ends standing. It also rejects plans that are upright only on paper: the solver readily finds swing-ups in which a link whirls round three or four times, and at that speed the small disagreement between the planner's model and the chain grows faster than any feedback can remove it. The winning plan is then refined on a step twice as fine before it is flown.

A plan is only an open-loop recipe, and a real chain never follows one exactly. A time-varying LQR loop flies it: at every step it compares the chain with where the plan said it would be and corrects the force, with gains computed along that particular path. The plan is made with four-fifths of the motors' force so the correction always has room. While the chain swings, the planner keeps working: every 60 ms it re-solves the rest of the swing from the state the chain is actually in, starting from the plan it already has. That is model-predictive control, done the way a real controller has to: the computation takes time, and the chain does not wait for it.

At the top, a constant-gain LQR loop running at 100 Hz takes over from the plan and holds the chain upright. It only works close to vertical — for three links it recovers a tilt of 17° if all links lean the same way, but barely 1° if they are bent into a zigzag, because that is the mode the motors are slowest to correct. Which is why the swing-up has to arrive within a fraction of a degree, and why it has to be planned rather than improvised.

The rig is drawn the way it would have to be built for a chain that goes right round. Nothing may cross the plane of the swing within reach of the chain, so nothing is built over it. A ring track on posts runs round the outside, far enough out that the chain cannot touch it from anywhere the suspension may go: if the suspension ever overran its travel by more than 15 cm the run would be stopped first. Four carriages on the ring each carry a winch, their cables running to the two ends of a short bar on the suspension at 45° either side of it. Before a run the whole cross is turned on the ring so that the plane of the swing runs square to the bar, between the cables, and no cable can ever cross it. The suspension is a gimbal — an outer ring turning about the bar, a cross axle across it, and the first link's hub clamped onto the axle — and with the bar square to the swing it never locks. The model takes the cables as taut and the suspension's height as held exactly.

The structure here — an optimised feedforward swing-up flown by a time-varying Riccati feedback, then a balancing loop — is the one TU Wien used for the first experimental swing-up of a triple pendulum. The solver is different and the parameters are illustrative. The approach follows Glück, Eder & Kugi — Swing-up control of a triple pendulum on a cart with experimental validation (Automatica, 2013).