Awesome Open Source
Awesome Open Source

# Fastest-lap

Fastest-lap is a vehicle dynamics simulator. It can be used to understand vehicle dynamics, to learn about driving techniques, to design car prototypes, or just for fun!

### What can be done

• Numerical G-G diagram: given a vehicle, and a speed, to compute its ax-ay diagram. The G-G diagram is a useful technique in vehicle design and parameters exploration.

This is solved as an optimization problem: for a given lateral acceleration, find the minimum/maximum feasible longitudinal acceleration.

• Optimal laptime simulation: given a vehicle, and a circuit, to compute the optimal controls that minimize the laptime.

This problem is solved using a first order collocation method, the trapezoidal rule, with higher-order methods planned to be implemented soon. The NLP is solved using Ipopt, and CppAD to enhance its performance (a lap-time around Circuit de Catalunya can be obtained with 500 points in approximately 1 minute).

This is not a quasi-steady-state simulation. The model solves the fully transient states as in the dynamic equations without steady-state assumptions.

https://user-images.githubusercontent.com/26557659/163474269-5c195f4b-2109-419d-af49-7b7fa86a603d.mp4

### The approach

The core of the software is a C++ library, that can be used through a Python API. Full documentation is not yet available but some examples can be found in examples/python. Fastest-lap is very efficient, being able to compute a full optimal lap in less than 1 minute.

### Dynamic models

The code implements two car models:

### Circuits

Circuits are modeled from paths created from google earth, for example, the right track limit of Catalunya is included in this repository (database/google_earth/Catalunya_right.kml). Circuits are then preprocessed with a tool included herein to extract a reference line, its curvature, and the distance to the left/right track limits (database/catalunya_discrete.xml).

### Dependencies

Fastest-lap uses several open-source libraries:

• Ipopt: Interior Point OPTimizer, is an open source software package for large-scale nonlinear optimization. Used within this project to obtain the solution to optimal laptime problems written as NLP (Non-linear programming problem).
• CppAD: C++ Algorithmic Differentiation. Distributed alongside Ipopt, it is used to compute analytical derivatives.
• Tinyxml2: TinyXML-2 is a simple, small, efficient, C++ XML parser, used to read XML files (e.g. model parameters, tracks,...)
• logger-cpp: a simple logger in C++, to handle print levels, and other interesting add-ons
• lion-cpp: lightweigh interfaces for optimization and numerics, a C++ package manager for all the libraries mentioned above, plus other numerical methods such as mechanical frames, vector algebra, and Runge--Kutta schemes

### Installation

#### Windows 10

• bin: the dynamic libraries. Fastest-lap C++ core is there. If fastest-lap is used from MATLAB, point `loadlibrary()` to this directory.
• include: fastestlapc.h and fastest_lap.py. To use python scripts, make sure this folder is on the `PYTHONPATH`
• examples: python notebook examples.
• database: car and track data

#### Mac and Linux

This project uses CMake to build the source code and produce the binaries.

The canonical steps to compile a CMake project are: (assume `\$FASTESTLAP` is the source code top level.)

1. Create a build folder.
``````mkdir \${FASTESTLAP}/build
``````
1. From the build folder, run cmake
``````cd \${FASTESTLAP}/build && cmake ..
``````

The options available for cmake are:

``````-DCMAKE_BUILD_TYPE=Debug/Release
-DCMAKE_INSTALL_PREFIX=/path/to/install/dir
-DCODE_COVERAGE=Yes/No: enables code coverage (if so, use with -DCMAKE_BUILD_TYPE=Debug)
-DBUILD_DOC=Yes/No: builds doxygen documentation
``````

At this stage, CMake will download and install all the thirdparty dependencies.

1. Compile
``````make
``````
1. Test (optional but recommended)
``````ctest --verbose
``````
1. Install (optional)
``````make install
``````

#### Linux

A Docker build environment is provided and can be used to compile the shared library and generate the Python bindings.

``````sh ./src/scripts/linux/docker_compile.sh
``````

### Documentation

Read the latest fastest-lap online documentation

### References

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Python (807,639
C Plus Plus (238,904
Vehicle (6,136
Circuit (4,093
Optimal Control (114
Racing (99
Formula1 (81
Ipopt (26
Racecar (7
Motogp (4