From 3ff90573c786d693a5015675a868c2b638af6b2c Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Tue, 10 Sep 2024 15:20:34 -0700 Subject: [PATCH] Test all torque cars' lateral limits (#1232) * test more models! * Impreza 2020: reach max in ~0.8s instead of ~0.6 * leave todo for gen2, not safety critical since jerk is under threshold (1000/40*2/100=0.5s) * fix honda --- opendbc/car/honda/carcontroller.py | 9 ++------- opendbc/car/honda/values.py | 4 ++++ opendbc/car/subaru/values.py | 2 ++ opendbc/car/tests/test_lateral_limits.py | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/opendbc/car/honda/carcontroller.py b/opendbc/car/honda/carcontroller.py index 20358c67fb..85199a2b91 100644 --- a/opendbc/car/honda/carcontroller.py +++ b/opendbc/car/honda/carcontroller.py @@ -97,12 +97,6 @@ def process_hud_alert(hud_alert): "lanes_visible", "fcw", "acc_alert", "steer_required", "lead_distance_bars"]) -def rate_limit_steer(new_steer, last_steer): - # TODO just hardcoded ramp to min/max in 0.33s for all Honda - MAX_DELTA = 3 * DT_CTRL - return clip(new_steer, last_steer - MAX_DELTA, last_steer + MAX_DELTA) - - class CarController(CarControllerBase): def __init__(self, dbc_name, CP): super().__init__(dbc_name, CP) @@ -138,7 +132,8 @@ def update(self, CC, CS, now_nanos): gas, brake = 0.0, 0.0 # *** rate limit steer *** - limited_steer = rate_limit_steer(actuators.steer, self.last_steer) + limited_steer = rate_limit(actuators.steer, self.last_steer, -self.params.STEER_DELTA_DOWN * DT_CTRL, + self.params.STEER_DELTA_UP * DT_CTRL) self.last_steer = limited_steer # *** apply brake hysteresis *** diff --git a/opendbc/car/honda/values.py b/opendbc/car/honda/values.py index 70ccecb0ed..1200f69cca 100644 --- a/opendbc/car/honda/values.py +++ b/opendbc/car/honda/values.py @@ -35,6 +35,10 @@ class CarControllerParams: BOSCH_GAS_LOOKUP_BP = [-0.2, 2.0] # 2m/s^2 BOSCH_GAS_LOOKUP_V = [0, 1600] + STEER_STEP = 1 # 100 Hz + STEER_DELTA_UP = 3 # min/max in 0.33s for all Honda + STEER_DELTA_DOWN = 3 + def __init__(self, CP): self.STEER_MAX = CP.lateralParams.torqueBP[-1] # mirror of list (assuming first item is zero) for interp of signed request values diff --git a/opendbc/car/subaru/values.py b/opendbc/car/subaru/values.py index 15b8a8b8ec..c7f93f9fae 100644 --- a/opendbc/car/subaru/values.py +++ b/opendbc/car/subaru/values.py @@ -20,10 +20,12 @@ def __init__(self, CP): self.STEER_DRIVER_FACTOR = 1 # from dbc if CP.flags & SubaruFlags.GLOBAL_GEN2: + # TODO: lower rate limits, this reaches min/max in 0.5s which negatively affects tuning self.STEER_MAX = 1000 self.STEER_DELTA_UP = 40 self.STEER_DELTA_DOWN = 40 elif CP.carFingerprint == CAR.SUBARU_IMPREZA_2020: + self.STEER_DELTA_UP = 35 self.STEER_MAX = 1439 else: self.STEER_MAX = 2047 diff --git a/opendbc/car/tests/test_lateral_limits.py b/opendbc/car/tests/test_lateral_limits.py index 585289968d..2a0b7eb90a 100755 --- a/opendbc/car/tests/test_lateral_limits.py +++ b/opendbc/car/tests/test_lateral_limits.py @@ -35,7 +35,7 @@ def setup_class(cls): pytest.skip("Platform is behind dashcamOnly") # TODO: test all platforms - if CP.lateralTuning.which() != 'torque': + if CP.steerControlType != 'torque': pytest.skip() if CP.notCar: