I keep here my (old) notebooks on Model Predictive Control for path-following problems. Includes a Pybullet simulation to demo the controller. This mainly uses CVXPY as a framework. This repo contains code from other projecs, check them out in the special thanks section.
-
State space model derivation -> analytical and numerical derivaion of the model
-
MPC -> implementation and testing of various tweaks/improvements
-
Obstacle Avoidance -> Using halfplane constrains to avaoid track collisions -> Sill work in progress!
Racing car model is from: https://github.com/erwincoumans/pybullet_robots.
Results:
The settings used for tuning the MPC controller are in the mpc_config class.
The results above can be reproduced both in Docker and Conda.
From this repository root directory:
docker build -t mpc-demo -f docker/Dockerfile .
- To run the pybullet demo:
xhost +local:docker
docker run -it --net=host --ipc=host --privileged \
--env="DISPLAY" \
--env="QT_X11_NO_MITSHM=1" \
--volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
--volume="${XAUTHORITY}:/root/.Xauthority" \
mpc-demo:latest \
bash -c "python3 mpc_demo_pybullet.py"
- To run the simulation-less demo: change the last command to
python3 mpc_demo_nosim.py
.- this is a simpler demo that does not use pybullet, useful for debugging.
In both cases the script will promt the user to press enter
before starting the demo, pybullet may take a few seconds.
The environment used for this project can be repoduced via conda:
conda env create -f env.yml
conda activate simulation
The demos can be run with:
python3 mpc_demo_pybullet.py
python3 mpc_demo_nosim.py
This environment also includes jupyter lab
to experiment with the jupyter notebooks.