From 1b35278d95e9b8baea54cefe53eeeed1c5c1d9f7 Mon Sep 17 00:00:00 2001 From: Justin Newberry Date: Thu, 7 Sep 2023 15:28:46 -0700 Subject: [PATCH] Subaru: remove 2020+ temporary steering faults (#29116) * subaru steer faults * it takes a bool now * Update selfdrive/car/subaru/carcontroller.py Co-authored-by: Shane Smiskol * that was removed * should be abs * bump panda * bump panda * subaru faults * add fixme Co-authored-by: Shane Smiskol * review suggestions * still want zero steer when lat not active * bump submodules * move it under the non-preglobal section * better comment for steer limited Co-authored-by: Shane Smiskol --------- Co-authored-by: Shane Smiskol old-commit-hash: fb06b98667483bbf9d62b16d7f5aa5e50721f597 --- selfdrive/car/subaru/carcontroller.py | 20 +++++++++++++++++--- selfdrive/car/subaru/values.py | 4 ++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/selfdrive/car/subaru/carcontroller.py b/selfdrive/car/subaru/carcontroller.py index 5553fda0d8..19304efdb1 100644 --- a/selfdrive/car/subaru/carcontroller.py +++ b/selfdrive/car/subaru/carcontroller.py @@ -1,8 +1,13 @@ from openpilot.common.numpy_fast import clip, interp from opendbc.can.packer import CANPacker -from openpilot.selfdrive.car import apply_driver_steer_torque_limits +from openpilot.selfdrive.car import apply_driver_steer_torque_limits, common_fault_avoidance from openpilot.selfdrive.car.subaru import subarucan -from openpilot.selfdrive.car.subaru.values import DBC, GLOBAL_GEN2, PREGLOBAL_CARS, HYBRID_CARS, CanBus, CarControllerParams, SubaruFlags +from openpilot.selfdrive.car.subaru.values import DBC, GLOBAL_GEN2, PREGLOBAL_CARS, HYBRID_CARS, STEER_RATE_LIMITED, CanBus, CarControllerParams, SubaruFlags + +# FIXME: These limits aren't exact. The real limit is more than likely over a larger time period and +# involves the total steering angle change rather than rate, but these limits work well for now +MAX_STEER_RATE = 25 # deg/s +MAX_STEER_RATE_FRAMES = 7 # tx control frames needed before torque can be cut class CarController: @@ -12,6 +17,7 @@ class CarController: self.frame = 0 self.cruise_button_prev = 0 + self.steer_rate_counter = 0 self.p = CarControllerParams(CP) self.packer = CANPacker(DBC[CP.carFingerprint]['pt']) @@ -38,7 +44,15 @@ class CarController: if self.CP.carFingerprint in PREGLOBAL_CARS: can_sends.append(subarucan.create_preglobal_steering_control(self.packer, self.frame // self.p.STEER_STEP, apply_steer, CC.latActive)) else: - can_sends.append(subarucan.create_steering_control(self.packer, apply_steer, CC.latActive)) + apply_steer_req = CC.latActive + + if self.CP.carFingerprint in STEER_RATE_LIMITED: + # Steering rate fault prevention + self.steer_rate_counter, apply_steer_req = \ + common_fault_avoidance(abs(CS.out.steeringRateDeg) > MAX_STEER_RATE, apply_steer_req, + self.steer_rate_counter, MAX_STEER_RATE_FRAMES) + + can_sends.append(subarucan.create_steering_control(self.packer, apply_steer, apply_steer_req)) self.apply_steer_last = apply_steer diff --git a/selfdrive/car/subaru/values.py b/selfdrive/car/subaru/values.py index 2037b24a8d..7f66069514 100644 --- a/selfdrive/car/subaru/values.py +++ b/selfdrive/car/subaru/values.py @@ -707,3 +707,7 @@ LKAS_ANGLE = {CAR.FORESTER_2022, CAR.OUTBACK_2023, CAR.ASCENT_2023} GLOBAL_GEN2 = {CAR.OUTBACK, CAR.LEGACY, CAR.OUTBACK_2023, CAR.ASCENT_2023} PREGLOBAL_CARS = {CAR.FORESTER_PREGLOBAL, CAR.LEGACY_PREGLOBAL, CAR.OUTBACK_PREGLOBAL, CAR.OUTBACK_PREGLOBAL_2018} HYBRID_CARS = {CAR.CROSSTREK_HYBRID, CAR.FORESTER_HYBRID} + +# Cars that temporarily fault when steering angle rate is greater than some threshold. +# Appears to be all cars that started production after 2020 +STEER_RATE_LIMITED = GLOBAL_GEN2 | {CAR.IMPREZA_2020}