Fastest-lap is an optimal laptime simulator, written in C++, and with a python API.

Overview

Fastest-lap 🏁 🏎

Fastest-lap is an optimal laptime simulator, written in C++, and with a python API.

MacOS Linux

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.

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

Dynamic models

The only model implemented to date, is a Go-Kart model with 6DOF (x,y,z + yaw, pitch and roll). More models will be implemented.

The default parameters used can be found in ./database/roberto-lot-2016-kart.xml

Circuits

Circuits are modeled following Peter De Buck´s approach: connecting straights by circumference arcs.

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

Compilation

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
-DCHECK_BOUNDS=Yes/No
-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

References

[1] Tremlett, A. J., and D. J. N. Limebeer. "Optimal tyre usage for a formula one car." Vehicle System Dynamics 54.10 (2016): 1448-1473.
[2] Lot, Roberto, and Nicola Dal Bianco. "Lap time optimisation of a racing go-kart." Vehicle System Dynamics 54.2 (2016): 210-230.
[3] Dal Bianco, Nicola, Roberto Lot, and Marco Gadola. "Minimum time optimal control simulation of a GP2 race car." Proceedings of the Institution of Mechanical Engineers, Part D: Journal of Automobile Engineering 232.9 (2018): 1180-1195.
[4] Lot, Roberto, and Matteo Massaro. "A symbolic approach to the multibody modeling of road vehicles." International Journal of Applied Mechanics 9.05 (2017): 1750068.
[5] Kelly, Daniel P., and Robin S. Sharp. "Time-optimal control of the race car: a numerical method to emulate the ideal driver." Vehicle System Dynamics 48.12 (2010): 1461-1474.
[6] Piccinini, Mattia. "Path planning and control of self-driving vehicles at the limits of handling"
[7] Casanova, D. "On minimum time vehicle manoeuvring: the theoretical optimal lap"

