Double & Triple Inverted Pendulum Control

Double & Triple Inverted Pendulum Control

Double & Triple Inverted Pendulum Control

A Beginner’s Guide to Theory, Algorithms, Stability, and Robustness.

Hands-on Learning
Hands-on Learning

Date

November 24, 2026

Updated

November 25, 2026

Category

Blog

Word count

2.5k words

Views

11
Hands-on Learning
Hands-on Learning

Date

November 24, 2026

Updated

November 25, 2026

Category

Blog
stabilityinverted pendulumcontrol algorithmrobustnesscontrol

Word count

2.5k words

Views

11
Connected Post Group(3 linked views)

Double & Triple Inverted Pendulum Control: A Beginner’s Guide to Theory, Algorithms, Stability, and Robustness


1. Background: What Is an Inverted Pendulum & Why Does It Matter?

Imagine trying to balance a broomstick upright on the palm of your hand.

  • If the broomstick leans right, you quickly slide your hand right to get underneath it.

  • Now imagine stacking a second broomstick on top of the first with a free hinge (Double Inverted Pendulum).

  • Now stack a third hinged broomstick on top of that (Triple Inverted Pendulum).

You still only have one hand (one horizontal motor pushing a cart left or right), yet you must keep two or three hinged rods balanced vertically without falling—and move the cart to a target spot along a track.

Why Engineers Study This System

Although it looks like a circus trick, the cart-pendulum is one of the most famous benchmark problems in control engineering because it shares the exact same physics as critical real-world systems:

  1. Rocket Launchers (SpaceX / NASA): A rocket balancing on its bottom thruster gimbal is literally a giant inverted pendulum.

  2. Humanoid & Bipedal Robots: Walking robots stay upright by shifting their feet and hips underneath their center of mass—a multi-link inverted pendulum.

  3. Self-Balancing Vehicles: Segways and two-wheeled balancing robots.

  4. Overhead Cranes & Robotics: Moving heavy suspended loads quickly without violent swinging (the hanging-to-upright inverse problem).


2. System Modeling & Theory (Without the Headache)

2.1 Generalized Coordinates (How We Describe Motion)

To control the system, we measure:

  • : Horizontal position of the cart along the rail (in meters).

  • : Angle of the bottom link from vertical upright (, ).

  • : Angle of the middle/top link from vertical upright.

  • : Angle of the top link from vertical upright (for the 3-link system).

Putting positions and velocities together gives our state vector :

  • Double Pendulum (3 DOF 6 States):

  • Triple Pendulum (4 DOF 8 States):

There is only one control input: the horizontal force applied to the cart.

2.2 Three Reasons This System Is Hard to Control

  1. Naturally Unstable: Any tiny tilt grows exponentially if .

  2. Underactuated: You have 1 motor () trying to control 3 or 4 independent motions (). You cannot grab the top link directly—you can only whip the cart underneath it.

  3. Non-Minimum Phase ("Counter-Steering"): Suppose the pendulum is upright at and you want to move the cart right to . If you immediately push the cart right, the links lag backward (left) and fall over! Instead, the controller first nudges the cart slightly left so the links lean forward (right), then accelerates right to catch up with them and settle at .

2.3 Nonlinear Equations of Motion (Euler–Lagrange)

Using energy—Kinetic Energy (how fast each mass moves and rotates) minus Potential Energy (how high each center of mass is)—the Lagrangian produces the exact nonlinear equation of motion:

In plain English:

  • : Inertia matrix — how heavy the cart and links feel together (changes with the angles ).

  • : Coriolis & centrifugal forces — whipping forces created when links swing past each other.

  • : Friction — cart rail drag and joint damping.

  • : Gravity — pulls every tilted link downward ().

  • : Motor force — pushes only the cart directly.

2.4 Linearization Around Upright ()

Near vertical upright, and , which simplifies the nonlinear physics into a linear state-space model:

This model is the foundation for LQR, MPC, and Pole Stability Analysis.


3. Double vs. Triple Pendulum: What Changes?

Adding just one extra hinged link on top makes the physics dramatically faster, more coupled, and less forgiving:

Property

Double Inverted Pendulum (2-Link)

Triple Inverted Pendulum (3-Link)

Degrees of Freedom (DOF)

3 ()

4 ()

State Vector Size

6 states

8 states

Open-Loop Unstable Poles

2 positive real poles ()

3 positive real poles ()

Error Doubling Time

(nearly twice as fast!)

Modal Shapes

2 modes (in-phase lean, S-bend)

