Skip to content

Commit

Permalink
Honda: Bus abstraction cleanup (#1592)
Browse files Browse the repository at this point in the history
Honda: Cleanup LKAS bus abstraction
  • Loading branch information
jyoung8607 authored Dec 19, 2024
1 parent 2e971ce commit 3cb926c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
5 changes: 2 additions & 3 deletions opendbc/car/honda/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ def update(self, CC, CS, now_nanos):
can_sends.append(make_tester_present_msg(0x18DAB0F1, 1, suppress_response=True))

# Send steering command.
can_sends.append(hondacan.create_steering_control(self.packer, self.CAN, apply_steer, CC.latActive, self.CP.carFingerprint,
CS.CP.openpilotLongitudinalControl))
can_sends.append(hondacan.create_steering_control(self.packer, self.CAN, apply_steer, CC.latActive))

# wind brake from air resistance decel at high speed
wind_brake = interp(CS.out.vEgo, [0.0, 2.3, 35.0], [0.001, 0.002, 0.15])
Expand Down Expand Up @@ -194,7 +193,7 @@ 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.CAN, self.CP.carFingerprint))
can_sends.append(hondacan.create_bosch_supplemental_1(self.packer, self.CAN))
# If using stock ACC, spam cancel command to kill gas when OP disengages.
if pcm_cancel_cmd:
can_sends.append(hondacan.spam_buttons_command(self.packer, self.CAN, CruiseButtons.CANCEL, self.CP.carFingerprint))
Expand Down
36 changes: 18 additions & 18 deletions opendbc/car/honda/hondacan.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ def __init__(self, CP=None, fingerprint=None) -> None:

if CP.carFingerprint in (HONDA_BOSCH - HONDA_BOSCH_RADARLESS):
self._pt, self._radar = self.offset + 1, self.offset
# normally steering commands are sent to radar, which forwards them to powertrain bus
# when radar is disabled, steering commands are sent directly to powertrain bus
self._lkas = self._pt if CP.openpilotLongitudinalControl else self._radar
else:
self._pt, self._radar = self.offset, self.offset + 1
self._pt, self._radar, self._lkas = self.offset, self.offset + 1, self.offset

@property
def pt(self) -> int:
Expand All @@ -31,14 +34,14 @@ def radar(self) -> int:
def camera(self) -> int:
return self.offset + 2

@property
def lkas(self) -> int:
return self._lkas

def get_lkas_cmd_bus(CAN, car_fingerprint, radar_disabled=False):
no_radar = car_fingerprint in HONDA_BOSCH_RADARLESS
if radar_disabled or no_radar:
# when radar is disabled, steering commands are sent directly to powertrain bus
return CAN.pt
# normally steering commands are sent to radar, which forwards them to powertrain bus
return 0
# B-CAN is forwarded to ACC-CAN radar side (CAN 0 on fake ethernet port)
@property
def body(self) -> int:
return self.offset


def get_cruise_speed_conversion(car_fingerprint: str, is_metric: bool) -> float:
Expand Down Expand Up @@ -114,30 +117,27 @@ def create_acc_commands(packer, CAN, enabled, active, accel, gas, stopping_count
return commands


def create_steering_control(packer, CAN, apply_steer, lkas_active, car_fingerprint, radar_disabled):
def create_steering_control(packer, CAN, apply_steer, lkas_active):
values = {
"STEER_TORQUE": apply_steer if lkas_active else 0,
"STEER_TORQUE_REQUEST": lkas_active,
}
bus = get_lkas_cmd_bus(CAN, car_fingerprint, radar_disabled)
return packer.make_can_msg("STEERING_CONTROL", bus, values)
return packer.make_can_msg("STEERING_CONTROL", CAN.lkas, values)


def create_bosch_supplemental_1(packer, CAN, car_fingerprint):
def create_bosch_supplemental_1(packer, CAN):
# non-active params
values = {
"SET_ME_X04": 0x04,
"SET_ME_X80": 0x80,
"SET_ME_X10": 0x10,
}
bus = get_lkas_cmd_bus(CAN, car_fingerprint)
return packer.make_can_msg("BOSCH_SUPPLEMENTAL_1", bus, values)
return packer.make_can_msg("BOSCH_SUPPLEMENTAL_1", CAN.lkas, values)


def create_ui_commands(packer, CAN, CP, enabled, pcm_speed, hud, is_metric, acc_hud, lkas_hud):
commands = []
radar_disabled = CP.carFingerprint in (HONDA_BOSCH - HONDA_BOSCH_RADARLESS) and CP.openpilotLongitudinalControl
bus_lkas = get_lkas_cmd_bus(CAN, CP.carFingerprint, radar_disabled)

if CP.openpilotLongitudinalControl:
acc_hud_values = {
Expand Down Expand Up @@ -183,10 +183,10 @@ def create_ui_commands(packer, CAN, CP, enabled, pcm_speed, hud, is_metric, acc_
lkas_hud_values['SET_ME_X48'] = 0x48

if CP.flags & HondaFlags.BOSCH_EXT_HUD and not CP.openpilotLongitudinalControl:
commands.append(packer.make_can_msg('LKAS_HUD_A', bus_lkas, lkas_hud_values))
commands.append(packer.make_can_msg('LKAS_HUD_B', bus_lkas, lkas_hud_values))
commands.append(packer.make_can_msg('LKAS_HUD_A', CAN.lkas, lkas_hud_values))
commands.append(packer.make_can_msg('LKAS_HUD_B', CAN.lkas, lkas_hud_values))
else:
commands.append(packer.make_can_msg('LKAS_HUD', bus_lkas, lkas_hud_values))
commands.append(packer.make_can_msg('LKAS_HUD', CAN.lkas, lkas_hud_values))

if radar_disabled:
radar_hud_values = {
Expand Down
2 changes: 1 addition & 1 deletion opendbc/car/honda/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,4 @@ def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experime
@staticmethod
def init(CP, can_recv, can_send):
if CP.carFingerprint in (HONDA_BOSCH - HONDA_BOSCH_RADARLESS) and CP.openpilotLongitudinalControl:
disable_ecu(can_recv, can_send, bus=1, addr=0x18DAB0F1, com_cont_req=b'\x28\x83\x03')
disable_ecu(can_recv, can_send, bus=CanBus(CP).pt, addr=0x18DAB0F1, com_cont_req=b'\x28\x83\x03')

0 comments on commit 3cb926c

Please sign in to comment.