Issues
  • Problem Compilation Project

    Problem Compilation Project

    Hello,

    I am using a Kali-linux VM. I am currently trying to compile the project and follow the different steps of the README.md. On the Linux part

    sudo sh ./src/scripts/linux/docker_compile.sh

    I'm having this following error, what am I doing wrong ?

    [100%] Linking CXX shared library libcppad_lib.so
    CMake Error: failed to create symbolic link 'libcppad_lib.so': operation not permitted
    CMake Error: cmake_symlink_library: System Error: Operation not permitted
    make[8]: *** [cppad_lib/CMakeFiles/cppad_lib.dir/build.make:146: cppad_lib/libcppad_lib.so.1227] Error 1
    make[8]: *** Deleting file 'cppad_lib/libcppad_lib.so.1227'
    make[8]: Leaving directory '/src/build/lion/build/cppad/build'
    make[7]: Leaving directory '/src/build/lion/build/cppad/build'
    make[7]: *** [CMakeFiles/Makefile2:953: cppad_lib/CMakeFiles/cppad_lib.dir/all] Error 2
    make[6]: Leaving directory '/src/build/lion/build/cppad/build'
    make[6]: *** [Makefile:130: all] Error 2
    make[5]: *** [CMakeFiles/cppad.dir/build.make:112: /src/build/lion/build/cppad/src/cppad-stamp/cppad-build] Error 2
    make[5]: Leaving directory '/src/build/lion/build/thirdparty'
    make[4]: *** [CMakeFiles/Makefile2:80: CMakeFiles/cppad.dir/all] Error 2
    make[4]: Leaving directory '/src/build/lion/build/thirdparty'
    make[3]: Leaving directory '/src/build/lion/build/thirdparty'
    make[3]: *** [Makefile:84: all] Error 2
    -- Configuration of fastest-lap
    
    CMake Error at CMakeLists.txt:90 (install):
      install TARGETS given target "tinyxml2" which does not exist.
    
    
    -- Configuring incomplete, errors occurred!
    See also "/src/build/lion/build/CMakeFiles/CMakeOutput.log".
    See also "/src/build/lion/build/CMakeFiles/CMakeError.log".
    make[2]: *** [CMakeFiles/lion.dir/build.make:107: /src/build/lion/src/lion-stamp/lion-configure] Error 1
    make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/lion.dir/all] Error 2
    make: *** [Makefile:84: all] Error 2
    -- Configuration of fastest-lap
    
    CMake Error at cmake/get-third-party.cmake:35 (find_package):
      Could not find a package configuration file provided by "GTest" with any of
      the following names:
    
        GTestConfig.cmake
        gtest-config.cmake
    
      Add the installation prefix of "GTest" to CMAKE_PREFIX_PATH or set
      "GTest_DIR" to a directory containing one of the above files.  If "GTest"
      provides a separate development package or SDK, be sure it has been
      installed.
    Call Stack (most recent call first):
      CMakeLists.txt:18 (include)
    
    
    -- Configuring incomplete, errors occurred!
    See also "/src/build/CMakeFiles/CMakeOutput.log".
    make: *** No targets specified and no makefile found.  Stop.
    
    

    Thanks for you time

    help wanted 
    opened by Xperience94 29
  • Added European Tracks

    Added European Tracks

    This PR adds six tracks. Track limits (left and right) have been constructed with Google Earth and exported to kml files (included). Both kml are post processed using fastest-lap Python command:

    fastest_lap.circuit_preprocessor(options)

    to produce a single .xml file included.

    Tracks:

    • Hungaroring
    • Jarama
    • Pau ville (city track)
    • Vallelunga
    • Varano
    • Zolder
    opened by pierre-trott 12
  • Create vehicle from XML database: check that there are not unused parameters

    Create vehicle from XML database: check that there are not unused parameters

    When a vehicle is loaded from XML, a nice feature to have would be that the program checks that all the inputs present in the XML file have been used, and to throw an exception instead.

    Having this feature could help to identify typos in the parameters that might lead to catastrophic events. For example, if one writes <front-tyre/> instead of <front-tire/> , the whole data would just be ignored and the tire parameters wouldn't be loaded.

    A way of doing this, would be that every time an XML element is read, make the software add an XML attribute _parameter_used="true". Then, after the car has been loaded, check that all the elements have this attribute set to true.

    enhancement 
    opened by juanmanzanero 9
  • Dockerize the build environment for Linux compilation

    Dockerize the build environment for Linux compilation

    Provide a Dockerized build environment for Linux compilation. The dockerfile will pull ubuntu:latest, install the required build dependencies and drop the user into a bash shell. The compilation instructions can be followed from within the docker container.

    I had difficulty building and running the library locally on my arch linux machine, either having difficulty compiling or having missing references to other packages. To avoid interference with any local machine configuration, this was the solution I came up with to build the project.

    Changes

    • Add: Dockerfile
    • Add: Script to build the docker image and to run an interactive shell inside the docker container
    • Update: lint README.md

    Tested

    I can run the example Python notebooks

    image

    Problems / Feedback

    The package builds as the docker user and in the directory of the docker container. Some of the cmake steps generate files like examples/fastest_lap.py with absolute file paths referenced from the docker container, not the host machine. Files created within the docker container inherit root permissions.

    The docker script will drop the user into a docker container and will not automatically build the project.

    opened by kktse 9
  • Unable to run circuit_preprocessor in Windows 10

    Unable to run circuit_preprocessor in Windows 10

    Hello, Thanks for sharing this great work and making it available on Windows!

    I have an issue when trying to run the circuit_preprocessor in Python (Windows 10 - PyCharms). When I try to run your example script, I get the following error:

    2022-06-27_08h47_58

    c_lib.circuit_preprocessor(c_options); OSError: [WinError -529697949] Windows Error 0xe06d7363

    I am able to run optimal_laptime.py without any problem.

    I was thinking it could be the paths could be the issue. What is the source of these relative paths I have to put in? If not, any ideas what it could be?

    Thanks in advance!

    opened by pierre-trott 8
  • Project Compilation on Windows

    Project Compilation on Windows

    Hi Juan,

    First of all I want to congratulate you on such a project, your fastest-lap looks really cool!

    I've found it very interesting and I would like to deepen it. Because of this, I would like to build the project on my Windows machine, not just use the binaries you've provided.

    I've seen that one of the third-party packages used by fastest-lap -lion- requires a Fortran compiler. Do you have any suggestions for any specific Fortran compiler on Windows as you have for Linux and Mac?

    Thanks for you time!

    opened by mambro 3
  • Argument CMAKE_BUILD_TYPE optional during cmake build

    Argument CMAKE_BUILD_TYPE optional during cmake build

    Background

    Build option CMAKE_BUILD_TYPE is 'mandatory' because STREQUAL expects an argument. Force the expression to evaluate early by checking the existence of CMAKE_BUILD_TYPE. This makes CMAKE_BUILD_TYPE an optional build argument. Defaults to Release. Fixes build errors when using Docker build script, where at this time, cmake build flags can not be passed into the script.

    Tested

    $ cmake --version
    cmake version 3.23.2
    

    Without changes

            Configure Fastest-lap                                                                                                                                
            =====================                                                                                                                                
                                                                                                                                                                 
    CMake Error at CMakeLists.txt:75 (if):                                                                                                                       
      if given arguments:                                                                                                                                        
                                                                                                                                                                 
        "MSYS" "AND" "STREQUAL" "Debug"                                                                                                                          
                                                                                                                                                                 
      Unknown arguments specified      
    

    With changes prevents this error.

    Checklist

    Before submitting a pull request, make sure you satisfy all of the following points:

    • [x] Give as much detail as possible on what is included within the pull request
    • [x] Make sure that new additions are not already present in the project
    • [ ] ~~If it contains source code, comply with the coding guidelines~~
    • [ ] ~~Add new tests for new features~~
    • [ ] Run and pass the tests using GitHub's workflows
    opened by kktse 3
  • Energy limits

    Energy limits

    Allowing the user to set a maximum energy limit for a lap (i.e. fuel limit per lap) could make this simulation tool very useful for racing series such as Indycar and Formula E.

    Setting energy limits and power limits to each individual tire could also produce lap simulations that could tell us more about how drivers change their driving style in order to make the tires last.

    Thank you for building this simulation tool!

    enhancement 
    opened by dfamonteiro 3
  • Compiling and executing problem

    Compiling and executing problem

    -Hello! I have compiled with cmake the project, but at the time I try to run it, I get this message:

    make[2]: *** No hay ninguna regla para construir el objetivo 'thirdparty/lib/liblapack.so', necesario para 'lib/libfastestlapc.so/. Alto. make[1]: *** [CMakeFiles/Makefile2:273: src/main/c/CMakeFiles/fastestlapc.dir/all] Error 2 make: *** [Makefile:141: all] Error 2

    Any idea how to solve it?

    opened by JaimeAlvarez18 3
  • Can't loop simulations

    Can't loop simulations

    Hi,

    I'm trying to run the simulation multiple times and changing the vehicle model parameters between each iteration.

    • I run the simulation on the car model.
    • I modify the car model xml file with code
    • I re-run the simulation...

    The first iteration works but stops after with an generic Windows Error. Could it be that it doesn't like that I am loading a vehicle that is already loaded? Is there a way to unload_vehicle before load_vehicle again on the same xml? If not, do I have to rename the car model xml to something different every iteration.

    Thanks

    opened by pierre-trott 2
  • Unused Attribute

    Unused Attribute

    Before submitting a pull request, make sure you satisfy all of the following points:

    • [x] Give as much detail as possible on what is included within the pull request As discussed in the issue: https://github.com/juanmanzanero/fastest-lap/issues/21

    Extra changes added in engine.hpp to check the __unused__ attribute on certain parameters, to ensure optional parameters don't trigger the exception.

    • [x] Make sure that new additions are not already present in the project
    • [x] If it contains source code, comply with the coding guidelines
    • [x] Add new tests for new features
    • [x] Run and pass the tests using GitHub's workflows
    opened by kvkpraneeth 1
  • Python bindings for vehicle_get_property

    Python bindings for vehicle_get_property

    The C version of vehicle_get_property is

    double vehicle_get_property(const char* vehicle_name, const double* q, const double* qa, const double* u, const double s, const char* property_name);
    

    Provide a binding in python, with the form:

    def vehicle_get_property(vehicle_name, inputs, property_name)
    

    where inputs is a dictionary with all the required inputs (q, qa, u and s), which are written into their C version (const double*) inside the function. To do so, the program shall first inquire C++ the key_name, q_names, qa_names, and u_names (this needs to be implemented first)

    The program should stop if a required variable is not present and if there's an unused variable inside the map.

    enhancement 
    opened by juanmanzanero 0
