Skip to content

mcarfagno/mpc_python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

203 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mpc_python

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 model

This 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.

Note: 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!

Showcase

You can run the demo with MuJoCo and the mushr car or just python with no physics simulation:

MuJoCo simulation with the mushr car model (without obstacles) Headless toy demo with dummy car (without obstacles)
MuJoCo simulation with static obstacle avoidance Headless toy demo with static obstacle avoidance
MuJoCo simulation with moving obstacle avoidance Headless toy demo with moving obstacle avoidance

Getting started

Here is a brief overview of the codebase:

mpc_python
├── config/
│   ├── mpc.yaml           # the configuration of the MPC. Start here!
│   └── simulation.yaml    # common configuration of the demos
└── mpc_python/
    ├── cvxpy_mpc/
    │   ├── cvxpy_mpc.py   # main mpc implementation
    │   └── utils.py
    ├── models/
    │   └── mushr/         # model from prl-mushr/mushr_mujoco_ros
    ├── mpc_demo_mujoco.py # mujoco demo entry point
    └── mpc_demo_nosim.py  # no physics demo entry point

There are a few ways to run this:

Nix Flake ❄️

A Nix flake is provided for a reproducible development shell.

Just run the 2 examples below:

nix run --impure .#mujoco-demo
nix run .#nosim-demo

Otherwise, enter the development shell: this is heavier but also includes jupyter lab to experiment with the notebooks.

nix develop --impure

GUI demos require nixGL (auto-detects Intel/AMD/NVIDIA GPU):

nixGL python mpc_python/mpc_demo_mujoco.py

Headless demos run without it:

python mpc_python/mpc_demo_nosim.py

Conda

conda env create -f env.yml
conda activate simulation

Then run the scripts:

python3 mpc_demo_mujoco.py
python3 mpc_demo_nosim.py

Notebooks

  1. Model derivation — analytical and numerical derivation (1.0, parametrized curves, differential, motion model)

  2. MPC — implementation and testing of various tweaks (2.0, 2.1, 2.2, 2.3)

  3. Obstacle Avoidance — halfplane constraints to avoid track collisions (3.0, 3.1) — Still work in progress!

References & Special Thanks ⭐ :

About

A simple MPC controller for path tracking implemented in python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors