A (hopefully) easy-to-follow Iterative MPC tracking controller built with CVXPY and paired with MuJoCo. Designed to help anyone looking to transition from basic control to real-time convex optimization.
MuJoCo simulation with the mushr car modelThis mainly uses CVXPY to maintain a strict quadratic programming framework rather than relying on a non-linear solver like CasADi (which I love btw!). But, implementing an iMPC, we can still bridge the gap between convex optimization and real-world vehicle physics, allowing you to handle non-linear kinematics through iterative linearization.
MuJoCo simulation with the mushr car model Headless toy demo with dummy carNote: I've also preserved my original notebooks on Model Predictive Control for path-following problems here for historical context, a bit outdated.
This repo builds upon code and ideas from other open-source projects; please check them out in the Special Thanks section!
A Nix flake is provided for a reproducible development shell.
Just run the 2 examples below:
nix run --impure .#mujoco-demo
nix run .#nosim-demoOtherwise, enter the development shell: this is heavier but also includes jupyter lab to experiment with the notebooks.
nix develop --impureGUI demos require nixGL (auto-detects Intel/AMD/NVIDIA GPU):
nixGL python mpc_python/mpc_demo_mujoco.pyHeadless demos run without it:
python mpc_python/mpc_demo_nosim.pyconda env create -f env.yml
conda activate simulationThen run the scripts:
python3 mpc_demo_mujoco.py
python3 mpc_demo_nosim.py-
Model derivation — analytical and numerical derivation (1.0, parametrized curves, differential, motion model)
-
MPC — implementation and testing of various tweaks (2.0, 2.1, 2.2, 2.3)
-
Obstacle Avoidance — halfplane constraints to avoid track collisions (3.0, 3.1) — Still work in progress!
- Prof. Borrelli - mpc papers and material
- AtsushiSakai - pythonrobotics
- alexliniger - mpcc and his paper
- arex18 - rocket-lander
- prl-mushr - mushr for the vehicle used