3 modes (lean, S-bend, fast Z-zig-zag)

Typical Actuator Limit ()

Max Recoverable Upright Tilt

Swing-Up Difficulty

Moderate (2 links must phase-align at top)

High (3 links must align simultaneously)


4. Comparison of Control Algorithms

Here is how the major control algorithms compare on both 2-link and 3-link pendulums:

4.1 PID Control (Proportional–Integral–Derivative)

  • Idea: Reacts directly to error (), accumulated error (), and rate of change ().

  • Double / Triple Performance: Poor / Fails. PID is built for Single-Input Single-Output (SISO) loops. Running separate PID loops for , , , and fights itself because pushing the cart affects all links at once in opposite directions.

4.2 LQR (Linear Quadratic Regulator)

  • Idea: Uses the linearized model to find the optimal state-feedback gain :

    by minimizing a cost balancing tracking accuracy () against motor effort ():

    Solving the Continuous-Time Algebraic Riccati Equation (CARE) gives automatically.

  • 2-Link vs. 3-Link:

    • Works wonderfully near upright for both 2 and 3 links.

    • Limitation: Ideal LQR assumes unlimited motor force. If tilts get large enough that clips at (actuator saturation), clipped LQR loses stability much sooner on a 3-link pendulum than on a 2-link pendulum.

4.3 Constrained Linear MPC (Model Predictive Control) + ESO

  • Idea: At every control step (e.g., every ), MPC predicts the next steps ( into the future) and solves a fast Quadratic Program subject to hard limits:

    Pairing MPC with an Extended State Observer (ESO / Kalman Filter):

    1. Estimates all velocities () smoothly from noisy angle and position sensors.

    2. Estimates unknown friction or external load bias and cancels it out.

  • 2-Link vs. 3-Link:

    • Best choice for upright balancing & hardware robustness on both systems.

    • Because MPC anticipates rail boundaries and force limits before hitting them, it safely catches larger tilts and handles sensor noise and friction far better than plain LQR.

4.4 2-DOF Trajectory Optimization + TV-LQR (For Swing-Up)

  • Idea: LQR and Linear MPC only know the upright linearization—they cannot swing a pendulum up from hanging down (). Simple energy-pumping heuristics work for 1 link, occasionally catch 2 links, and fail on 3 links.

  • Solution (Two-Degree-of-Freedom Control):

    1. Trajectory Planning (Direct Collocation): Solve the full nonlinear equations of motion over from to respecting and , producing nominal .

    2. Online Feedback Tracking (TV-LQR): Follow the path using Time-Varying LQR gains along the swing:

    3. Top Catch: Once all links enter the upright capture basin (), hand off to infinite-horizon LQR or Constrained MPC.

Algorithm Summary Matrix

Algorithm

Handles Upright Balance?

Handles Swing-Up ()?

Respects & Rail Limits?

Rejects Friction & Noise?

Best Use Case

PID

Barely (1-link only)

No

No

Poor

Simple 1-link demos

CARE LQR

Yes (2 & 3 links)

No

No (clips blindly)

Moderate

Clean upright stabilization

Constrained MPC + ESO

Yes (2 & 3 links)

No

Yes (explicitly)

Yes (via ESO)

Robust upright control & tracking

Direct Collocation + TV-LQR

Yes (handoff at top)

Yes (2 & 3 links)

Yes

Good (with TV-LQR)

Full down-to-up swing-up


5. Stability, Robustness & How to Read a Pole Plot

5.1 Short Answer: Are All Poles on the Left Side Always Stable?

Yes! In a continuous-time pole plot (-plane), if all closed-loop poles are strictly on the left-hand side (left of the vertical zero line), the linear control system is stable—meaning if you nudge the pendulum, it will always return to upright (0°) instead of falling over.

(One real-world caveat: Having all poles on the left side guarantees linear stability near upright. If the pendulum starts too far tilted or gets kicked harder than your motor limit , the motor hits saturation and it can still fall—which is why we check both pole plots and nonlinear simulation!)

5.2 The Easiest Way to Read a Pole Plot (Think of It Like a Weather Map)

Every pole is just a dot with two coordinates: (Left/Right, Up/Down). Those two directions tell you two completely different things about how the pendulum moves:

1. Left vs. Right (Horizontal Axis = Shrink or Explode)

  • Left Side (): STABLE — Any tilt shrinks over time like . Farther left = recovers faster.

  • Right Side (): UNSTABLE — Any tilt grows over time like (the pendulum falls over). Farther right = falls over faster.

