Skip to content

Commit

Permalink
Honda Radarless: Send buttons to camera when engaged vs forwarding or…
Browse files Browse the repository at this point in the history
… spamming.
  • Loading branch information
csouers committed Jan 16, 2024
1 parent e1a05de commit 0e3eaba
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 13 deletions.
24 changes: 20 additions & 4 deletions selfdrive/car/honda/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions selfdrive/car/honda/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions selfdrive/car/honda/hondacan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
9 changes: 5 additions & 4 deletions selfdrive/car/honda/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions selfdrive/car/honda/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/tests/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions selfdrive/test/process_replay/test_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"),
Expand Down

0 comments on commit 0e3eaba

Please sign in to comment.