This repository contains an example that implements a Model Predictive Control (MPC) controller for trajectory tracking of a unicycle while enforcing safety constraints using Control Barrier Functions (CBFs). The goal is to follow a predefined reference trajectory while avoiding an obstacle and staying within a safe region.
There are already many repositories with similar implementations, but most of them are using CasADi or MATLAB. This repository instead is a Python implementation that uses CVXPY for the QP subproblem and jax for autograd as well as parallelization.
- Python 3.10+
jax
cvxpy
numpy
matplotlib
To run the demo, simply run the sqp_mpccbf_tracking.ipynb
notebook in Google Colab .
- Trajectory tracking with NMPC.
- Discrete Control Barrier Functions (CBFs) to enforce
h[k+1] - h[k] >= -a;pha * h[k]
as a MPC constraint - Sequential Quadratic Programming (SQP) for handling nonlinearities and updating the linearization at each iteration.
- QP formulation using cvxpy with cp.Parameter for warm-starting and fast updates.
- OSQP failed: remove
time_limit
argument inprob.solve(...)
or increasemax_sqp_iter
or try different QP solvers.