- A project to implement MPC control calculation with constraints on Microcomputer (Teensy4.1) for simple autonoumous driving control.
- The vehicle uses Kinematic Bicycle Model.
- The program utilizes Quadratic Programming solvers and run on PlatformIO IDE.
Main files of this project are stored in src folder (because of platformIO configuration), including:
- konfig.h
- matrix.cpp
- matrix.h
- mpc.cpp
- mpc.h
- mpc_constrainedschur_engl.ino
- Install the PlatformIO
- Configure the system for Teensy40 (as environment) and Teensy41 (as a device, change this to your Arduino system, accordingly)
- Build and Upload
For custom implementation, you need to modify konfig.h
and *.ino
files. More specifically:
- Set the length of
X, U, Z
vectors and sampling timedt
inkonfig.h
, depend on your model. - Set the MPC parameters like
Hp (Prediction Horizon)
orHu (Control Horizon)
inkonfig.h
, depend on your application. - Enable/disable and set the MPC constraints parameters like
DU
,U
, orZ
inkonfig.h
, depend on your application. - Define the (linear) matrix system
A, B, C
and MPC initialization valueweightQ, weightR
in the*.ino
file.
After that, you only need to initialize the MPC class, set the non-zero initialization matrix by calling MPC::vReInit(A, B, C, weightQ, weightR)
function at initialization, and call the function MPC::bUpdate(SP, x, u)
at every sampling time to calculate the control value u(k)
.
- Matrix
- Quadratic Programming solver
- Optimization
This project is adapted from a public repo by pronenewbits. Thanks for developing such a good repo and detailed docs.