From 2bd4e71b243e8c07a8698ae91174cf269983a20b Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Sat, 19 Aug 2023 02:38:36 -0400 Subject: [PATCH] Hyundai longitudinal (CAN): don't send FCA11 on non-FCA cars (#28479) * Hyundai longitudinal (CAN): don't send FCA messages to non-FCA cars * Update comments * outside * change to FCA11 only * move down * add todos * Apply suggestions from code review * add todo --------- Co-authored-by: Shane Smiskol --- selfdrive/car/hyundai/carcontroller.py | 4 +++- selfdrive/car/hyundai/hyundaican.py | 27 ++++++++++++++------------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/selfdrive/car/hyundai/carcontroller.py b/selfdrive/car/hyundai/carcontroller.py index 8c734583e4..6af5f572da 100644 --- a/selfdrive/car/hyundai/carcontroller.py +++ b/selfdrive/car/hyundai/carcontroller.py @@ -171,8 +171,10 @@ class CarController: if self.frame % 2 == 0 and self.CP.openpilotLongitudinalControl: # TODO: unclear if this is needed jerk = 3.0 if actuators.longControlState == LongCtrlState.pid else 1.0 + use_fca = self.CP.flags & HyundaiFlags.USE_FCA.value can_sends.extend(hyundaican.create_acc_commands(self.packer, CC.enabled, accel, jerk, int(self.frame / 2), - hud_control.leadVisible, set_speed_in_units, stopping, CC.cruiseControl.override)) + hud_control.leadVisible, set_speed_in_units, stopping, + CC.cruiseControl.override, use_fca)) # 20 Hz LFA MFA message if self.frame % 5 == 0 and self.CP.flags & HyundaiFlags.SEND_LFA.value: diff --git a/selfdrive/car/hyundai/hyundaican.py b/selfdrive/car/hyundai/hyundaican.py index dc5a5b6286..c0c60fba03 100644 --- a/selfdrive/car/hyundai/hyundaican.py +++ b/selfdrive/car/hyundai/hyundaican.py @@ -125,7 +125,7 @@ def create_lfahda_mfc(packer, enabled, hda_set_speed=0): } return packer.make_can_msg("LFAHDA_MFC", 0, values) -def create_acc_commands(packer, enabled, accel, upper_jerk, idx, lead_visible, set_speed, stopping, long_override): +def create_acc_commands(packer, enabled, accel, upper_jerk, idx, lead_visible, set_speed, stopping, long_override, use_fca): commands = [] scc11_values = { @@ -163,17 +163,19 @@ def create_acc_commands(packer, enabled, accel, upper_jerk, idx, lead_visible, s } commands.append(packer.make_can_msg("SCC14", 0, scc14_values)) - # note that some vehicles most likely have an alternate checksum/counter definition - # https://github.com/commaai/opendbc/commit/9ddcdb22c4929baf310295e832668e6e7fcfa602 - fca11_values = { - "CR_FCA_Alive": idx % 0xF, - "PAINT1_Status": 1, - "FCA_DrvSetStatus": 1, - "FCA_Status": 1, # AEB disabled - } - fca11_dat = packer.make_can_msg("FCA11", 0, fca11_values)[2] - fca11_values["CR_FCA_ChkSum"] = hyundai_checksum(fca11_dat[:7]) - commands.append(packer.make_can_msg("FCA11", 0, fca11_values)) + # Only send FCA11 on cars where it exists on the bus + if use_fca: + # note that some vehicles most likely have an alternate checksum/counter definition + # https://github.com/commaai/opendbc/commit/9ddcdb22c4929baf310295e832668e6e7fcfa602 + fca11_values = { + "CR_FCA_Alive": idx % 0xF, + "PAINT1_Status": 1, + "FCA_DrvSetStatus": 1, + "FCA_Status": 1, # AEB disabled + } + fca11_dat = packer.make_can_msg("FCA11", 0, fca11_values)[2] + fca11_values["CR_FCA_ChkSum"] = hyundai_checksum(fca11_dat[:7]) + commands.append(packer.make_can_msg("FCA11", 0, fca11_values)) return commands @@ -187,6 +189,7 @@ def create_acc_opt(packer): } commands.append(packer.make_can_msg("SCC13", 0, scc13_values)) + # TODO: this needs to be detected and conditionally sent on unsupported long cars fca12_values = { "FCA_DrvSetState": 2, "FCA_USM": 1, # AEB disabled