From 4ee0b8196f85b29b735c3319924f3c40cebc86e5 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Wed, 12 Oct 2022 21:54:53 -0700 Subject: [PATCH] Hyundai: fix alt CAN-FD cancel (#26057) --- selfdrive/car/hyundai/carcontroller.py | 1 + selfdrive/car/hyundai/carstate.py | 4 +++- selfdrive/car/hyundai/hyundaicanfd.py | 11 ++++++----- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/selfdrive/car/hyundai/carcontroller.py b/selfdrive/car/hyundai/carcontroller.py index bcbab2ab94..a5d995df25 100644 --- a/selfdrive/car/hyundai/carcontroller.py +++ b/selfdrive/car/hyundai/carcontroller.py @@ -117,6 +117,7 @@ class CarController: # cruise cancel if CC.cruiseControl.cancel: if self.CP.flags & HyundaiFlags.CANFD_ALT_BUTTONS: + can_sends.append(hyundaicanfd.create_acc_cancel(self.packer, self.CP, CS.cruise_info)) self.last_button_frame = self.frame else: for _ in range(20): diff --git a/selfdrive/car/hyundai/carstate.py b/selfdrive/car/hyundai/carstate.py index 4c2650c19f..3752fdebef 100644 --- a/selfdrive/car/hyundai/carstate.py +++ b/selfdrive/car/hyundai/carstate.py @@ -34,6 +34,8 @@ class CarState(CarStateBase): self.brake_error = False self.buttons_counter = 0 + self.cruise_info = {} + # On some cars, CLU15->CF_Clu_VehicleSpeed can oscillate faster than the dash updates. Sample at 5 Hz self.cluster_speed = 0 self.cluster_speed_counter = CLUSTER_SAMPLE_RATE @@ -194,13 +196,13 @@ class CarState(CarStateBase): cp_cruise_info = cp if self.CP.flags & HyundaiFlags.CANFD_HDA2 else cp_cam ret.cruiseState.speed = cp_cruise_info.vl["CRUISE_INFO"]["SET_SPEED"] * speed_factor ret.cruiseState.standstill = cp_cruise_info.vl["CRUISE_INFO"]["CRUISE_STANDSTILL"] == 1 + self.cruise_info = copy.copy(cp_cruise_info.vl["CRUISE_INFO"]) cruise_btn_msg = "CRUISE_BUTTONS_ALT" if self.CP.flags & HyundaiFlags.CANFD_ALT_BUTTONS else "CRUISE_BUTTONS" self.prev_cruise_buttons = self.cruise_buttons[-1] self.cruise_buttons.extend(cp.vl_all[cruise_btn_msg]["CRUISE_BUTTONS"]) self.main_buttons.extend(cp.vl_all[cruise_btn_msg]["ADAPTIVE_CRUISE_MAIN_BTN"]) self.buttons_counter = cp.vl[cruise_btn_msg]["COUNTER"] - self.cruise_info_copy = {} if self.CP.flags & HyundaiFlags.CANFD_HDA2: self.cam_0x2a4 = copy.copy(cp_cam.vl["CAM_0x2a4"]) diff --git a/selfdrive/car/hyundai/hyundaicanfd.py b/selfdrive/car/hyundai/hyundaicanfd.py index 9d4e4d4e0d..f2cbafdcf0 100644 --- a/selfdrive/car/hyundai/hyundaicanfd.py +++ b/selfdrive/car/hyundai/hyundaicanfd.py @@ -47,12 +47,13 @@ def create_buttons(packer, cnt, btn): } return packer.make_can_msg("CRUISE_BUTTONS", 5, values) -def create_cruise_info(packer, cruise_info_copy, cancel): +def create_acc_cancel(packer, CP, cruise_info_copy): values = cruise_info_copy - if cancel: - values["CRUISE_STATUS"] = 0 - values["CRUISE_INACTIVE"] = 1 - return packer.make_can_msg("CRUISE_INFO", 5, values) + values.update({ + "CRUISE_STATUS": 0, + "CRUISE_INACTIVE": 1, + }) + return packer.make_can_msg("CRUISE_INFO", get_e_can_bus(CP), values) def create_lfahda_cluster(packer, CP, enabled): values = {