Implementation of some control algorithms, based on model-predictive control, for racing cars on a track.
Cascaded MPC is an unofficial implementation of [1].
Coinhsl (taken from ThirdParty-HSL)
Linear solvers that make code significantly faster
- Install dependencies
sudo apt install gcc g++ gfortran liblapack-dev libmetis-dev pkg-config --install-recommends
- Obtain a tarball with Coin-HSL source code from https://licences.stfc.ac.uk/product/coin-hsl
- Unzip the tarball
coinhsl-x.y.z.tar.gz
intothirdparty/coinhsl
and rename the unzipped folder tocoinhsl
- Run the following commands form inside
thirdparty/coinhsl
to install coinhsl libraries
./configure
make -j12
sudo make install
You should get a message like
Libraries have been installed in:
/usr/local/lib
- Install miniconda
- Create a conda environment
conda env create -yn --name vehicle-control python=3.12.0
- Install dependencies
pip install -r requirements.txt
- config: Contains configuration files encoded in a yaml format for different controllers, models and environments (track or trajectory).
- controllers: Python modules related to controllers.
- feedback_linearization: Module containing feedback linearization controllers.
- mpc: Module containing model predictive controllers.
- environment: Python modules related to code for constructing the track and some trajectories.
- models: Classes representing different models (dynamic, kinematic, etc.)
- simulation: Python modules defining the simulation cycle
- thirdparty: Third-party libraries (for now hsl libraries which deliver fast linear solvers for ipopt)
If you want to run the code, use main.py
. The script loads the config simconfig.yaml
and defines some parameters for the class RacingSimulator
.
The goal is to enhance racing performance by pushin the vehicle to its physical limits while achieving good computational performance. When using NMPC, computation times can become prohibitive with a longer planning horizon. The proposal of [1] is to be able to plan far ahead in the future while keeping things sufficiently efficient. This entails also a better racing performance. The idea boils down to using two different models:
- Singletrack for short-term planning, responsible for safety and stability
- Pointmass for long-term planning, since it is a low accuracy model
These two models are serially chained inside a single planning and control loop, resulting in a NMPC problem formulation.
In the gifs below we show some results on a test track. The plots on the right indicate respetively:
- Average computation time per prediction horizon
- Absolute speed
- Steering angle
$\delta$ - Commanded force
$F_x$ - Commanded steering velocity
$\omega$
[1] V. A. Laurense and J. C. Gerdes, "Long-Horizon Vehicle Motion Planning and Control Through Serially Cascaded Model Complexity," in IEEE Transactions on Control Systems Technology, vol. 30, no. 1, pp. 166-179, Jan. 2022
- Learning-based MPC
- Observers for the state
- More realistic track