This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Notebooks · posts/cart-pole-balanced

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.

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.

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.

[1]lines 21–79