This repository contains a racing line optimization algorithm in python that uses Particle Swarm Optimization.
This version was developed and tested with python==3.8.12
. The following modules are required:
matplotlib
numpy
scipy
shapely
The input parameters are:
-
track_layout
: array of$(x,y)$ coordinates that represent the layout of the track. -
width
: width of the track. We assume it is constant along the track. They are stored in the./data/tracks.json
file.
The track borders are obtained by adding an offset (i.e. half of the width
) to the track_layout
in both directions (left and right).
Now, we define the search space of the algorithm, namely the sectors. Sectors are equally distanced segments that go from the outer border to inner border of the track. The points through which the racing line passes, will move along these segments:
To find the racing line, the algorithm will fit a cubic spline to the sector points. The vehicles's speed at each point
where
where
The algorithm's objective is to compute the fastest racing line around the track based on the laptime. Having the speed and the distance between each pair of points computed by the spline, we can compute the laptime.
Run the main.py
script to see the optimizer work. Inside the main function you will have the possibility to change the hyper-parameters of the PSO algorithm.
This project is under the MIT license. See LICENSE for more information.