Presets
Playback
Controller and plant
Keep Kp above (M+m) g to balance at all; delay and noise make it harder.
Layers
Model checks
The science
Why a balanced pole is a control problem
A pole standing on a cart is an inverted pendulum: with the controller off, a small tilt θ grows as θ(t) = θ0 cosh(λ t) with λ = √(g / [l (4/3 − m/(M+m))]), where l is the distance to the pole's centre of mass. For the default 1.9 m pole this is about 3.0 per second, so a 5 degree tilt becomes 45 degrees in about a second.
The controller
The cart is pushed with F = Kp θ + Kd θ̇ + Kx x + 0.6 ẋ, limited to ±Fmax. Pushing the cart under the pole's tip moves the pivot back below the centre of mass. In the linear approximation, ignoring the cart terms, the loop is stable only when Kp > (M+m) g and Kd > 0; the small Kx terms keep the cart near the middle. Their sign looks backwards: to bring a drifting cart back, the controller first has to lean the pole the right way, which means pushing the cart further away for a moment (a non-minimum-phase system). The phase plane (angle against angular rate) shows a stable controller as a spiral into the origin.
Delay, noise and saturation
Every millisecond of delay between sensing and pushing removes phase margin; around 100 to 150 ms the default gains no longer cope. Sensor noise is amplified by Kd and appears as a jittery force. If the force limit is too low the motor saturates and large tilts cannot be recovered.
Honest simplifications: a rigid uniform pole, a frictionless pivot, viscous cart drag only, ideal sensors apart from the noise and delay you add, and an instant motor. The model is the textbook nonlinear cart-pole integrated with RK4 and is identical to the 3D page.
What to try
- Press Weak angle gain: Kp = 14 is below (M+m) g = 18.8 N/rad, so the pole falls however fast the cart reacts.
- Press Slow actuator or raise the delay slider until the oscillation grows: delay costs stability.
- Turn the controller off and watch the angle graph follow cosh growth.
- Use Push and watch the phase-plane loop recover; lower the force limit until a push is no longer recoverable.