Cart-pole (inverted pendulum) with PID control. Watch the pendulum balance upright on a moving cart, tune the controller, or destabilize it with a kick to see how the controller recovers.
RK4 integrator, substepped at 0.5 ms, runs entirely in the browser.
p
0.000
m
theta
0.0
deg
F
0.00
N
|theta|max
0.0
peak (deg)
Cost = pT Q p + R F². Q penalizes state error (cart position p, pole angle θ, cart velocity v, pole rate ω); R penalizes control effort. Higher Q_θ makes the controller more aggressive on pole angle; higher R makes it more conservative.
Four real eigenvalues λi in the LHP. The page runs Ackermann pole placement to compute the gain K that places the closed-loop poles at these four locations. All four values must be negative (stable); more negative = faster response, larger control effort.
The cart-pole has four state variables: cart position p, cart velocity v, pole angle theta (0 = straight up), and pole angular velocity omega. The control goal is to keep the pole upright (θ → 0); Kp/Ki/Kd act on θ. The cart position is uncontrolled and settles to whatever offset the balance requires. Equations follow Åström & Murray, Feedback Systems (Princeton, 2008), §2.2 Example 2.2 — the simplified pole-only form (eq. 2.10) is the exact rocket-stabilization controller this tool implements. The full coupled cart-pole EOMs (eq. 2.9 in Åström & Murray, or §5 in Spong, Hutchinson & Vidyasagar, Robot Modeling and Control, Wiley, 2006) are then pre-solved into the decoupled form shown below under a point-mass assumption for the pole (mass m concentrated at the center of mass a distance L from the pivot, so I = mL2). The slider labelled L is the half-length (pivot-to-CoM distance), not the full rod length. PID form from Åström & Hägglund, Advanced PID Control (ISA, 2006). The Åström Ex. 2.2 button above loads the textbook scenario.
Want the full picture? The Inverted Pendulum Modeling and Control tutorial walks through the derivation, the linearization, state-feedback design (pole placement and LQR), and why the simplified Ex. 2.2 form cannot by itself hold the cart still.
| Symbol | Units | Meaning |
|---|---|---|
| m | Cart position along the rail (positive = right of center) | |
| m/s | Cart velocity | |
| rad | Pole angle from vertical (0 = upright, positive = falling to the right) | |
| rad/sec | Pole angular velocity | |
| N | Control force applied to the cart (clamped to ) | |
| N | Force saturation limit (slider, default 30 N) | |
| m | Setpoint for cart position (0 by default) | |
| kg | Cart mass (slider) | |
| kg | Pole mass (slider) | |
| m | Half-length of the pole (distance from pivot to center of mass; slider) | |
| kg·m² | Pole moment of inertia about the pivot. Point-mass assumption: mass m concentrated at the CoM a distance L from the pivot, so | |
| m/s² | Gravitational acceleration (9.81 m/s²) | |
| N·s/m | Cart viscous friction coefficient (slider) | |
| N·m·s/rad | Pivot viscous friction coefficient (slider) | |
| — | PID gains (sliders) | |
| 1/s | Derivative-filter pole (slider). is the filtered pole angular velocity: | |
| rad | Pole-angle error (target 0; the PID acts on this). Equivalent to the pole angle θ in this controller. | |
| rad·s | Integrated pole-angle error (anti-windup not shown in the compact form) |
https://hongbinli.ca/tools/inverted-pendulum-simulator