From 6b7b6034b7216fda588d161aa28cdafd7c428cec Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 11 Aug 2023 00:27:53 -0700 Subject: [PATCH] common_fault_avoidance: take a bool (#29328) old-commit-hash: 2a38f38be12052790804851a179acd159cea7f8b --- selfdrive/car/__init__.py | 4 ++-- selfdrive/car/hyundai/carcontroller.py | 2 +- selfdrive/car/toyota/carcontroller.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/selfdrive/car/__init__.py b/selfdrive/car/__init__.py index 10da0dc56c..fdcbb98197 100644 --- a/selfdrive/car/__init__.py +++ b/selfdrive/car/__init__.py @@ -132,7 +132,7 @@ def apply_std_steer_angle_limits(apply_angle, apply_angle_last, v_ego, LIMITS): return clip(apply_angle, apply_angle_last - angle_rate_lim, apply_angle_last + angle_rate_lim) -def common_fault_avoidance(measured_value: float, max_value: float, request: bool, above_limit_frames: int, +def common_fault_avoidance(fault_condition: bool, request: bool, above_limit_frames: int, max_above_limit_frames: int, max_mismatching_frames: int = 1): """ Several cars have the ability to work around their EPS limits by cutting the @@ -140,7 +140,7 @@ def common_fault_avoidance(measured_value: float, max_value: float, request: boo """ # Count up to max_above_limit_frames, at which point we need to cut the request for above_limit_frames to avoid a fault - if request and abs(measured_value) >= max_value: + if request and fault_condition: above_limit_frames += 1 else: above_limit_frames = 0 diff --git a/selfdrive/car/hyundai/carcontroller.py b/selfdrive/car/hyundai/carcontroller.py index ff23d43f08..8c734583e4 100644 --- a/selfdrive/car/hyundai/carcontroller.py +++ b/selfdrive/car/hyundai/carcontroller.py @@ -65,7 +65,7 @@ class CarController: apply_steer = apply_driver_steer_torque_limits(new_steer, self.apply_steer_last, CS.out.steeringTorque, self.params) # >90 degree steering fault prevention - self.angle_limit_counter, apply_steer_req = common_fault_avoidance(CS.out.steeringAngleDeg, MAX_ANGLE, CC.latActive, + self.angle_limit_counter, apply_steer_req = common_fault_avoidance(abs(CS.out.steeringAngleDeg) >= MAX_ANGLE, CC.latActive, self.angle_limit_counter, MAX_ANGLE_FRAMES, MAX_ANGLE_CONSECUTIVE_FRAMES) diff --git a/selfdrive/car/toyota/carcontroller.py b/selfdrive/car/toyota/carcontroller.py index 0a23094fa3..d2558b5b29 100644 --- a/selfdrive/car/toyota/carcontroller.py +++ b/selfdrive/car/toyota/carcontroller.py @@ -57,7 +57,7 @@ class CarController: apply_steer = apply_meas_steer_torque_limits(new_steer, self.last_steer, CS.out.steeringTorqueEps, self.params) # >100 degree/sec steering fault prevention - self.steer_rate_counter, apply_steer_req = common_fault_avoidance(CS.out.steeringRateDeg, MAX_STEER_RATE, CC.latActive, + self.steer_rate_counter, apply_steer_req = common_fault_avoidance(abs(CS.out.steeringRateDeg) >= MAX_STEER_RATE, CC.latActive, self.steer_rate_counter, MAX_STEER_RATE_FRAMES) if not CC.latActive: