mcarfagno/mpc_python
A simple MPC controller for path tracking implemented in python
What it solves
This project addresses the challenge of moving from basic control methods to real-time convex optimization for vehicle path tracking. It provides an easy-to-follow implementation of an iterative Model Predictive Control (MPC) controller that handles non-linear kinematics through iterative linearization, while keeping the optimization problem strictly quadratic (QP) using CVXPY instead of relying on non-linear solvers like CasADi.
How it works
The controller is implemented with CVXPY, maintaining a strict quadratic programming framework. To handle real-world vehicle physics, it uses iterative MPC (iMPC): at each step, the non-linear vehicle model is linearized around the current state, and a convex QP problem is solved to compute optimal control inputs. The repository includes demos that simulate the vehicle either in MuJoCo with the mushr car model or in a headless toy environment without physics. Configuration files (mpc.yaml, simulation.yaml) let you adjust MPC parameters and simulation settings. The codebase is organized into a main MPC implementation (cvxpy_mpc.py), utility functions, a models folder with the mushr vehicle, and two entry points for running demos with or without MuJoCo.
Who it's for
This project is aimed at learners and developers who are familiar with basic control concepts and want to understand or implement real-time convex optimization for model predictive control. It is also useful for those experimenting with path-following, obstacle avoidance, and iterative linearization in vehicle control, as it provides runnable demos and notebooks that explain model derivation and MPC variations.
Highlights
- Iterative MPC with CVXPY for strict quadratic programming, avoiding non-linear solvers.
- Works with the MuJoCo simulation (mushr car model) and a headless toy demo without physics.
- Supports static and moving obstacle avoidance via halfplane constraints.
- Provides notebooks covering model derivation, MPC implementation, iterative linearization, and obstacle avoidance (still work in progress).
- Includes Nix and Conda setup options plus configuration files to tweak the controller.
Related
- Project
- Project
- Project
- Project