Skip to content

tsg1306/LapTimeSim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏎️ LapTimeSim - Quasi-Static Lap Time Simulator

Python 3.7+ License: MIT

A physics-based lap time simulation tool that models vehicle dynamics to predict optimal lap times on racing circuits. Originally developed as part of a TIPE (Travaux d'Initiative Personnelle EncadrΓ©s) project.

Circuit Speed Map Circuit Speed Map

πŸ“‹ Table of Contents

🎯 Overview

LapTimeSim is a quasi-static lap time simulator that calculates the theoretical optimal lap time for a given car-track combination. The simulation uses fundamental physics principles including:

  • Tire friction modeling with load sensitivity
  • Aerodynamic forces (downforce and drag)
  • Powertrain modeling with gear ratios and efficiency
  • Combined grip using the friction ellipse (traction circle) concept
  • Optimal velocity profiling through corners and straights

What is a Quasi-Static Simulation?

Unlike dynamic simulations that solve differential equations in real-time, a quasi-static approach assumes the vehicle is always in equilibrium at each point. This simplification allows for faster computation while still capturing the essential physics of vehicle performance.

✨ Features

  • πŸš— Comprehensive Vehicle Model: Mass distribution, aerodynamics, tires, powertrain
  • πŸ›€οΈ Track Discretization: Converts track centerline data into simulation-ready mesh
  • πŸ“Š GGV Diagram Generation: 3D traction envelope visualization
  • πŸ”„ Optimal Gear Selection: Automatic gear optimization based on engine curves
  • πŸ“ˆ Rich Visualization: Speed traces, circuit maps with velocity coloring, gear/RPM plots
  • πŸ’Ύ Modular Data Format: Separate car and track model files for easy mixing and matching

πŸ”¬ Physics Model

Vehicle Dynamics

The simulator models the following forces:

Longitudinal Forces (X-axis)

F_x = F_engine - F_aero_drag - F_rolling - F_braking
  • Engine Force: Interpolated from torque curve Γ— gear ratio Γ— efficiency
  • Aerodynamic Drag: F_drag = 0.5 Γ— ρ Γ— Cd Γ— A Γ— vΒ²
  • Rolling Resistance: F_roll = Cr Γ— |F_z|

Vertical Forces (Z-axis)

F_z = -M Γ— g + F_downforce
  • Weight: F_weight = M Γ— g
  • Downforce: F_down = 0.5 Γ— ρ Γ— Cl Γ— A Γ— vΒ²

Lateral Forces (Y-axis)

F_y = M Γ— vΒ² / R  (centripetal force required for cornering)

Tire Model

The tire friction model includes load sensitivity:

ΞΌ = ΞΌ_0 + sensitivity Γ— (N_rated - N_actual)

Where:

  • ΞΌ_0 is the base friction coefficient
  • sensitivity is the load sensitivity factor
  • N_rated is the rated load for the tire
  • N_actual is the actual normal load on the tire

Friction Ellipse (Combined Grip)

The combined longitudinal and lateral grip is modeled using the friction ellipse:

(a_x / a_x_max)Β² + (a_y / a_y_max)Β² ≀ 1

This ensures that when the car is cornering at maximum lateral grip, longitudinal acceleration capacity is reduced accordingly.

Simulation Algorithm

  1. Calculate Maximum Cornering Speeds: For each point, compute the maximum velocity limited by lateral grip
  2. Find Apex Points: Identify local minima in the velocity profile (braking zones)
  3. Forward Integration: From each apex, simulate acceleration forward
  4. Backward Integration: From each apex, simulate braking backward
  5. Merge Profiles: Take the minimum velocity at each point from all integration passes

πŸ› οΈ Installation

Prerequisites

  • Python 3.7 or higher
  • pip package manager

Dependencies

pip install numpy matplotlib scipy

Clone the Repository

git clone https://github.com/yourusername/LapTimeSim.git
cd LapTimeSim

πŸš€ Usage

Quick Start

  1. Model your car (or use an existing model):
python src/CarModelSimV2.py
  1. Model your track (or use an existing model):
python src/CircuitModelingSimV2.py
  1. Run the lap simulation:
python src/LapSimV2.py

Configuration

Edit the file paths in each script to point to your data files:

# In LapSimV2.py
nom_circuit, pays, tr = ouvertureFileTrack("data/tracks/Model_Monza_TrackSimV2.txt")
nom_voiture, veh = ouvertureFileCar("data/cars/Model_Alpine_A110_CarSimV2.txt")

πŸ“ File Formats

Car Input File (.txt)

Tab-separated values with parameter names and values:

Alpine A110 (cup)
Total Mass	1100	kg
Front Mass Distribution	42	%
Wheelbase	2420	mm
Lift Coefficient CL	-2.8	-
Drag Coefficient CD	-0.8	-
...
MARKER_info/data
1000	150
2000	200
...

The section after MARKER_info/data contains the engine torque curve (RPM vs Torque in NΒ·m).

Track Input File (.txt)

Tab-separated with corner type, length, and radius:

Country	TrackName
Straight	465.949	0.000
Left	5.364	1856.545
Right	4.046	787.304
...
  • Straight: Length in meters, radius = 0
  • Left/Right: Arc length in meters, radius in meters

Model Output Files

Both car and track models are exported as Python dictionaries serialized to text files, containing all computed parameters needed for simulation.

πŸ“‚ Project Structure

LapTimeSim/
β”œβ”€β”€ README.md
β”œβ”€β”€ LICENSE
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ CarModelSimV2.py      # Vehicle parameter processing
β”‚   β”œβ”€β”€ CircuitModelingSimV2.py   # Track geometry processing
β”‚   └── LapSimV2.py           # Main lap time simulation
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ cars/                 # Car definition files
β”‚   β”‚   β”œβ”€β”€ AlpineA110V2.txt
β”‚   β”‚   └── essaieCARV2.txt
β”‚   └── tracks/               # Track definition files
β”‚       β”œβ”€β”€ castelletV2.txt
β”‚       └── monza.txt
β”œβ”€β”€ docs/
β”‚   └── physics_model.md      # Detailed physics documentation
β”œβ”€β”€ examples/
β”‚   └── example_usage.py      # Example usage scripts
└── output/
    └── Model_*_SimV2.txt     # Generated model files

πŸ“Š Examples

Sample Output

Running the simulation on Paul Ricard (Le Castellet) with an Alpine A110 Cup:

DΓ©coupage du circuit : OK
Simulation terminΓ©
Temps au tour: 1:52.340

Visualization

The simulator generates several plots:

  1. Speed vs Time: Vehicle speed throughout the lap
  2. Circuit Map: Track layout colored by velocity
  3. Engine RPM & Gear: Gear selection and engine speed
  4. Yaw Rate: Vehicle rotation rate through corners
  5. GGV Diagram: 3D traction envelope (Car Model only)

πŸ”§ Customization

Adding a New Car

  1. Create a new car definition file following the format in data/cars/
  2. Run CarModelSimV2.py with the new file path
  3. Use the generated model file in LapSimV2.py

Adding a New Track

  1. Create track data with corner-by-corner radius and length
  2. Format as per data/tracks/ examples
  3. Run CircuitModelingSimV2.py to generate the model

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Development Ideas

  • Add elevation changes (3D track model)
  • Implement thermal tire model
  • Add fuel consumption modeling
  • Create GUI interface
  • Support for telemetry data import
  • Validate against real lap times

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Developed as part of a TIPE project on racing simulation
  • Inspired by professional lap time simulation tools
  • Physics model based on vehicle dynamics literature

πŸ“§ Contact

For questions or feedback, please open an issue on GitHub.


Made with ❀️ for motorsport enthusiasts and engineering students

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages