diff --git a/selfdrive/car/hyundai/carcontroller.py b/selfdrive/car/hyundai/carcontroller.py index e16e42afd1..3d9d2a8099 100644 --- a/selfdrive/car/hyundai/carcontroller.py +++ b/selfdrive/car/hyundai/carcontroller.py @@ -5,7 +5,7 @@ from common.realtime import DT_CTRL from opendbc.can.packer import CANPacker from selfdrive.car import apply_std_steer_torque_limits from selfdrive.car.hyundai import hyundaicanfd, hyundaican -from selfdrive.car.hyundai.values import HyundaiFlags, Buttons, CarControllerParams, CANFD_CAR, CAR, CAN_CANFD_CAR +from selfdrive.car.hyundai.values import HyundaiFlags, Buttons, CarControllerParams, CANFD_CAR, CAR VisualAlert = car.CarControl.HUDControl.VisualAlert LongCtrlState = car.CarControl.Actuators.LongControlState @@ -156,7 +156,7 @@ class CarController: can_sends.append(hyundaicanfd.create_buttons(self.packer, self.CP, CS.buttons_counter+1, Buttons.RES_ACCEL)) self.last_button_frame = self.frame else: - if self.car_fingerprint in CAN_CANFD_CAR: + if self.CP.flags & HyundaiFlags.CAN_CANFD: can_sends.append(hyundaican.create_lkas11_new(self.packer, self.frame, apply_steer, lat_active, torque_fault, CS.lkas11, CC.enabled, hud_control.leftLaneVisible, hud_control.rightLaneVisible, @@ -169,12 +169,12 @@ class CarController: if not self.CP.openpilotLongitudinalControl: if CC.cruiseControl.cancel: - can_sends.append(hyundaican.create_clu11(self.packer, self.frame, CS.clu11, Buttons.CANCEL, self.CP.carFingerprint)) + can_sends.append(hyundaican.create_clu11(self.packer, self.frame, CS.clu11, Buttons.CANCEL, self.CP)) elif CC.cruiseControl.resume: # send resume at a max freq of 10Hz if (self.frame - self.last_button_frame) * DT_CTRL > 0.1: # send 25 messages at a time to increases the likelihood of resume being accepted - can_sends.extend([hyundaican.create_clu11(self.packer, self.frame, CS.clu11, Buttons.RES_ACCEL, self.CP.carFingerprint)] * 25) + can_sends.extend([hyundaican.create_clu11(self.packer, self.frame, CS.clu11, Buttons.RES_ACCEL, self.CP)] * 25) if (self.frame - self.last_button_frame) * DT_CTRL >= 0.15: self.last_button_frame = self.frame diff --git a/selfdrive/car/hyundai/carstate.py b/selfdrive/car/hyundai/carstate.py index 0a583421ae..f48d9abcd1 100644 --- a/selfdrive/car/hyundai/carstate.py +++ b/selfdrive/car/hyundai/carstate.py @@ -7,7 +7,7 @@ from common.conversions import Conversions as CV from opendbc.can.parser import CANParser from opendbc.can.can_define import CANDefine from selfdrive.car.hyundai.hyundaicanfd import get_e_can_bus -from selfdrive.car.hyundai.values import HyundaiFlags, CAR, DBC, FEATURES, CAMERA_SCC_CAR, CANFD_CAR, EV_CAR, HYBRID_CAR, Buttons, CarControllerParams, CAN_CANFD_CAR +from selfdrive.car.hyundai.values import HyundaiFlags, CAR, DBC, FEATURES, CAMERA_SCC_CAR, CANFD_CAR, EV_CAR, HYBRID_CAR, Buttons, CarControllerParams from selfdrive.car.interfaces import CarStateBase PREV_BUTTON_SAMPLES = 8 @@ -134,7 +134,7 @@ class CarState(CarStateBase): ret.gearShifter = self.parse_gear_shifter(self.shifter_values.get(gear)) - if not self.CP.openpilotLongitudinalControl and self.CP.carFingerprint not in CAN_CANFD_CAR: + if not self.CP.openpilotLongitudinalControl and not (self.CP.flags & HyundaiFlags.CAN_CANFD.value): aeb_src = "FCA11" if self.CP.flags & HyundaiFlags.USE_FCA.value else "SCC12" aeb_sig = "FCA_CmdAct" if self.CP.flags & HyundaiFlags.USE_FCA.value else "AEB_CmdAct" aeb_warning = cp_cruise.vl[aeb_src]["CF_VSM_Warn"] != 0 @@ -302,10 +302,10 @@ class CarState(CarStateBase): ("WHL_SPD11", 50), ("SAS11", 100), ] - freq_mdps12 = 100 if CP.carFingerprint in CAN_CANFD_CAR else 50 + freq_mdps12 = 100 if CP.flags & HyundaiFlags.CAN_CANFD.value else 50 checks.append(("MDPS12", freq_mdps12)) - if not CP.openpilotLongitudinalControl and CP.carFingerprint not in (CAMERA_SCC_CAR | CAN_CANFD_CAR): + if not CP.openpilotLongitudinalControl and CP.carFingerprint not in CAMERA_SCC_CAR and not (CP.flags & HyundaiFlags.CAN_CANFD.value): signals += [ ("MainMode_ACC", "SCC11"), ("VSetDis", "SCC11"), @@ -331,7 +331,7 @@ class CarState(CarStateBase): ("CF_VSM_Warn", "SCC12"), ("CF_VSM_DecCmdAct", "SCC12"), ] - elif CP.carFingerprint in CAN_CANFD_CAR: + elif CP.flags & HyundaiFlags.CAN_CANFD.value: signals += [ ("MainMode_ACC", "SCC12"), ("VSetDis", "SCC12"), @@ -348,7 +348,7 @@ class CarState(CarStateBase): ("CF_Lca_IndLeft", "LCA11"), ("CF_Lca_IndRight", "LCA11"), ] - freq_lca11 = 20 if CP.carFingerprint in CAN_CANFD_CAR else 50 + freq_lca11 = 20 if CP.flags & HyundaiFlags.CAN_CANFD.value else 50 checks.append(("LCA11", freq_lca11)) if CP.carFingerprint in (HYBRID_CAR | EV_CAR): @@ -379,7 +379,7 @@ class CarState(CarStateBase): signals.append(("CF_Lvr_Gear", "LVR12")) checks.append(("LVR12", 100)) - bus = 4 if CP.carFingerprint in CAN_CANFD_CAR else 0 + bus = 4 if CP.flags & HyundaiFlags.CAN_CANFD.value else 0 return CANParser(DBC[CP.carFingerprint]["pt"], signals, checks, bus) @staticmethod @@ -394,7 +394,7 @@ class CarState(CarStateBase): ("CF_Lkas_LdwsRHWarning", "LKAS11"), ("CF_Lkas_FcwOpt_USM", "LKAS11"), ] - if CP.carFingerprint not in CAN_CANFD_CAR: + if CP.flags & HyundaiFlags.CAN_CANFD.value: signals += [ ("CF_Lkas_LdwsSysState", "LKAS11"), ("CF_Lkas_SysWarning", "LKAS11"), @@ -439,7 +439,7 @@ class CarState(CarStateBase): ("CF_VSM_DecCmdAct", "SCC12"), ] - bus = 6 if CP.carFingerprint in CAN_CANFD_CAR else 2 + bus = 6 if CP.flags & HyundaiFlags.CAN_CANFD.value else 2 return CANParser(DBC[CP.carFingerprint]["pt"], signals, checks, bus) @staticmethod diff --git a/selfdrive/car/hyundai/hyundaican.py b/selfdrive/car/hyundai/hyundaican.py index b9afac52a6..ea9b22eb4f 100644 --- a/selfdrive/car/hyundai/hyundaican.py +++ b/selfdrive/car/hyundai/hyundaican.py @@ -1,5 +1,5 @@ import crcmod -from selfdrive.car.hyundai.values import CAR, CHECKSUM, CAMERA_SCC_CAR, CAN_CANFD_CAR +from selfdrive.car.hyundai.values import HyundaiFlags, CAR, CHECKSUM, CAMERA_SCC_CAR hyundai_checksum = crcmod.mkCrcFun(0x11D, initCrc=0xFD, rev=False, xorOut=0xdf) @@ -99,12 +99,12 @@ def create_lkas11_new(packer, frame, apply_steer, steer_req, return packer.make_can_msg("LKAS11", 4, values) -def create_clu11(packer, frame, clu11, button, car_fingerprint): +def create_clu11(packer, frame, clu11, button, CP): values = clu11 values["CF_Clu_CruiseSwState"] = button values["CF_Clu_AliveCnt1"] = frame % 0x10 # send buttons to camera on camera-scc based cars - bus = 2 if car_fingerprint in CAMERA_SCC_CAR else 4 if car_fingerprint in CAN_CANFD_CAR else 0 + bus = 2 if CP.carFingerprint in CAMERA_SCC_CAR else 4 if CP.flags & HyundaiFlags.CAN_CANFD else 0 return packer.make_can_msg("CLU11", bus, values) diff --git a/selfdrive/car/hyundai/interface.py b/selfdrive/car/hyundai/interface.py index 48c6985848..1a1bfc8b11 100644 --- a/selfdrive/car/hyundai/interface.py +++ b/selfdrive/car/hyundai/interface.py @@ -2,7 +2,7 @@ from cereal import car from panda import Panda from common.conversions import Conversions as CV -from selfdrive.car.hyundai.values import HyundaiFlags, CAR, DBC, CANFD_CAR, CAMERA_SCC_CAR, CANFD_RADAR_SCC_CAR, CAN_CANFD_CAR, EV_CAR, HYBRID_CAR, LEGACY_SAFETY_MODE_CAR, Buttons +from selfdrive.car.hyundai.values import HyundaiFlags, CAR, DBC, CANFD_CAR, CAMERA_SCC_CAR, CANFD_RADAR_SCC_CAR, EV_CAR, HYBRID_CAR, LEGACY_SAFETY_MODE_CAR, Buttons from selfdrive.car.hyundai.radar_interface import RADAR_START_ADDR from selfdrive.car import STD_CARGO_KG, create_button_event, scale_tire_stiffness, get_safety_config from selfdrive.car.interfaces import CarInterfaceBase @@ -44,8 +44,13 @@ class CarInterface(CarInterfaceBase): if candidate not in CANFD_RADAR_SCC_CAR: ret.flags |= HyundaiFlags.CANFD_CAMERA_SCC.value else: + # detect platforms with HKG CAN and CAN-FD definitions + if 0x50 in fingerprint[5]: + ret.flags |= HyundaiFlags.CAN_CANFD.value + # Send LFA message on cars with HDA - if 0x485 in fingerprint[2]: + lfahda_bus = 6 if ret.flags & HyundaiFlags.CAN_CANFD.value else 2 + if 0x485 in fingerprint[lfahda_bus]: ret.flags |= HyundaiFlags.SEND_LFA.value # These cars use the FCA11 message for the AEB and FCW signals, all others use SCC12 @@ -234,7 +239,7 @@ class CarInterface(CarInterfaceBase): else: ret.longitudinalTuning.kpV = [0.5] ret.longitudinalTuning.kiV = [0.0] - ret.experimentalLongitudinalAvailable = candidate not in (LEGACY_SAFETY_MODE_CAR | CAMERA_SCC_CAR | CAN_CANFD_CAR) + ret.experimentalLongitudinalAvailable = candidate not in (LEGACY_SAFETY_MODE_CAR | CAMERA_SCC_CAR) and not (ret.flags & HyundaiFlags.CAN_CANFD) ret.openpilotLongitudinalControl = experimental_long and ret.experimentalLongitudinalAvailable ret.pcmCruise = not ret.openpilotLongitudinalControl @@ -250,7 +255,7 @@ class CarInterface(CarInterfaceBase): bus = 5 if ret.flags & HyundaiFlags.CANFD_HDA2 else 4 ret.enableBsm = 0x1e5 in fingerprint[bus] else: - bus = 4 if candidate in CAN_CANFD_CAR else 0 + bus = 4 if ret.flags & HyundaiFlags.CAN_CANFD else 0 ret.enableBsm = 0x58b in fingerprint[bus] # *** panda safety config *** @@ -264,7 +269,7 @@ class CarInterface(CarInterfaceBase): ret.safetyConfigs[1].safetyParam |= Panda.FLAG_HYUNDAI_CANFD_ALT_BUTTONS if ret.flags & HyundaiFlags.CANFD_CAMERA_SCC: ret.safetyConfigs[1].safetyParam |= Panda.FLAG_HYUNDAI_CAMERA_SCC - elif candidate in CAN_CANFD_CAR: + elif ret.flags & HyundaiFlags.CAN_CANFD: ret.safetyConfigs = [get_safety_config(car.CarParams.SafetyModel.noOutput), get_safety_config(car.CarParams.SafetyModel.hyundai)] ret.safetyConfigs[1].safetyParam |= Panda.FLAG_HYUNDAI_CAN_CANFD diff --git a/selfdrive/car/hyundai/values.py b/selfdrive/car/hyundai/values.py index 22a7740682..8f013ec3e6 100644 --- a/selfdrive/car/hyundai/values.py +++ b/selfdrive/car/hyundai/values.py @@ -62,6 +62,7 @@ class HyundaiFlags(IntFlag): CANFD_ALT_GEARS_2 = 64 SEND_LFA = 128 USE_FCA = 256 + CAN_CANFD = 512 class CAR: @@ -1703,9 +1704,6 @@ CANFD_RADAR_SCC_CAR = {CAR.GENESIS_GV70_1ST_GEN, CAR.KIA_SORENTO_PHEV_4TH_GEN, C # The camera does SCC on these cars, rather than the radar CAMERA_SCC_CAR = {CAR.KONA_EV_2022, } -# These cars have both CAN and CAN-FD messages -CAN_CANFD_CAR = {CAR.PALISADE_2023, } - HYBRID_CAR = {CAR.IONIQ_PHEV, CAR.ELANTRA_HEV_2021, CAR.KIA_NIRO_PHEV, CAR.KIA_NIRO_HEV_2021, CAR.SONATA_HYBRID, CAR.KONA_HEV, CAR.IONIQ, CAR.IONIQ_HEV_2022, CAR.SANTA_FE_HEV_2022, CAR.SANTA_FE_PHEV_2022, CAR.IONIQ_PHEV_2019, CAR.TUCSON_HYBRID_4TH_GEN, CAR.KIA_SPORTAGE_HYBRID_5TH_GEN, CAR.KIA_SORENTO_PHEV_4TH_GEN, CAR.KIA_K5_HEV_2020, CAR.KIA_NIRO_HEV_2ND_GEN} # these cars use a different gas signal EV_CAR = {CAR.IONIQ_EV_2020, CAR.IONIQ_EV_LTD, CAR.KONA_EV, CAR.KIA_NIRO_EV, CAR.KONA_EV_2022, CAR.KIA_EV6, CAR.IONIQ_5, CAR.GENESIS_GV60_EV_1ST_GEN}