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.
x
0.000
m
theta
0.0
deg
F
0.00
N
|theta|max
0.0
peak (deg)
The pole angle as a function of cart force, linearized at the upright equilibrium (sinθ→θ, cosθ→1, drop ω2):
The PID controller actually integrated by the simulator, with the derivative filtered by a first-order pole at −N:
Loop gain L(s) = C(s) · P(s) (unity feedback):
Closed-loop poles (roots of 1 + L(s) = 0):
Model note: These poles are for the simplified 2-state
linearization P(s)=1/(As²+B) (Åström & Murray Ex. 2.2).
The simulator integrates the full nonlinear cart-pole with 5+
states and saturation. The two models may disagree: the nonlinear system
can remain bounded even when the simplified model predicts instability.
The cart-pole has four state variables: cart position x, 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/s | 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