2. What Is the "Imaginary Axis"? (The Vertical Line at )

The Imaginary Axis is simply the vertical line at —the borderline fence separating Stable (left) from Unstable (right).

  • Why "Imaginary"? Numbers along the horizontal axis are normal "Real" numbers (), while numbers going up and down use , called "Imaginary" numbers (). Nothing about it is fake—in physics and control engineering, the vertical height simply measures oscillation speed (wiggling / bouncing).

  • What happens if a pole sits right on the Imaginary Axis ()?

    • At the center : Like a frictionless cart on ice—push it, and it drifts at steady speed forever without returning or exploding.

    • Up/down on the vertical line : Like a frictionless swing—it swings back and forth forever at the same amplitude, never dying down and never blowing up (marginally stable).

3. Up vs. Down (Vertical Height = How Fast It Wiggles)

  • Height (dot sits right on the horizontal line): Zero wiggle. The pendulum moves straight back to 0° smoothly without bouncing past 0°.

  • Farther Up/Down from the horizontal line (larger ): Faster wiggling (higher frequency). Divide by to get bounces per second in Hz. (Every oscillation appears as a symmetric top/bottom mirror pair and .)

4. How to Judge a Good Controller at a Glance

  1. All ✕ marks left of the vertical zero line? Stable!

  2. Comfortably far left (e.g., -1 to -10), not hugging 0? Fast recovery and safe margin!

  3. Inside a cone to the left (vertical height distance left)? Well-damped (), smooth response without violent shaking! (Very tall dots barely left of zero like -0.5 ± 12j ring back and forth many times before settling.)


5.2 Stability vs. Robustness: Why "Barely Stable" Isn't Enough!

A controller is stable if its nominal closed-loop poles are in the Left Half Plane. A controller is robust if it stays stable even when real-world hardware doesn't match your math model (e.g., error in mass, link length, motor strength, or friction).

Look at what happens to the rightmost closed-loop poles under plant uncertainty:

5.6 Four Key Robustness Metrics to Watch

  1. Worst-Case Spectral Abscissa ( under Uncertainty):If all perturbed poles stay well to the left of zero (e.g., ), the pendulum won't tip over if your mass estimate is slightly off.

  2. Minimum Damping Ratio ():Keep . Low damping causes violent high-frequency shaking that wastes energy and excites unmodeled structural flex.

  3. Nyquist Vector Margin ():Measures the shortest distance from the open-loop frequency curve to the critical instability point . Ideal LQR guarantees (and peak sensitivity ); higher () means stronger tolerance to unmodeled time delays.

  4. Gain & Phase Margins:

    • Gain Margin (dB): How much stronger or weaker the motor can get before instability.

    • Phase Margin (): How much sensor or computation delay the loop can tolerate (aim for ).


6. Beginner’s Tuning & Design Cheat Sheet

  1. Start at Upright with LQR/MPC First: Verify your model and pole plot show all ✕ poles strictly left of the imaginary axis before attempting any swing-up.

  2. Tune and Intuitively:

    • Pendulum falls over too easily? Increase angle weights (), especially on the top link.

    • Motor slams back and forth at ? Increase control penalty (gives a gentler controller with a larger capture basin).

    • Cart drifts too slowly to ? Increase slightly—but keep it moderate so cart tracking doesn't steal motor force needed to balance the links.

    • Too much ringing/oscillation? Increase velocity weights () to raise damping and pull poles away from the imaginary axis.

  3. Use MPC + ESO When Constraints & Friction Matter: If the track is short, force limits are tight, or friction/sensor noise is present, Constrained MPC + ESO keeps the system inside bounds while canceling steady-state load bias.

  4. Use Direct Collocation + TV-LQR for Swing-Up: Plan the nonlinear swing-up path first, track it with TV-LQR, and switch to MPC/LQR as soon as all links enter the upright capture basin.

  5. Why Can a System Be Unstable Even When All Poles Are on the Stable Left Side?

    Linear pole plots ignore motor force limits (±u_max) and large-angle nonlinearities, so overly aggressive controller gains still saturate the actuator, miss the upright capture zone, and cause the real pendulum to fall.


8. Exercise

  • Inverted Double Pendulum Control Design

    https://www.zinniascape.com/posts/4ef3dbe5-88f3-4bb4-b062-40601f180627

  • Triple Inverted Pendulum Control Design

    https://www.zinniascape.com/posts/d2899a18-0c45-4be3-9825-39bb4164e880