This guide will help you get started with the vehicle simulation repository.
- Python 3.10 or higher
- pip
# Clone or navigate to the repository
cd simulation_repo
# Create venv and install project (dev deps by default)
bash setup.sh
# Runtime-only install (without dev extras)
INSTALL_DEV=0 bash setup.shRun a simple simulation with default vehicle parameters:
from simulation.dynamics import ExtendedPlant, ExtendedPlantParams
# Use default parameters
params = ExtendedPlantParams()
plant = ExtendedPlant(params)
# Initialize and simulate
plant.reset(speed=0.0)
for _ in range(100):
state = plant.step(0.5, dt=0.1) # 50% throttle
print(f"Speed: {state.speed:.2f} m/s")See examples/basic_simulation.py for a complete example.
Fit vehicle parameters from trip data:
python scripts/fit_params.py \
--data data/processed/vehicle/all_trips_data.pt \
--output fitted_params.jsonOr use the GUI:
python examples/gui_usage.pyUse the dedicated fetching GUI to download trips from S3 without CLI flags:
python scripts/fetch_trips_gui.pyEquivalent CLI:
python scripts/fetch_trips.py \
--car NiroEV \
--start 2024-01-01 \
--end 2024-01-07 \
--dest data/raw/tripsUse the dedicated parser GUI to build .pt datasets from raw trip folders:
python scripts/parse_trips_gui.pyEquivalent CLI:
python scripts/parse_trips.py \
--root data/raw/trips \
--car NiroEV \
--out-dir data/processed/NiroEVpython scripts/simulate_trip.py \
--params fitted_params.json \
--trip-data data/processed/vehicle/all_trips_data.pt \
--output simulation_results.npzLaunch the dedicated feedforward comparison GUI:
# Script
python scripts/feedforward_compare_gui.py
# Console entry point (after pip install -e .)
feedforward-compare-guiWhat this GUI provides:
- Open-loop and closed-loop feedforward comparison against trip data
- GT acceleration Butterworth filtering with cutoff control in Hz
- Separate throttle and brake feedforward gain sliders
- Full-state diagnostics in an 8-subplot layout (2 columns)
Parameter loading supports fitted params JSON, fitter config.json, and fitting_checkpoint.json payloads.
Both the simulation script and examples support comprehensive plotting of all simulation states:
Simulation Script (scripts/simulate_trip.py):
# Generate plots with all internal states
python scripts/simulate_trip.py \
--params fitted_params.json \
--trip-data data/processed/vehicle/all_trips_data.pt \
--output simulation_results.npz \
--plot \
--plot-output simulation_plot.png
# For synthetic simulation (without trip data)
python scripts/simulate_trip.py \
--params fitted_params.json \
--output simulation_results.npz \
--plot \
--duration 60.0 \
--dt 0.1Basic Simulation Example (examples/basic_simulation.py):
# Run with plotting enabled
python examples/basic_simulation.py --plot
# Customize duration and output path
python examples/basic_simulation.py \
--plot \
--plot-output my_results.png \
--duration 20.0 \
--dt 0.05Plot Contents:
The plotting functionality generates a comprehensive figure with 14 subplots (all sharing the x-axis for time):
- Actuations - Throttle and brake commands (0-100%)
- Vehicle Speed - Simulated speed (and measured if available)
- Acceleration - Simulated acceleration (and measured if available)
- Road Grade - Road grade in degrees
- Motor Angular Speed - Motor shaft angular speed (rad/s)
- Motor Current - With current limit overlay
- Motor Voltage - Commanded voltage, back-EMF voltage, and V_max limits
- Drive Torque at Wheel - With motor/wheel T_max overlays
- Motor Power - V × I, with P_max limits
- Brake Torque - With brake T_max limit
- Forces - Tire, drag, rolling, grade, and net forces
- Wheel Angular Speed and Slip Ratio - Dual y-axis plot
- Vehicle Position - Position over time
- Status Flags - Held by brakes and coupling enabled (0/1)
All plots are saved as PNG files with 150 DPI resolution and can be used for detailed analysis of vehicle dynamics behavior.
- Read the Dynamics Model Documentation to understand the physics
- Check the Fitting Guide for parameter fitting workflows
- Explore the API Reference for detailed API documentation
- Try the examples in the
examples/directory