Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 72 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,74 @@
# Python
__pycache__/
data/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Virtual Environment
venv/
env/
ENV/

# Project specific
report.html
models/tinyphysics_*.onnx
*.swp
best_pid_params.txt
visualizations/
*.onnx

# Jupyter Notebooks
.ipynb_checkpoints
*.ipynb_checkpoints/
*.ipynb

# Visual Studio Code
.vscode/
*.code-workspace
.history/

# PyCharm
.idea/
*.iml
*.iws
*.ipr

# Logs
logs/
*.log

# Data (optional - uncomment if you don't want to track data files)
data/
*.csv

# Outputs
*.png
*.jpg
*.jpeg
*.gif
*.svg
*.pkl
*.joblib

# OS specific
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
40 changes: 40 additions & 0 deletions controllers/tuned_pid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from . import BaseController
import numpy as np

class Controller(BaseController):
"""
A simplified tuned PID controller with feed-forward term

Based on the baseline PID controller but adds a feed-forward term
Feed-forward term: k_ff * target_lataccel / v_ego**2
"""
def __init__(self):
# Optimized PID gains from Optuna (trial 25)
self.p = 0.21942091482230813 # Proportional gain
self.i = 0.09438349898803905 # Integral gain
self.d = -0.06219594603865014 # Derivative gain

# Add feed-forward gain
self.k_ff = 0.02737288447587737

# State variables
self.error_integral = 0
self.prev_error = 0

def update(self, target_lataccel, current_lataccel, state, future_plan):
# Extract vehicle velocity for feed-forward term
v_ego = state.v_ego

# Calculate PID terms (same as baseline)
error = (target_lataccel - current_lataccel)
self.error_integral += error
error_diff = error - self.prev_error
self.prev_error = error

# Calculate feed-forward term (avoid division by zero)
feed_forward = 0
if v_ego > 0.1: # Only apply feed-forward when moving
feed_forward = self.k_ff * target_lataccel / (v_ego**2)

# Combine PID and feed-forward
return self.p * error + self.i * self.error_integral + self.d * error_diff + feed_forward
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ pandas==2.1.2
matplotlib==3.8.1
seaborn==0.13.2
tqdm
optuna==3.5.0
plotly==5.26.0
kaleido==0.2.1
34 changes: 34 additions & 0 deletions scripts/run_tuning.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@echo off
echo Starting PID Controller Tuning Process
echo ==================================

REM Install requirements
pip install -r requirements.txt

REM Activate environment if needed
REM call venv\Scripts\activate.bat

REM Run PID tuning with recommended parameters
python scripts/tune_pid.py ^
--model_path ./models/tinyphysics.onnx ^
--data_path ./data ^
--num_segs 200 ^
--n_trials 100 ^
--update_controller

echo.
echo Tuning completed! Updated controller with best parameters.
echo Running final evaluation against baseline PID...
echo.

REM Generate final evaluation report
python eval.py ^
--model_path ./models/tinyphysics.onnx ^
--data_path ./data ^
--num_segs 100 ^
--test_controller tuned_pid ^
--baseline_controller pid

echo.
echo Evaluation complete! See report.html for results.
echo ==================================
34 changes: 34 additions & 0 deletions scripts/run_tuning.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
echo "Starting PID Controller Tuning Process"
echo "=================================="

# Install requirements
pip install -r requirements.txt

# Activate environment if needed
# source venv/bin/activate

# Run PID tuning with recommended parameters
python scripts/tune_pid.py \
--model_path ./models/tinyphysics.onnx \
--data_path ./data \
--num_segs 200 \
--n_trials 100 \
--update_controller

echo
echo "Tuning completed! Updated controller with best parameters."
echo "Running final evaluation against baseline PID..."
echo

# Generate final evaluation report
python eval.py \
--model_path ./models/tinyphysics.onnx \
--data_path ./data \
--num_segs 100 \
--test_controller tuned_pid \
--baseline_controller pid

echo
echo "Evaluation complete! See report.html for results."
echo "=================================="
Loading
Loading