mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-08-24 00:03:45 +08:00
Use common flag
This commit is contained in:
@@ -102,22 +102,21 @@ class CarController:
|
||||
if self.CP.flags & HyundaiFlags.ENABLE_BLINKERS:
|
||||
can_sends.append([0x7b1, 0, b"\x02\x3E\x80\x00\x00\x00\x00\x00", self.CAN.ECAN])
|
||||
|
||||
can_canfd_hda2 = self.CP.flags & HyundaiFlags.CAN_CANFD_HDA2
|
||||
|
||||
# CAN-FD platforms
|
||||
if self.CP.carFingerprint in CANFD_CAR or can_canfd_hda2:
|
||||
if self.CP.carFingerprint in CANFD_CAR:
|
||||
hda2 = self.CP.flags & HyundaiFlags.CANFD_HDA2
|
||||
hda2_long = hda2 and self.CP.openpilotLongitudinalControl
|
||||
hda2_can_canfd = hda2 and self.CP.flags & HyundaiFlags.CAN_CANFD
|
||||
|
||||
# steering control
|
||||
can_sends.extend(hyundaicanfd.create_steering_messages(self.packer, self.CP, self.CAN, CC.enabled, apply_steer_req, apply_steer))
|
||||
|
||||
# disable LFA on HDA2
|
||||
if self.frame % 5 == 0 and (hda2 or can_canfd_hda2):
|
||||
if self.frame % 5 == 0 and hda2:
|
||||
can_sends.append(hyundaicanfd.create_cam_0x2a4(self.packer, self.CAN, CS.cam_0x2a4))
|
||||
|
||||
# LFA and HDA icons
|
||||
if self.frame % 5 == 0 and (not hda2 or hda2_long) and not can_canfd_hda2:
|
||||
if self.frame % 5 == 0 and (not hda2 or hda2_long):
|
||||
can_sends.append(hyundaicanfd.create_lfahda_cluster(self.packer, self.CAN, CC.enabled))
|
||||
|
||||
# blinkers
|
||||
@@ -133,7 +132,7 @@ class CarController:
|
||||
self.accel_last = accel
|
||||
else:
|
||||
# button presses
|
||||
if can_canfd_hda2:
|
||||
if hda2_can_canfd:
|
||||
if CC.cruiseControl.cancel:
|
||||
can_sends.append(hyundaican.create_clu11(self.packer, self.frame, CS.clu11, Buttons.CANCEL, self.CP))
|
||||
elif CC.cruiseControl.resume:
|
||||
|
||||
@@ -8,7 +8,8 @@ from opendbc.can.parser import CANParser
|
||||
from opendbc.can.can_define import CANDefine
|
||||
from openpilot.selfdrive.car.hyundai.hyundaicanfd import CanBus
|
||||
from openpilot.selfdrive.car.hyundai.values import HyundaiFlags, CAR, DBC, CAN_GEARS, CAMERA_SCC_CAR, \
|
||||
CANFD_CAR, EV_CAR, HYBRID_CAR, Buttons, CarControllerParams
|
||||
CANFD_CAR, EV_CAR, HYBRID_CAR, Buttons, CarControllerParams, \
|
||||
CAN_CANFD_CAR
|
||||
from openpilot.selfdrive.car.interfaces import CarStateBase
|
||||
|
||||
PREV_BUTTON_SAMPLES = 8
|
||||
@@ -53,7 +54,7 @@ class CarState(CarStateBase):
|
||||
self.params = CarControllerParams(CP)
|
||||
|
||||
def update(self, cp, cp_cam):
|
||||
if self.CP.carFingerprint in CANFD_CAR:
|
||||
if self.CP.carFingerprint in (CANFD_CAR - CAN_CANFD_CAR):
|
||||
return self.update_canfd(cp, cp_cam)
|
||||
|
||||
ret = car.CarState.new_message()
|
||||
@@ -106,7 +107,7 @@ class CarState(CarStateBase):
|
||||
ret.cruiseState.enabled = cp.vl["TCS13"]["ACC_REQ"] == 1
|
||||
ret.cruiseState.standstill = False
|
||||
else:
|
||||
scc_bus = "SCC12" if self.CP.flags & HyundaiFlags.CAN_CANFD_HDA2.value else "SCC11"
|
||||
scc_bus = "SCC12" if self.CP.flags & HyundaiFlags.CAN_CANFD.value else "SCC11"
|
||||
ret.cruiseState.available = cp_cruise.vl[scc_bus]["MainMode_ACC"] == 1
|
||||
ret.cruiseState.enabled = cp_cruise.vl["SCC12"]["ACCMode"] != 0
|
||||
ret.cruiseState.standstill = cp_cruise.vl[scc_bus]["SCCInfoDisplay"] == 4.
|
||||
@@ -142,7 +143,7 @@ class CarState(CarStateBase):
|
||||
|
||||
ret.gearShifter = self.parse_gear_shifter(self.shifter_values.get(gear))
|
||||
|
||||
if not self.CP.openpilotLongitudinalControl and not (self.CP.flags & HyundaiFlags.CAN_CANFD_HDA2.value):
|
||||
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
|
||||
@@ -157,7 +158,7 @@ class CarState(CarStateBase):
|
||||
# save the entire LKAS11 and CLU11
|
||||
self.lkas11 = copy.copy(cp_cam.vl["LKAS11"])
|
||||
self.clu11 = copy.copy(cp.vl["CLU11"])
|
||||
if self.CP.flags & HyundaiFlags.CAN_CANFD_HDA2:
|
||||
if self.CP.flags & HyundaiFlags.CAN_CANFD and self.CP.flags & HyundaiFlags.CANFD_HDA2:
|
||||
self.cam_0x2a4 = copy.copy(cp_cam.vl["CAM_0x2a4"])
|
||||
self.steer_state = cp.vl["MDPS12"]["CF_Mdps_ToiActive"] # 0 NOT ACTIVE, 1 ACTIVE
|
||||
self.prev_cruise_buttons = self.cruise_buttons[-1]
|
||||
@@ -240,7 +241,7 @@ class CarState(CarStateBase):
|
||||
if CP.carFingerprint in CANFD_CAR:
|
||||
return self.get_can_parser_canfd(CP)
|
||||
|
||||
freq_mdps12 = 100 if CP.flags & HyundaiFlags.CAN_CANFD_HDA2.value else 50
|
||||
freq_mdps12 = 100 if CP.flags & HyundaiFlags.CAN_CANFD.value else 50
|
||||
|
||||
messages = [
|
||||
# address, frequency
|
||||
@@ -257,18 +258,18 @@ class CarState(CarStateBase):
|
||||
("SAS11", 100),
|
||||
]
|
||||
|
||||
if not CP.openpilotLongitudinalControl and CP.carFingerprint not in CAMERA_SCC_CAR and not (CP.flags & HyundaiFlags.CAN_CANFD_HDA2.value):
|
||||
if not CP.openpilotLongitudinalControl and CP.carFingerprint not in CAMERA_SCC_CAR and not (CP.flags & HyundaiFlags.CAN_CANFD.value):
|
||||
messages += [
|
||||
("SCC11", 50),
|
||||
("SCC12", 50),
|
||||
]
|
||||
if CP.flags & HyundaiFlags.USE_FCA.value:
|
||||
messages.append(("FCA11", 50))
|
||||
elif CP.flags & HyundaiFlags.CAN_CANFD_HDA2.value:
|
||||
elif CP.flags & HyundaiFlags.CAN_CANFD.value:
|
||||
messages.append(("SCC12", 50))
|
||||
|
||||
if CP.enableBsm:
|
||||
freq_lca11 = 20 if CP.flags & HyundaiFlags.CAN_CANFD_HDA2.value else 50
|
||||
freq_lca11 = 20 if CP.flags & HyundaiFlags.CAN_CANFD.value else 50
|
||||
messages.append(("LCA11", freq_lca11))
|
||||
|
||||
if CP.carFingerprint in (HYBRID_CAR | EV_CAR):
|
||||
@@ -288,7 +289,7 @@ class CarState(CarStateBase):
|
||||
else:
|
||||
messages.append(("LVR12", 100))
|
||||
|
||||
bus = CanBus(CP).ECAN if CP.flags & HyundaiFlags.CAN_CANFD_HDA2.value else 0
|
||||
bus = CanBus(CP).ECAN if CP.flags & HyundaiFlags.CAN_CANFD.value else 0
|
||||
return CANParser(DBC[CP.carFingerprint]["pt"], messages, bus)
|
||||
|
||||
@staticmethod
|
||||
@@ -298,10 +299,10 @@ class CarState(CarStateBase):
|
||||
|
||||
messages = []
|
||||
|
||||
if not (CP.flags & HyundaiFlags.CAN_CANFD_HDA2):
|
||||
messages += [
|
||||
("LKAS11", 100)
|
||||
]
|
||||
if CP.flags & HyundaiFlags.CAN_CANFD:
|
||||
messages.append(("CAM_0x2a4", 20))
|
||||
else:
|
||||
messages.append(("LKAS11", 100))
|
||||
|
||||
if not CP.openpilotLongitudinalControl and CP.carFingerprint in CAMERA_SCC_CAR:
|
||||
messages += [
|
||||
@@ -312,10 +313,7 @@ class CarState(CarStateBase):
|
||||
if CP.flags & HyundaiFlags.USE_FCA.value:
|
||||
messages.append(("FCA11", 50))
|
||||
|
||||
if CP.flags & HyundaiFlags.CAN_CANFD_HDA2:
|
||||
messages.append(("CAM_0x2a4", 20))
|
||||
|
||||
bus = CanBus(CP).CAM if CP.flags & HyundaiFlags.CAN_CANFD_HDA2 else 2
|
||||
bus = CanBus(CP).CAM if CP.flags & HyundaiFlags.CAN_CANFD else 2
|
||||
return CANParser(DBC[CP.carFingerprint]["pt"], messages, bus)
|
||||
|
||||
def get_can_parser_canfd(self, CP):
|
||||
|
||||
@@ -113,7 +113,7 @@ def create_clu11(packer, frame, clu11, button, CP):
|
||||
values["CF_Clu_CruiseSwState"] = button
|
||||
values["CF_Clu_AliveCnt1"] = frame % 0x10
|
||||
# send buttons to camera on camera-scc based cars
|
||||
bus = 2 if CP.carFingerprint in CAMERA_SCC_CAR else CanBus(CP).ECAN if CP.flags & HyundaiFlags.CAN_CANFD_HDA2 else 0
|
||||
bus = 2 if CP.carFingerprint in CAMERA_SCC_CAR else CanBus(CP).ECAN if CP.flags & HyundaiFlags.CAN_CANFD else 0
|
||||
return packer.make_can_msg("CLU11", bus, values)
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ class CanBus(CanBusBase):
|
||||
|
||||
if hda2 is None:
|
||||
assert CP is not None
|
||||
hda2 = CP.flags & HyundaiFlags.CANFD_HDA2.value or CP.flags & HyundaiFlags.CAN_CANFD_HDA2.value
|
||||
hda2 = CP.flags & HyundaiFlags.CANFD_HDA2.value
|
||||
|
||||
# On the CAN-FD platforms, the LKAS camera is on both A-CAN and E-CAN. HDA2 cars
|
||||
# have a different harness than the HDA1 and non-HDA variants in order to split
|
||||
@@ -51,7 +51,7 @@ def create_steering_messages(packer, CP, CAN, enabled, lat_active, apply_steer):
|
||||
"NEW_SIGNAL_2": 0,
|
||||
}
|
||||
|
||||
if CP.flags & HyundaiFlags.CANFD_HDA2 or CP.flags & HyundaiFlags.CAN_CANFD_HDA2:
|
||||
if CP.flags & HyundaiFlags.CANFD_HDA2:
|
||||
if CP.openpilotLongitudinalControl:
|
||||
ret.append(packer.make_can_msg("LFA", CAN.ECAN, values))
|
||||
ret.append(packer.make_can_msg("LKAS", CAN.ACAN, values))
|
||||
|
||||
@@ -5,7 +5,7 @@ from openpilot.common.conversions import Conversions as CV
|
||||
from openpilot.selfdrive.car.hyundai.hyundaicanfd import CanBus
|
||||
from openpilot.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, UNSUPPORTED_LONGITUDINAL_CAR, \
|
||||
Buttons
|
||||
Buttons, CAN_CANFD_CAR
|
||||
from openpilot.selfdrive.car.hyundai.radar_interface import RADAR_START_ADDR
|
||||
from openpilot.selfdrive.car import create_button_events, get_safety_config
|
||||
from openpilot.selfdrive.car.interfaces import CarInterfaceBase
|
||||
@@ -50,11 +50,10 @@ class CarInterface(CarInterfaceBase):
|
||||
ret.flags |= HyundaiFlags.CANFD_ALT_GEARS.value
|
||||
if candidate not in CANFD_RADAR_SCC_CAR:
|
||||
ret.flags |= HyundaiFlags.CANFD_CAMERA_SCC.value
|
||||
# detect cars with hybrid definitions of CAN and CAN-FD
|
||||
if candidate in CAN_CANFD_CAR:
|
||||
ret.flags |= HyundaiFlags.CAN_CANFD.value
|
||||
else:
|
||||
# detect HDA2 with CAN and CAN-FD definitions with ADAS Driving ECU
|
||||
if hda2:
|
||||
ret.flags |= HyundaiFlags.CAN_CANFD_HDA2.value
|
||||
|
||||
# Send LFA message on cars with HDA
|
||||
if 0x485 in fingerprint[2]:
|
||||
ret.flags |= HyundaiFlags.SEND_LFA.value
|
||||
@@ -255,7 +254,7 @@ class CarInterface(CarInterfaceBase):
|
||||
else:
|
||||
ret.longitudinalTuning.kpV = [0.5]
|
||||
ret.longitudinalTuning.kiV = [0.0]
|
||||
ret.experimentalLongitudinalAvailable = candidate not in (UNSUPPORTED_LONGITUDINAL_CAR | CAMERA_SCC_CAR) and candidate != CAR.PALISADE_2023
|
||||
ret.experimentalLongitudinalAvailable = candidate not in (UNSUPPORTED_LONGITUDINAL_CAR | CAMERA_SCC_CAR | CAN_CANFD_CAR)
|
||||
ret.openpilotLongitudinalControl = experimental_long and ret.experimentalLongitudinalAvailable
|
||||
ret.pcmCruise = not ret.openpilotLongitudinalControl
|
||||
|
||||
@@ -267,15 +266,16 @@ class CarInterface(CarInterfaceBase):
|
||||
ret.longitudinalActuatorDelayUpperBound = 0.5
|
||||
|
||||
# *** feature detection ***
|
||||
if candidate in CANFD_CAR:
|
||||
if candidate in (CANFD_CAR - CAN_CANFD_CAR):
|
||||
ret.enableBsm = 0x1e5 in fingerprint[CAN.ECAN]
|
||||
else:
|
||||
bus = CAN.ECAN if ret.flags & HyundaiFlags.CAN_CANFD_HDA2 else 0
|
||||
bus = CAN.ECAN if ret.flags & HyundaiFlags.CAN_CANFD else 0
|
||||
ret.enableBsm = 0x58b in fingerprint[bus]
|
||||
|
||||
# *** panda safety config ***
|
||||
if candidate in CANFD_CAR:
|
||||
cfgs = [get_safety_config(car.CarParams.SafetyModel.hyundaiCanfd), ]
|
||||
cfgs = [get_safety_config(car.CarParams.SafetyModel.hyundaiCanfd), ] if ret.flags & HyundaiFlags.CAN_CANFD else \
|
||||
[get_safety_config(car.CarParams.SafetyModel.hyundai), ]
|
||||
if CAN.ECAN >= 4:
|
||||
cfgs.insert(0, get_safety_config(car.CarParams.SafetyModel.noOutput))
|
||||
ret.safetyConfigs = cfgs
|
||||
@@ -286,16 +286,12 @@ 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
|
||||
if ret.flags & HyundaiFlags.CAN_CANFD:
|
||||
ret.safetyConfigs[-1].safetyParam |= Panda.FLAG_HYUNDAI_CAN_CANFD_HDA2
|
||||
else:
|
||||
if candidate in LEGACY_SAFETY_MODE_CAR:
|
||||
# these cars require a special panda safety mode due to missing counters and checksums in the messages
|
||||
ret.safetyConfigs = [get_safety_config(car.CarParams.SafetyModel.hyundaiLegacy)]
|
||||
elif ret.flags & HyundaiFlags.CAN_CANFD_HDA2:
|
||||
cfgs = [get_safety_config(car.CarParams.SafetyModel.hyundai), ]
|
||||
if CAN.ECAN >= 4:
|
||||
cfgs.insert(0, get_safety_config(car.CarParams.SafetyModel.noOutput))
|
||||
ret.safetyConfigs = cfgs
|
||||
ret.safetyConfigs[-1].safetyParam |= Panda.FLAG_HYUNDAI_CAN_CANFD_HDA2
|
||||
else:
|
||||
ret.safetyConfigs = [get_safety_config(car.CarParams.SafetyModel.hyundai, 0)]
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class CarControllerParams:
|
||||
self.STEER_DELTA_UP = 2
|
||||
self.STEER_DELTA_DOWN = 3
|
||||
|
||||
elif CP.flags & HyundaiFlags.CAN_CANFD_HDA2:
|
||||
elif CP.flags & HyundaiFlags.CAN_CANFD:
|
||||
self.STEER_MAX = 384
|
||||
self.STEER_DELTA_UP = 3
|
||||
self.STEER_DELTA_DOWN = 6
|
||||
@@ -69,7 +69,7 @@ class HyundaiFlags(IntFlag):
|
||||
CANFD_ALT_GEARS_2 = 64
|
||||
SEND_LFA = 128
|
||||
USE_FCA = 256
|
||||
CAN_CANFD_HDA2 = 512
|
||||
CAN_CANFD = 512
|
||||
|
||||
|
||||
class CAR:
|
||||
@@ -1967,7 +1967,10 @@ CAN_GEARS = {
|
||||
CANFD_CAR = {CAR.KIA_EV6, CAR.IONIQ_5, CAR.IONIQ_6, CAR.TUCSON_4TH_GEN, CAR.TUCSON_HYBRID_4TH_GEN, CAR.KIA_SPORTAGE_HYBRID_5TH_GEN,
|
||||
CAR.SANTA_CRUZ_1ST_GEN, CAR.KIA_SPORTAGE_5TH_GEN, CAR.GENESIS_GV70_1ST_GEN, CAR.KIA_SORENTO_PHEV_4TH_GEN,
|
||||
CAR.GENESIS_GV60_EV_1ST_GEN, CAR.KIA_SORENTO_4TH_GEN, CAR.KIA_NIRO_HEV_2ND_GEN, CAR.KIA_NIRO_EV_2ND_GEN,
|
||||
CAR.GENESIS_GV80, CAR.KIA_CARNIVAL_4TH_GEN, CAR.KIA_SORENTO_HEV_4TH_GEN}
|
||||
CAR.GENESIS_GV80, CAR.KIA_CARNIVAL_4TH_GEN, CAR.KIA_SORENTO_HEV_4TH_GEN, CAR.PALISADE_2023}
|
||||
|
||||
# These cars have hybrid definitions of CAN and CAN-FD
|
||||
CAN_CANFD_CAR = {CAR.PALISADE_2023, }
|
||||
|
||||
# The radar does SCC on these cars when HDA I, rather than the camera
|
||||
CANFD_RADAR_SCC_CAR = {CAR.GENESIS_GV70_1ST_GEN, CAR.KIA_SORENTO_PHEV_4TH_GEN, CAR.KIA_SORENTO_4TH_GEN, CAR.GENESIS_GV80,
|
||||
|
||||
Reference in New Issue
Block a user