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

Control (vp.control)

Control design for the cart-pole in four calls.

  • cartpole_model, the cart-pole linearized about the upright
  • lqr, the optimal gain for the weights you choose
  • care, lyapunov and schur, the Riccati and Lyapunov solutions behind it
  • simulate, the nonlinear system run under that gain

The solvers are those of vp.linalg, checked by relative residuals and against SciPy.

Part of the distribution vipyr; it runs from a checkout of the repository. Planned on PyPI as pip install vipyr.

Functions

vp.control.care
The stabilizing solution X of A^T X + X A - X B R^-1 B^T X + Q = 0, as scipy.linalg.solve_continuous_are(A, B, Q, R).
vp.control.cartpole_model
The cart-pole linearized about the upright: A = df/ds (4 by 4) and B = df/du (4 by 1), by central differences of step h on the nonlinear dynamics, so the linear model is the one the simulation runs.
vp.control.lqr
The linear-quadratic regulator for xdot = A x + B u with cost int x^T Q x + u^T R u: the gain K = R^-1 B^T P, m by n, with u = -K x, and the Riccati solution P. As python-control's lqr without its third result.
vp.control.lyapunov
The X with A X + X A^T = Q, as scipy.linalg.solve_continuous_lyapunov(A, Q). lib/lyap solves A'^T X + X A' + C = 0, so A' = A^T and C = -Q.
vp.control.schur
The real Schur decomposition A = Z T Z^T: T quasi-triangular, Z orthogonal. As scipy.linalg.schur(A, output="real"). T is not unique, so compare through the residual and the eigenvalues, not entry by entry.
vp.control.simulate
The nonlinear cart-pole under the state feedback u = -K s, from the state s0 for `steps` steps of dt (fourth-order Runge-Kutta, the force held over each step). One row per time: t, x, xdot, theta, thetadot, u.

Examples in the gallery