Releases(v0.2)
  • v0.2(Jul 7, 2022)

    Heavy changes to the Fastest-lap API!

    • The name of the functions and the arguments have heavily changed, so please take a fresh look at the examples
    • In the XML options, a variable that has systematically changed is <save_variables> by <output_variables>
    • delete_vehicle() and delete_track() have been merged to a single delete_variable() function
    • New functions such as copy_variable(), move_variable(), print_variable() are available
    • Track data can be downloaded using track_download_data()
    • Circuit length can be downloaded using track_download_length()
    • Error messages can now be read from Windows
    • Accelerations can be outputted from optimal laptime simulations using <ax/> and <ay/> (units: m/s2)

    These libraries were compiled in Windows 10, with microsoft visual studio 2022, and intel compilers 2022.1.0

    Usage:

    Download and unzip. The contents of the zip folder are:

    • 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
    Source code(tar.gz)
    Source code(zip)
    fastest-lap-w10-x64-msvc2022-v0.2.zip(50.69 MB)
  • v0.1(Jun 23, 2022)

    First release of Fastest-lap. Version will be increased to v1.0 once proper documentation is provided.

    This release is the first one that includes pre-compiled windows libraries.

    These libraries were compiled in Windows 10, with microsoft visual studio 2022, and intel compilers 2022.1.0

    Usage:

    Download and unzip. The contents of the zip folder are:

    • 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
    Source code(tar.gz)
    Source code(zip)
    fastest-lap-w10-x64-msvc2022-v0.1.zip(50.74 MB)
