From e32bfa80ad435b1b608d18be2ad76ed41ce537cc Mon Sep 17 00:00:00 2001 From: Chris Souers Date: Fri, 26 Jan 2024 21:46:00 +0000 Subject: [PATCH] Honda Radarless: Send buttons to camera when engaged vs forwarding or spamming. Co-authored-by: Jason Wen <47793918+sunnyhaibin@users.noreply.github.com> --- selfdrive/car/honda/carcontroller.py | 24 +++++++++++++++---- selfdrive/car/honda/carstate.py | 1 + selfdrive/car/honda/hondacan.py | 15 ++++++++---- selfdrive/car/honda/interface.py | 9 +++---- selfdrive/car/honda/values.py | 5 ++++ selfdrive/car/tests/routes.py | 2 +- .../test/process_replay/test_processes.py | 2 ++ 7 files changed, 45 insertions(+), 13 deletions(-) diff --git a/selfdrive/car/honda/carcontroller.py b/selfdrive/car/honda/carcontroller.py index 056b47c4b3ba9a..97edf9151e3792 100644 --- a/selfdrive/car/honda/carcontroller.py +++ b/selfdrive/car/honda/carcontroller.py @@ -202,11 +202,27 @@ def update(self, CC, CS, now_nanos): if not self.CP.openpilotLongitudinalControl: if self.frame % 2 == 0 and self.CP.carFingerprint not in HONDA_BOSCH_RADARLESS: # radarless cars don't have supplemental message can_sends.append(hondacan.create_bosch_supplemental_1(self.packer, self.CP.carFingerprint)) - # If using stock ACC, spam cancel command to kill gas when OP disengages. + # Buttons: spam the cancel or resume buttons + cruise = None + setting = CruiseButtons.NONE if pcm_cancel_cmd: - can_sends.append(hondacan.spam_buttons_command(self.packer, CruiseButtons.CANCEL, self.CP.carFingerprint)) - elif CC.cruiseControl.resume: - can_sends.append(hondacan.spam_buttons_command(self.packer, CruiseButtons.RES_ACCEL, self.CP.carFingerprint)) + cruise = CruiseButtons.CANCEL + elif self.CP.carFingerprint not in HONDA_BOSCH_RADARLESS and CC.cruiseControl.resume: + cruise = CruiseButtons.RES_ACCEL + elif self.CP.carFingerprint in HONDA_BOSCH_RADARLESS and CC.enabled and self.frame % 4 == 0: + # Intercept buttons when engaged. panda will forward when disengaged. Block the LKAS button coming from the car. + # Keep stock LKAS disabled so it can't disengage cruise when the wheel touch timeout expires. + cruise = CruiseButtons.NONE + if CS.cruise_buttons: + cruise = CS.cruise_buttons + elif CS.cruise_setting and CS.cruise_setting is not CruiseButtons.LKAS: + setting = CS.cruise_setting + elif CC.cruiseControl.resume: + cruise = CruiseButtons.RES_ACCEL + elif CS.lkas_hud['ENABLED']: + setting = CruiseButtons.LKAS + if cruise is not None: + can_sends.append(hondacan.create_buttons_command(self.packer, cruise, setting, CS.scm_buttons, self.CP.carFingerprint)) else: # Send gas and brake commands. diff --git a/selfdrive/car/honda/carstate.py b/selfdrive/car/honda/carstate.py index 03aedb31d2afa6..79e5250c4ba077 100644 --- a/selfdrive/car/honda/carstate.py +++ b/selfdrive/car/honda/carstate.py @@ -205,6 +205,7 @@ def update(self, cp, cp_cam, cp_body): if self.CP.carFingerprint in HONDA_BOSCH: if not self.CP.openpilotLongitudinalControl: + self.scm_buttons = cp.vl["SCM_BUTTONS"] if self.CP.carFingerprint in HONDA_BOSCH_RADARLESS else {} # ACC_HUD is on camera bus on radarless cars acc_hud = cp_cam.vl["ACC_HUD"] if self.CP.carFingerprint in HONDA_BOSCH_RADARLESS else cp.vl["ACC_HUD"] ret.cruiseState.nonAdaptive = acc_hud["CRUISE_CONTROL_LABEL"] != 0 diff --git a/selfdrive/car/honda/hondacan.py b/selfdrive/car/honda/hondacan.py index a8cbad78cecbf5..21b259ef4dbbf0 100644 --- a/selfdrive/car/honda/hondacan.py +++ b/selfdrive/car/honda/hondacan.py @@ -147,7 +147,8 @@ def create_ui_commands(packer, CP, enabled, pcm_speed, hud, is_metric, acc_hud, commands.append(packer.make_can_msg("ACC_HUD", bus_pt, acc_hud_values)) lkas_hud_values = { - 'SET_ME_X41': 0x41, + 'ENABLED': 1, + 'SET_ME_X20': 0x20, 'STEERING_REQUIRED': hud.steer_required, 'SOLID_LANES': hud.lanes_visible, 'BEEP': 0, @@ -181,11 +182,17 @@ def create_ui_commands(packer, CP, enabled, pcm_speed, hud, is_metric, acc_hud, return commands -def spam_buttons_command(packer, button_val, car_fingerprint): +def create_buttons_command(packer, button_val, setting_val, stock_scm_buttons, car_fingerprint): values = { - 'CRUISE_BUTTONS': button_val, - 'CRUISE_SETTING': 0, + 'CRUISE_BUTTONS': button_val } + # Radarless: forward unmodified signals + if len(stock_scm_buttons): + values.update({ + 'CRUISE_SETTING': setting_val, + 'BOH_1': stock_scm_buttons['BOH_1'], + 'BOH_2': stock_scm_buttons['BOH_2'], + }) # send buttons to camera on radarless cars bus = 2 if car_fingerprint in HONDA_BOSCH_RADARLESS else get_pt_bus(car_fingerprint) return packer.make_can_msg("SCM_BUTTONS", bus, values) diff --git a/selfdrive/car/honda/interface.py b/selfdrive/car/honda/interface.py index 9f228cd8fb6e90..326833a9e78099 100755 --- a/selfdrive/car/honda/interface.py +++ b/selfdrive/car/honda/interface.py @@ -13,8 +13,9 @@ ButtonType = car.CarState.ButtonEvent.Type EventName = car.CarEvent.EventName TransmissionType = car.CarParams.TransmissionType -BUTTONS_DICT = {CruiseButtons.RES_ACCEL: ButtonType.accelCruise, CruiseButtons.DECEL_SET: ButtonType.decelCruise, - CruiseButtons.MAIN: ButtonType.altButton3, CruiseButtons.CANCEL: ButtonType.cancel} +CRUISE_BUTTONS_DICT = {CruiseButtons.RES_ACCEL: ButtonType.accelCruise, CruiseButtons.DECEL_SET: ButtonType.decelCruise, + CruiseButtons.MAIN: ButtonType.altButton3, CruiseButtons.CANCEL: ButtonType.cancel} +SETTINGS_BUTTONS_DICT = {CruiseButtons.DISTANCE: ButtonType.gapAdjustCruise, CruiseButtons.LKAS: ButtonType.altButton1} class CarInterface(CarInterfaceBase): @@ -312,8 +313,8 @@ def _update(self, c): ret = self.CS.update(self.cp, self.cp_cam, self.cp_body) ret.buttonEvents = [ - *create_button_events(self.CS.cruise_buttons, self.CS.prev_cruise_buttons, BUTTONS_DICT), - *create_button_events(self.CS.cruise_setting, self.CS.prev_cruise_setting, {1: ButtonType.altButton1}), + *create_button_events(self.CS.cruise_buttons, self.CS.prev_cruise_buttons, CRUISE_BUTTONS_DICT), + *create_button_events(self.CS.cruise_setting, self.CS.prev_cruise_setting, SETTINGS_BUTTONS_DICT), ] # events diff --git a/selfdrive/car/honda/values.py b/selfdrive/car/honda/values.py index fefce7ff9ca9d4..deb773d4bea71e 100644 --- a/selfdrive/car/honda/values.py +++ b/selfdrive/car/honda/values.py @@ -57,6 +57,11 @@ class CruiseButtons: DECEL_SET = 3 CANCEL = 2 MAIN = 1 + NONE = 0 + +# CRUISE_SETTINGS + DISTANCE = 3 + LKAS = 1 # See dbc files for info on values diff --git a/selfdrive/car/tests/routes.py b/selfdrive/car/tests/routes.py index 69b39b3b2e8e4b..5b22a71947a4ee 100755 --- a/selfdrive/car/tests/routes.py +++ b/selfdrive/car/tests/routes.py @@ -93,7 +93,7 @@ class CarTestRoute(NamedTuple): CarTestRoute("f34a60d68d83b1e5|2020-10-06--14-35-55", HONDA.ACURA_RDX), CarTestRoute("54fd8451b3974762|2021-04-01--14-50-10", HONDA.RIDGELINE), CarTestRoute("2d5808fae0b38ac6|2021-09-01--17-14-11", HONDA.HONDA_E), - CarTestRoute("f44aa96ace22f34a|2021-12-22--06-22-31", HONDA.CIVIC_2022), + CarTestRoute("f44aa96ace22f34a|2021-12-22--06-22-31", HONDA.CIVIC_2022), # TODO: Replace with route where OP sends buttons to the cam when engaged CarTestRoute("87d7f06ade479c2e|2023-09-11--23-30-11", HYUNDAI.AZERA_6TH_GEN), CarTestRoute("66189dd8ec7b50e6|2023-09-20--07-02-12", HYUNDAI.AZERA_HEV_6TH_GEN), diff --git a/selfdrive/test/process_replay/test_processes.py b/selfdrive/test/process_replay/test_processes.py index 46fa93ba4dd939..e05d155d49d565 100755 --- a/selfdrive/test/process_replay/test_processes.py +++ b/selfdrive/test/process_replay/test_processes.py @@ -25,6 +25,7 @@ ("TOYOTA3", "f7d7e3538cda1a2a|2021-08-16--08-55-34--6"), # TOYOTA.COROLLA_TSS2 ("HONDA", "eb140f119469d9ab|2021-06-12--10-46-24--27"), # HONDA.CIVIC (NIDEC) ("HONDA2", "7d2244f34d1bbcda|2021-06-25--12-25-37--26"), # HONDA.ACCORD (BOSCH) + # TODO: Add 'HONDA3' for radarless cars with OP sending buttons to camera when engaged ("CHRYSLER", "4deb27de11bee626|2021-02-20--11-28-55--8"), # CHRYSLER.PACIFICA_2018_HYBRID ("RAM", "17fc16d840fe9d21|2023-04-26--13-28-44--5"), # CHRYSLER.RAM_1500 ("SUBARU", "341dccd5359e3c97|2022-09-12--10-35-33--3"), # SUBARU.OUTBACK @@ -49,6 +50,7 @@ ("TOYOTA3", "regen7204CA3A498|2023-10-30--23-15-55--0"), ("HONDA", "regen048F8FA0B24|2023-10-30--23-15-53--0"), ("HONDA2", "regen7D2D3F82D5B|2023-10-30--23-15-55--0"), + # TODO: Add 'HONDA3' for radarless cars with OP sending buttons to camera when engaged ("CHRYSLER", "regen7125C42780C|2023-10-30--23-16-21--0"), ("RAM", "regen2731F3213D2|2023-10-30--23-18-11--0"), ("SUBARU", "regen86E4C1B4DDD|2023-10-30--23-18-14--0"),