Skip to main content
Sandbox Physics

Control & mechanics · Force limits

Cart-Pole Balance

Can a cart's motor catch a falling pole and then bring the cart back to its start? Yes, if the release tilt is small and the motor can push hard enough. To catch a pole leaning right, the cart must first accelerate right and get back under it. The push also depends on the cart's position and speed, so once the pole is upright the cart is steered back to its start. If the push needed is larger than the motor's limit, the pole falls.

Tilt a three-dimensional cart-pole and let it go. Watch the feedback controller catch the pole and bring the cart back, and see balance fail when the motor cannot push as hard as the controller asks.

Interactive modelCart-Pole Balance
Tilt from upright00
Rod angular speed00
Delivered cart force00
Requested cart force00
Cart position00
System horizontal momentum00
Signed motor work00
Maximum sampled work-balance residual00

Physics tutorial

Catch the pole, then return the cart

BackgroundStanding straight up is an unstable equilibrium: any small lean grows. To hold it there, feedback has to respond to the actual motion, using a motor that can only push so hard.

Why it mattersRead the motion, the drive the controller asks for and the mechanical work together, as parts of one experiment.

Start with the essentials

Focus question
Why does a rightward lean first require a rightward push?
One-sentence intuition
Accelerating the base sideways rotates the pole, because the pole is pinned to the cart. The controller also watches the cart's position and velocity, so the cart comes back to where it started.

Core mathematical model

Nonlinear cart-pole dynamics

(M+m)x¨+mlcos⁡θ θ¨−mlsin⁡θ θ˙2=F,lθ¨+cos⁡θ x¨=gsin⁡θ(M+m)\ddot x+ml\cos\theta\,\ddot\theta-ml\sin\theta\,\dot\theta^2=F,\qquad l\ddot\theta+\cos\theta\,\ddot x=g\sin\theta

Tilt is measured toward the right from upright. The rod is massless and the bob is a point mass.

Full-state feedback near upright

Fd=kxx+kvx˙+kθθ+kωθ˙,F=clip⁡(Fd,−Fmax⁡,Fmax⁡)F_d=k_xx+k_v\dot x+k_\theta\theta+k_\omega\dot\theta,\qquad F=\operatorname{clip}(F_d,-F_{\max},F_{\max})

The gains are recalculated whenever you change the length or the response rate. They put all four poles of the linearized, unsaturated system at minus the response rate. Every gain sign follows the angle convention above.

Mechanical energy and motor work

E=12(M+m)x˙2+mlx˙θ˙cos⁡θ+12ml2θ˙2+mgl(cos⁡θ−1),E˙=Fx˙E=\tfrac12(M+m)\dot x^2+ml\dot x\dot\theta\cos\theta+\tfrac12ml^2\dot\theta^2+mgl(\cos\theta-1),\qquad\dot E=F\dot x

The cross term that couples cart and pole cannot be dropped. Potential energy is zero at upright. Only the change in energy is compared with the motor's work, so the choice of zero does not matter.

Common difficulties

Feedback has limits

Typical misconceptionOnce feedback is on, the system will recover from any release.

Better mental modelCompare the limit presets. These controllers balance only near upright and have limited drive strength. They are not swing-up controllers.

A balanced pole still needs the cart controlled

Typical misconceptionFeeding back the angle alone will bring the cart back to its start.

Better mental modelThe control force depends on the cart's position and velocity as well as the pole's tilt and angular velocity.

Run the experiment

  1. 01

    Tilt and release

    Drag the gold handle to set the initial tilt, then press play.

    What to observe: Watch the rod, and watch how hard and in which direction the controller drives the motor.
  2. 02

    Find the motor's limit

    Choose Too little force, then raise the force limit.

    What to observe: Look for the moment when the motor stops delivering what the controller asks for.
  3. 03

    Compare energy with motor work

    Go to the end of the playback and export the record. Then compare standard and fine integration.

    What to observe: The change in mechanical energy matches the work done by the motor, which is negative whenever the motor brakes.

Primary theory: MIT · Cart-Pole · ETH Zürich · 1D reaction-wheel model, Section II

FeedbackSomething broken, confusing, or missing on this page?Tell us
What kind of feedback?

Sent with this page’s address, its Lab ID, the site language and your device type. Please leave out personal details. Feedback is kept for up to 12 months.Privacy policy