From 4ae473d1b65f53a056db59803c0942d2a8fa8db1 Mon Sep 17 00:00:00 2001 From: Yassine Yousfi Date: Wed, 23 Jul 2025 11:32:52 -0700 Subject: [PATCH] new pid tune + readme fixes --- README.md | 15 +++++++-------- controllers/pid.py | 16 ++++++++-------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 4b71eb38..31ba9757 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,6 @@ Machine learning models can drive cars, paint beautiful pictures and write passable rap. But they famously suck at doing low level controls. Your goal is to write a good controller. This repo contains a model that simulates the lateral movement of a car, given steering commands. The goal is to drive this "car" well for a given desired trajectory. - ## Getting Started We'll be using a synthetic dataset based on the [comma-steering-control](https://github.com/commaai/comma-steering-control) dataset for this challenge. These are actual car and road states from [openpilot](https://github.com/commaai/openpilot) users. @@ -26,10 +25,10 @@ We'll be using a synthetic dataset based on the [comma-steering-control](https:/ pip install -r requirements.txt # test this works -python tinyphysics.py --model_path ./models/tinyphysics.onnx --data_path ./data/00000.csv --debug --controller pid +python tinyphysics.py --model_path ./models/tinyphysics.onnx --data_path ./data/00000.csv --debug --controller pid ``` -There are some other scripts to help you get aggregate metrics: +There are some other scripts to help you get aggregate metrics: ``` # batch Metrics of a controller on lots of routes python tinyphysics.py --model_path ./models/tinyphysics.onnx --data_path ./data --num_segs 100 --controller pid @@ -43,22 +42,22 @@ You can also use the notebook at [`experiment.ipynb`](https://github.com/commaai ## TinyPhysics This is a "simulated car" that has been trained to mimic a very simple physics model (bicycle model) based simulator, given realistic driving noise. It is an autoregressive model similar to [ML Controls Sim](https://blog.comma.ai/096release/#ml-controls-sim) in architecture. Its inputs are the car velocity (`v_ego`), forward acceleration (`a_ego`), lateral acceleration due to road roll (`road_lataccel`), current car lateral acceleration (`current_lataccel`), and a steer input (`steer_action`), then it predicts the resultant lateral acceleration of the car. - ## Controllers Your controller should implement a new [controller](https://github.com/commaai/controls_challenge/tree/master/controllers). This controller can be passed as an arg to run in-loop in the simulator to autoregressively predict the car's response. - ## Evaluation Each rollout will result in 2 costs: -- `lataccel_cost`: $\dfrac{\Sigma(actual\\_lat\\_accel - target\\_lat\\_accel)^2}{steps} * 100$ +- `lataccel_cost`: $\dfrac{\Sigma(\mathrm{actual\_lat\_accel} - \mathrm{target\_lat\_accel})^2}{steps} * 100$ -- `jerk_cost`: $\dfrac{\Sigma((actual\\_lat\\_accel\_t - actual\\_lat\\_accel\_{t-1}) / \Delta t)^2}{steps - 1} * 100$ +- `jerk_cost`: $\dfrac{\Sigma((\mathrm{actual\_lat\_accel}_t - \mathrm{actual\_lat\_accel}_{t-1}) / \Delta t)^2}{steps - 1} * 100$ -It is important to minimize both costs. `total_cost`: $(lataccel\\_cost * 50) + jerk\\_cost$ +It is important to minimize both costs. `total_cost`: $(\mathrm{lat\_accel\_cost} * 50) + \mathrm{jerk\_cost}$ ## Submission Run the following command, then submit `report.html` and your code to [this form](https://forms.gle/US88Hg7UR6bBuW3BA). +Competitive scores (`total_cost<100`) will be added to the leaderboard + ``` python eval.py --model_path ./models/tinyphysics.onnx --data_path ./data --num_segs 5000 --test_controller --baseline_controller pid ``` diff --git a/controllers/pid.py b/controllers/pid.py index 6da40a46..ebbb6aab 100644 --- a/controllers/pid.py +++ b/controllers/pid.py @@ -6,15 +6,15 @@ class Controller(BaseController): A simple PID controller """ def __init__(self,): - self.p = 0.3 - self.i = 0.05 - self.d = -0.1 + self.p = 0.195 + self.i = 0.100 + self.d = -0.053 self.error_integral = 0 self.prev_error = 0 def update(self, target_lataccel, current_lataccel, state, future_plan): - error = (target_lataccel - current_lataccel) - self.error_integral += error - error_diff = error - self.prev_error - self.prev_error = error - return self.p * error + self.i * self.error_integral + self.d * error_diff + error = (target_lataccel - current_lataccel) + self.error_integral += error + error_diff = error - self.prev_error + self.prev_error = error + return self.p * error + self.i * self.error_integral + self.d * error_diff