Inverted Pendulum Simulator

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.

Cart-Pole Animation

Presets:
Default parameters
Cart position x Reference (target x) Pole Control force F

Time-Series Response

Cart x (m) Setpoint (m) Pole angle (deg) Control F (N)

x

0.000

m

theta

0.0

deg

F

0.00

N

|theta|max

0.0

peak (deg)

Cart and Pole Parameters

2.0 kg
0.2 kg
0.5 m
0.1
0.01

PID Gains

30
0
0.5
20
30 N

Plant Transfer Function (live)

The pole angle as a function of cart force, linearized at the upright equilibrium (sinθ→θ, cosθ→1, drop ω2):

Controller Transfer Function (live)

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.

Equations of Motion

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 Definitions

Symbol Units Meaning
mCart position along the rail (positive = right of center)
m/sCart velocity
radPole angle from vertical (0 = upright, positive = falling to the right)
rad/sPole angular velocity
NControl force applied to the cart (clamped to )
NForce saturation limit (slider, default 30 N)
mSetpoint for cart position (0 by default)
kgCart mass (slider)
kgPole mass (slider)
mHalf-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/mCart viscous friction coefficient (slider)
N·m·s/radPivot viscous friction coefficient (slider)
PID gains (sliders)
1/sDerivative-filter pole (slider). is the filtered pole angular velocity:
radPole-angle error (target 0; the PID acts on this). Equivalent to the pole angle θ in this controller.
rad·sIntegrated pole-angle error (anti-windup not shown in the compact form)
Cite this tool: Li, H. (2026). Inverted Pendulum Simulator. https://hongbinli.ca/tools/inverted-pendulum-simulator