Owner
Juan Manzanero
Doctor in Aerospace Engineering. Flight dynamics engineer at European Space Agency
Juan Manzanero
Einsums in C++ Provides compile-time contraction pattern analysis to determine optimal operation to perform

Einsums in C++ Provides compile-time contraction pattern analysis to determine optimal operation to perform. Examples This will optimize at compile-ti

Justin Turney 8 Jul 26, 2022
A Motorola 68K simulator based on Musashi-master 68K simulator.

cpmsim Originally referenced as http://home.earthlink.net/~schultdw/cpm68/simulator.html (now 404) This simple CP/M-68K simulator, is built around the

Neil Cherry 8 Oct 26, 2021
A tiny evolution simulator, which uses SDL2 and is written in C

evosim Evosim is a small evolution simulator. Evosim uses the SDL2 library for graphics. The program can be compiled by simply running make in the evo

Victor Ocampo 2 Nov 20, 2021
Elofetch - The fastest neofetch ever made

Elofetch Elofetch - The fastest neofetch ever made Elofetch is a fast program written in C. Like neofetch, this program will show you software and har

ProX 5 May 30, 2022
FastFormat - The fastest, most robust C++ formatting library

FastFormat The fastest, most robust C++ formatting library Git access to the FastFormat formatting library (C++) FastFormat is an extremely fast, 100%

null 51 Jul 12, 2022
Fastest tiktok share botter. Over 100k shares a second.

TikTok Share Botter ⚠️ CURRENTLY PATCHED WAITING FOR WORK AROUND ⚠️ Fastest multi-threaded and proxyless TikTok Share Botter written in C++. Click her

HNT8 Organization 5 Jul 26, 2022
HiFi error modeler and simulator with ploidy

A HiFi Shotgun Simulator Author: Gene Myers First: Aug 1, 2021 Current: Aug 1, 2021 Commands Himodel HIsim The Error Model Commands This module contai

Eugene W Myers Jr 8 Jul 15, 2022
Stock exchange simulator made in Swing using Java with logic backend in C++ giving it faster load time and better data control

StockSimulator Stock exchange simulator made in Swing using Java with logic backend in C++ giving it faster load time and better data control Features

Dušan Todorović 0 Mar 1, 2022
Simple evolution simulator with generations mechanic and customizable settings.

SimpleEvolution Simple evolution simulator with generations mechanic and customizable settings. Field is divided in three sections: safe zone, medium

Oleg 3 Dec 18, 2021
Mobile robot simulator

The Stage Simulator This is the Stage README file, containing an introduction, license and citation information. Stage is a 2(.5)D robotics standalone

Richard Vaughan 350 Jul 29, 2022
Real-time 2D fluid simulator with lots of visualization options.

Fluid Simulator Building Start by cloning the program and all submodules using the following command: git clone --recursive https://github.com/linusmo

Linus Mossberg 26 Jun 20, 2022
Restoration of The Linux Scheduler Simulator (LinSched)

Restoration of The Linux Scheduler Simulator (LinSched)

Jim Huang 13 Sep 3, 2021
GrandOrgue is a sample based pipe organ simulator.

GrandOrgue is a sample based pipe organ simulator. It currently supports Linux, Windows and OS X. Porting to other OS supported by RtMidi,

GrandOrgue 62 Jul 26, 2022
Biological evolution simulator

biosim4 What is this? This pile of code was used to simulate biological creatures that evolve through natural selection. The results of the experiment

David R. Miller 2.2k Jul 31, 2022
JaBS - Jaakko's Backscattering Simulator

JaBS - Jaakko's Backscattering Simulator

null 3 Mar 31, 2022
a Little Computer 3 simulator

smol3 ??️ a Little Computer 3 simulator smol3 is a tiny LC3 simulator written in C. It aims to be fast and correct. TODO read input binary files write

pry 1 Oct 22, 2021
Using Pi Pico to provide trimwheel for Flightgear Flight Simulator

Trimwheel for FGFS This uses a Rotary Encoder (RE) and a Raspberry Pi Pico (Pico) to connect the RE to FlightGear Flight Simulator as a Pitch Trimwhee

Dave Attwood 1 Dec 14, 2021
An Electronic voting machine simulator using C

EVM-using-C An Electronic voting machine simulator using C The project is divided into few parts 1.The program first asks to enter the information of

BABA SHANKAR S N 1 Oct 24, 2021
Adaptive Runtime AUTOSAR Linux Simulator

Adaptive-AUTOSAR Adaptive AUTOSAR is a simulated Adaptive Platform enviroment over Linux defined by AUTOSAR. The goal of this project is to implement

Armin Kassemi Langroodi 91 Aug 5, 2022