Based on this repository
The project aims to generate optimal trajectories for a car using curvilinear bicycle model, simulate the model's behavior, and compute the control signals required to follow the trajectory. This is achieved using the do_mpc library in python, which is designed for model predictive control (MPC) applications.
Plotting depends on TeX so you may be required to install appropriate packages on your system
To install the required dependencies in a virutal python environment run: on Linux:
python -m venv ./venv
source ./venv/bin/activate
pip install -r ./requirements.txt
On NixOS you can use the development shell from this repository instead: Only use it on NixOS, this shell overrites $LD_LIBRARY_PATH which may break other systems
nix-shell
run the __main__.py
script in src
directory. You can run the following to get information about script usage:
python src/__main__.py --help
Example usage:
python src/__main__.py ./data/tracks/buckmore.json ./data/vehicles/tbr18.json 0.8 --nonlinear --plot-all
python src/__main__.py ./data/tracks/buckmore.json ./data/vehicles/tbr18.json 0.8 --bayes --plot-all
Parameters:
- Path to a json file representing the track
- Path to the vehicle model parameters (only one model is implemented, Mazda MX5 <3)
- third is a float value, depicting how much track the vehicle can use, where 1 means the whole track, and 0.1 means that only 10% of the track around the center line will be used.
- optimisation method from
--bayes
,--curvature
,--compromise
,--laptime
,--nonlinear
(On windows watch out for "\" and "/") - plot options:
--plot-path
/--plot-all
.
Examlpe usage:
python src/mpc.py --laptime
Parameters:
- optimisation method from
--bayes
,--curvature
,--compromise
,--laptime
(On windows watch out for "\" and "/") This describes what optimization was used to generate track trajectory and requires running the said optimization first, to generate required files.
The work was divided into three modules.
First, a high level trajectory optimisation, takes in a list of points that describe a race track, and according to vehicle model generates an optimal trajectory that minimizing e.g. lap time or curvature. This part is based on code by Joe Davison, which we expanded on by adding two additional methods of optimization: Bayesian and non-linear (COBYLA).
We used a few differrent methods to compare the results between them.
based on an article: Computing the racing line using Bayesian optimization. The method, in brief, is based on generating a trajectory in the form of a one-dimensional list representing the position on the track, calculating the travel time for each position, creating a database from these, and training a Gaussian regressor. The track is represented according to Racing Line Optimisation for Autonomus Vehicles. Two other representations in the track variable system were also tested, but they did not yield clear results.
Starts by generating random trajectory, chooses 10 best and using non-linear optimisation , generates an optimal trajectory. It uses COBYLA algorithm. Recently on some OS, we had some issues with multiprocessing library, where this part of script fails.
The rest of the methods are described here.
There are two models used in the project. First was already implemented. Second based on curvilinear bicycle model and Pacejka tire parameters. In order to adjust the latter to the base, there was a need to create additional functions to calculate responding constraints. It was impossible to simply recalculate one model into another.
We use a curvilinear bicycle model to simulate a car, based on an article: Optimization-Based Hierarchical Motion Planning for Autonomous Racing.
In summary, The model operates in a curvilinear coordinate system relative to a reference path, such as a race track centerline. This model includes dynamic force laws and represents vehicle states like position along the path (arc-length), lateral deviation, and heading angle.
Simplfied Pacejka tire model is used to calculate the lateral tire forces.
Important:
During tests, we found some unexpected behaviour, where without sending any control signals and initial speedex. vx = 5.0
, the car suddenly turns around 180 degrees, after about 1 second of simulation. We were able to find the cause of this error, but a more thoroughtly documented tire model would help find such errors faster
We used do-mpc library that implements a mpc controller for this part of the project. The objective function of the optimizer inside do_mpc is also based on an article: Optimization-Based Hierarchical Motion Planning for Autonomous Racing.
We were unable to get good results reliably using the controller, due to complicated boundry conditions and highly nonlinear model.
The optimizer takes a really long time to calculate the control signals (a few hours of runtime, for a few seconds of simulation), consuming a lot of RAM (approaching 16GBs)
There are two possible reasons for this behaviour, the first being a bad implementation of the model, the second being:
The do_mpc required the model to be written using symbolic expressions (using casadi library as a backend). In our project, we utilize B-splines to define the trajectory that our vehicle will follow, with these splines parameterized by a variable u
. To effectively plan and control the vehicle's path, we need a symbolic expression for the curvature at a given arc-length s
.
However, obtaining this symbolic expression directly is challenging because there is no straightforward translation between the parameter u
and arc-length s
.
As a solution, we sample the curvature at a given arc-length s, and generate a look-up table, from which we generate a symbolic expression using linear piecewise approximation.
Resulting expression, due to being a complex piecewise expression, and by nature not a smooth function, may be bad for optimization algorithms. Arc-length parametrized spline should be used to approximate the track in the place of B-spline.
Method: | curvature | Compromise | Lap Time | Bayesian Optimisation | non-linear optimisation |
---|---|---|---|---|---|
Lap time | 39.934 | 37.810 | 40.892 | 36.227 | 36.178 |
Run time | 2.037 | 35.233 | 47.472 | 22.396 | 106.063 |
Path Length | 860.772 | 790.462 | 830.327 | 773.561 | 772.140 |
Max velocity | 40.050 | 40.833 | 37.790 | 41.365 | 43.333 |
Mean velocity | 23.414 | 22.958 | 22.293 | 23.908 | 23.833 |
Method: | curvature | Compromise | Lap Time | Bayesian Optimisation |
---|---|---|---|---|
Lap time | 49.172 | 47.730 | 53.648 | 48.056 |
Run time | 5.301 | 101.786 | 65.495 | 27.840 |
Path Length | 856.095 | 810.150 | 845.530 | 806.397 |
Max velocity | 24.783 | 23.753 | 24.186 | 25.615 |
Mean velocity | 18.000 | 17.525 | 16.323 | 17.506 |