From 75a0e40b20f32d84198be20be56869d7f489710c Mon Sep 17 00:00:00 2001 From: FrogAi <91348155+FrogAi@users.noreply.github.com> Date: Sun, 28 Jan 2024 22:05:39 -0700 Subject: [PATCH] ZSS support Add ZSS support for Toyota Priuses with a Zorro Steering Sensor. Credit goes to DragonPilot! https: //github.com/dragonpilot-community/dragonpilot Co-Authored-By: eFini <16603033+efinilan@users.noreply.github.com> Co-Authored-By: Kumar <36933347+rav4kumar@users.noreply.github.com> --- selfdrive/car/toyota/carstate.py | 33 +++++++++++++++++++++++++++++++ selfdrive/car/toyota/interface.py | 3 +++ selfdrive/car/toyota/values.py | 1 + 3 files changed, 37 insertions(+) diff --git a/selfdrive/car/toyota/carstate.py b/selfdrive/car/toyota/carstate.py index bd3774a08dc1ae..814442d9ddbca3 100644 --- a/selfdrive/car/toyota/carstate.py +++ b/selfdrive/car/toyota/carstate.py @@ -27,6 +27,8 @@ # - prolonged high driver torque: 17 (permanent) PERM_STEER_FAULTS = (3, 17) +ZSS_THRESHOLD = 4.0 +ZSS_THRESHOLD_COUNT = 10 class CarState(CarStateBase): def __init__(self, CP): @@ -48,6 +50,11 @@ def __init__(self, CP): self.lkas_hud = {} # FrogPilot variables + self.zss_compute = False + self.zss_cruise_active_last = False + + self.zss_angle_offset = 0 + self.zss_threshold_count = 0 self.traffic_signals = {} @@ -212,6 +219,30 @@ def update(self, cp, cp_cam, conditional_experimental_mode, frogpilot_variables) SpeedLimitController.car_speed_limit = self.calculate_speed_limit() SpeedLimitController.write_car_state() + # ZSS Support - Credit goes to the DragonPilot team! + if self.CP.flags & ToyotaFlags.ZSS and self.zss_threshold_count < ZSS_THRESHOLD_COUNT: + zorro_steer = cp.vl["SECONDARY_STEER_ANGLE"]["ZORRO_STEER"] + # Only compute ZSS offset when acc is active + zss_cruise_active = ret.cruiseState.available + if zss_cruise_active and not self.zss_cruise_active_last: + self.zss_compute = True # Cruise was just activated, so allow offset to be recomputed + self.zss_threshold_count = 0 + self.zss_cruise_active_last = zss_cruise_active + + # Compute ZSS offset + if self.zss_compute: + if abs(ret.steeringAngleDeg) > 1e-3 and abs(zorro_steer) > 1e-3: + self.zss_compute = False + self.zss_angle_offset = zorro_steer - ret.steeringAngleDeg + + # Error check + new_steering_angle_deg = zorro_steer - self.zss_angle_offset + if abs(ret.steeringAngleDeg - new_steering_angle_deg) > ZSS_THRESHOLD: + self.zss_threshold_count += 1 + else: + # Apply offset + ret.steeringAngleDeg = new_steering_angle_deg + return ret def update_traffic_signals(self, cp_cam): @@ -280,6 +311,8 @@ def get_can_parser(CP): if CP.flags & ToyotaFlags.SMART_DSU: messages.append(("SDSU", 33)) + messages += [("SECONDARY_STEER_ANGLE", 0)] + return CANParser(DBC[CP.carFingerprint]["pt"], messages, 0) @staticmethod diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index 13b8fe0cdb00e8..26e4a3d0ac08c9 100644 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -44,6 +44,9 @@ def _get_params(ret, candidate, fingerprint, car_fw, experimental_long, docs): ret.steerActuatorDelay = 0.12 # Default delay, Prius has larger delay ret.steerLimitTimer = 0.4 + if 0x23 in fingerprint[0]: # Detect if ZSS is present + ret.flags |= ToyotaFlags.ZSS.value + ret.stoppingControl = False # Toyota starts braking more when it thinks you want to stop stop_and_go = candidate in TSS2_CAR diff --git a/selfdrive/car/toyota/values.py b/selfdrive/car/toyota/values.py index cff5a865605859..331cafcd6304a8 100644 --- a/selfdrive/car/toyota/values.py +++ b/selfdrive/car/toyota/values.py @@ -46,6 +46,7 @@ class ToyotaFlags(IntFlag): HYBRID = 1 SMART_DSU = 2 DISABLE_RADAR = 4 + ZSS = 8 class CAR(StrEnum):