Balancing & Optimal Control
A pole balanced on a cart falls over in half a second. Model it, find out why it's unstable, then balance it three ways: gains you place by hand, LQR's optimal gains, and model predictive control that plans within the motor's limit.
Start the lesson0/5 steps done
What you'll learn
- Predict a nonlinear system with a linear model, x' = Ax + Bu
- Read stability from eigenvalues
- Balance with state feedback by pole placement
- Choose gains from a cost with LQR, and tune them
- Respect a motor's limit with model predictive control
- Balance on noisy sensors with a Kalman filter (bonus)
Before you start
You should be comfortable with basic Python: variables, loops and functions. We'll introduce the robotics and the maths as you go. The first visit downloads the physics engine and Python, about 20 MB, and later visits load from your browser's cache.
Steps
- 1Modelling the cart-poleWrite the linear model of a pole on a cart, use it to find two pushes that stand the pole back up, and see where the model stops being right.StateLinearisationDiscrete-time modelOpen
- 2Why it falls: eigenvaluesRead the pole's fall from the eigenvalues of A, see how feedback moves them, and watch the obvious rule balance the pole while the cart runs off the rail.EigenvaluesStabilityState feedbackPro
- 3Balancing by pole placementChoose where the closed-loop eigenvalues go, compute the gain that puts them there, and balance the pole with all four states.Pole placementControllabilityAckermann's formulaPro
- 4LQR: gains from a costSay what you care about as a cost, let the Riccati iteration find the best gain, and tune two controllers: a firm one and a gentle one.Quadratic costRiccati iterationTuning Q and RPro
- 5MPC: respecting limitsWith a 1 N motor, LQR crashes the cart into the stop. Plan the next 0.4 s within the limit, apply the first push and plan again: model predictive control makes the 20 cm move.Receding horizonPrediction matricesProjected gradientPro
- ★Bonus: Balancing with noisy sensorsEvery reading is noisy now. Filter it with the model you've used all along, and balance on the estimate: LQR plus a Kalman filter.Sensor noiseKalman filterLQGPro