demoAIRobotics
A cart-pole, balanced by a PD controller
The pole starts 15 degrees from upright. A controller that pushes the cart in proportion to the pole's angle and rate, and a little toward the origin, catches it in under two seconds and holds it. At a fifth of the gains it falls.
Open in the workbenchDownload .vivOutputs below are from the site build’s run; Run all runs it again in your browser.
Look inside this program
- Atlas
The program’s map: every function and which calls which.
There’s no recorded run of this program yet.
The dynamics, the integrator and the drawing come from lib/cartpole, loaded with
import cartpole; this post adds the controller and the tests. The force is
, with the cart terms
small and positive: to move the cart left toward the origin, the controller must first
lean the pole left, and the way to do that is a push to the right.
The gains are top-level constants, so viv run --set K_THETA=30 ... tries another
controller without editing the program.
Printed
Tests 3 of 3 pass
- after two seconds the pole stays within two degrees of upright (passes)
- and the cart comes back to within 10 cm of where it started (passes)
- at a fifth of the gains the pole falls over (passes)