HKG: CAN config (#3281)

* can config

* clean up

* simple to start

* add fuel type

* last

* auto detection support

* cast

* move

* spaciing

* sort

* static
This commit is contained in:
Shane Smiskol
2026-04-02 22:37:44 -07:00
committed by GitHub
parent a3a9aaa3d5
commit 4c035f2794
2 changed files with 94 additions and 37 deletions

View File

@@ -1,6 +1,6 @@
from opendbc.car import Bus, get_safety_config, structs, uds
from opendbc.car.hyundai.hyundaicanfd import CanBus
from opendbc.car.hyundai.values import HyundaiFlags, CAR, DBC, HyundaiSafetyFlags
from opendbc.car.hyundai.values import HyundaiFlags, HyundaiCANConfig, CAR, DBC, HyundaiSafetyFlags
from opendbc.car.hyundai.radar_interface import RADAR_START_ADDR
from opendbc.car.interfaces import CarInterfaceBase
from opendbc.car.disable_ecu import disable_ecu
@@ -83,17 +83,11 @@ class CarInterface(CarInterfaceBase):
else:
# Shared configuration for non CAN-FD cars
ret.flags |= HyundaiCANConfig.detect(fingerprint)
ret.alphaLongitudinalAvailable = not (ret.flags & (HyundaiFlags.LEGACY | HyundaiFlags.UNSUPPORTED_LONGITUDINAL))
ret.enableBsm = 0x58b in fingerprint[0]
# Send LFA message on cars with HDA
if 0x485 in fingerprint[2]:
ret.flags |= HyundaiFlags.SEND_LFA.value
# These cars use the FCA11 message for the AEB and FCW signals, all others use SCC12
if 0x38d in fingerprint[0] or 0x38d in fingerprint[2]:
ret.flags |= HyundaiFlags.USE_FCA.value
if ret.flags & HyundaiFlags.LEGACY:
# these cars require a special panda safety mode due to missing counters and checksums in the messages
ret.safetyConfigs = [get_safety_config(structs.CarParams.SafetyModel.hyundaiLegacy)]
@@ -103,10 +97,6 @@ class CarInterface(CarInterfaceBase):
if ret.flags & HyundaiFlags.CAMERA_SCC:
ret.safetyConfigs[0].safetyParam |= HyundaiSafetyFlags.CAMERA_SCC.value
# These cars have the LFA button on the steering wheel
if 0x391 in fingerprint[0]:
ret.flags |= HyundaiFlags.HAS_LDA_BUTTON.value
# Common lateral control setup
ret.centerToFront = ret.wheelbase * 0.4

View File

@@ -1,6 +1,6 @@
import re
from dataclasses import dataclass, field
from enum import IntFlag
from enum import IntFlag, StrEnum, auto
from opendbc.car import Bus, CarSpecs, DbcDict, PlatformConfig, Platforms, uds
from opendbc.car.common.conversions import Conversions as CV
@@ -153,11 +153,60 @@ class HyundaiCarDocs(CarDocs):
package: str = "Smart Cruise Control (SCC)"
class FuelType(StrEnum):
ICE = auto() # default
HYBRID = auto()
EV = auto()
FCEV = auto()
@dataclass
class HyundaiCANConfig:
camera_scc: bool = False
fuel_type: FuelType = FuelType.ICE
@staticmethod
def detect(fingerprint) -> int:
flags = 0
# Send LFA message on cars with HDA
if 0x485 in fingerprint[2]:
flags |= HyundaiFlags.SEND_LFA
# These cars use the FCA11 message for the AEB and FCW signals, all others use SCC12
if 0x38d in fingerprint[0] or 0x38d in fingerprint[2]:
flags |= HyundaiFlags.USE_FCA
# These cars have the LFA button on the steering wheel
if 0x391 in fingerprint[0]:
flags |= HyundaiFlags.HAS_LDA_BUTTON
return int(flags)
def static_flags(self) -> int:
flags = 0
if self.camera_scc:
flags |= HyundaiFlags.CAMERA_SCC
if self.fuel_type == FuelType.HYBRID:
flags |= HyundaiFlags.HYBRID
elif self.fuel_type == FuelType.EV:
flags |= HyundaiFlags.EV
elif self.fuel_type == FuelType.FCEV:
flags |= HyundaiFlags.FCEV
return flags
@dataclass
class HyundaiPlatformConfig(PlatformConfig):
dbc_dict: DbcDict = field(default_factory=lambda: {Bus.pt: "hyundai_kia_generic"})
can_config: HyundaiCANConfig = field(default_factory=HyundaiCANConfig)
def init(self):
self.flags |= self.can_config.static_flags()
if self.flags & HyundaiFlags.MANDO_RADAR:
self.dbc_dict = {Bus.pt: "hyundai_kia_generic", Bus.radar: 'hyundai_kia_mando_front_radar_generated'}
@@ -185,7 +234,7 @@ class CAR(Platforms):
HyundaiCarDocs("Hyundai Azera Hybrid 2020", "All", car_parts=CarParts.common([CarHarness.hyundai_k])),
],
CarSpecs(mass=1675, wheelbase=2.885, steerRatio=14.5),
flags=HyundaiFlags.HYBRID,
can_config=HyundaiCANConfig(fuel_type=FuelType.HYBRID),
)
HYUNDAI_ELANTRA = HyundaiPlatformConfig(
[
@@ -214,7 +263,8 @@ class CAR(Platforms):
[HyundaiCarDocs("Hyundai Elantra Hybrid 2021-23", video="https://youtu.be/_EdYQtV52-c",
car_parts=CarParts.common([CarHarness.hyundai_k]))],
CarSpecs(mass=3017 * CV.LB_TO_KG, wheelbase=2.72, steerRatio=12.9, tireStiffnessFactor=0.65),
flags=HyundaiFlags.CHECKSUM_CRC8 | HyundaiFlags.HYBRID,
flags=HyundaiFlags.CHECKSUM_CRC8,
can_config=HyundaiCANConfig(fuel_type=FuelType.HYBRID),
)
HYUNDAI_GENESIS = HyundaiPlatformConfig(
[
@@ -228,32 +278,36 @@ class CAR(Platforms):
HYUNDAI_IONIQ = HyundaiPlatformConfig(
[HyundaiCarDocs("Hyundai Ioniq Hybrid 2017-19", car_parts=CarParts.common([CarHarness.hyundai_c]))],
CarSpecs(mass=1490, wheelbase=2.7, steerRatio=13.73, tireStiffnessFactor=0.385),
flags=HyundaiFlags.HYBRID | HyundaiFlags.MIN_STEER_32_MPH,
flags=HyundaiFlags.MIN_STEER_32_MPH,
can_config=HyundaiCANConfig(fuel_type=FuelType.HYBRID),
)
HYUNDAI_IONIQ_HEV_2022 = HyundaiPlatformConfig(
[HyundaiCarDocs("Hyundai Ioniq Hybrid 2020-22", car_parts=CarParts.common([CarHarness.hyundai_h]))],
CarSpecs(mass=1490, wheelbase=2.7, steerRatio=13.73, tireStiffnessFactor=0.385),
flags=HyundaiFlags.HYBRID | HyundaiFlags.LEGACY,
flags=HyundaiFlags.LEGACY,
can_config=HyundaiCANConfig(fuel_type=FuelType.HYBRID),
)
HYUNDAI_IONIQ_EV_LTD = HyundaiPlatformConfig(
[HyundaiCarDocs("Hyundai Ioniq Electric 2019", car_parts=CarParts.common([CarHarness.hyundai_c]))],
CarSpecs(mass=1490, wheelbase=2.7, steerRatio=13.73, tireStiffnessFactor=0.385),
flags=HyundaiFlags.MANDO_RADAR | HyundaiFlags.EV | HyundaiFlags.LEGACY | HyundaiFlags.MIN_STEER_32_MPH,
flags=HyundaiFlags.MANDO_RADAR | HyundaiFlags.LEGACY | HyundaiFlags.MIN_STEER_32_MPH,
can_config=HyundaiCANConfig(fuel_type=FuelType.EV),
)
HYUNDAI_IONIQ_EV_2020 = HyundaiPlatformConfig(
[HyundaiCarDocs("Hyundai Ioniq Electric 2020", "All", car_parts=CarParts.common([CarHarness.hyundai_h]))],
CarSpecs(mass=1490, wheelbase=2.7, steerRatio=13.73, tireStiffnessFactor=0.385),
flags=HyundaiFlags.EV,
can_config=HyundaiCANConfig(fuel_type=FuelType.EV),
)
HYUNDAI_IONIQ_PHEV_2019 = HyundaiPlatformConfig(
[HyundaiCarDocs("Hyundai Ioniq Plug-in Hybrid 2019", car_parts=CarParts.common([CarHarness.hyundai_c]))],
CarSpecs(mass=1490, wheelbase=2.7, steerRatio=13.73, tireStiffnessFactor=0.385),
flags=HyundaiFlags.HYBRID | HyundaiFlags.MIN_STEER_32_MPH,
flags=HyundaiFlags.MIN_STEER_32_MPH,
can_config=HyundaiCANConfig(fuel_type=FuelType.HYBRID),
)
HYUNDAI_IONIQ_PHEV = HyundaiPlatformConfig(
[HyundaiCarDocs("Hyundai Ioniq Plug-in Hybrid 2020-22", "All", car_parts=CarParts.common([CarHarness.hyundai_h]))],
CarSpecs(mass=1490, wheelbase=2.7, steerRatio=13.73, tireStiffnessFactor=0.385),
flags=HyundaiFlags.HYBRID,
can_config=HyundaiCANConfig(fuel_type=FuelType.HYBRID),
)
HYUNDAI_KONA = HyundaiPlatformConfig(
[HyundaiCarDocs("Hyundai Kona 2020", min_enable_speed=6 * CV.MPH_TO_MS, car_parts=CarParts.common([CarHarness.hyundai_b]))],
@@ -263,17 +317,20 @@ class CAR(Platforms):
HYUNDAI_KONA_2022 = HyundaiPlatformConfig(
[HyundaiCarDocs("Hyundai Kona 2022-23", car_parts=CarParts.common([CarHarness.hyundai_o]))],
CarSpecs(mass=1491, wheelbase=2.6, steerRatio=13.42, tireStiffnessFactor=0.385),
flags=HyundaiFlags.CAMERA_SCC | HyundaiFlags.ALT_LIMITS_2,
flags=HyundaiFlags.ALT_LIMITS_2,
can_config=HyundaiCANConfig(camera_scc=True),
)
HYUNDAI_KONA_EV = HyundaiPlatformConfig(
[HyundaiCarDocs("Hyundai Kona Electric 2018-21", car_parts=CarParts.common([CarHarness.hyundai_g]))],
CarSpecs(mass=1685, wheelbase=2.6, steerRatio=13.42, tireStiffnessFactor=0.385),
flags=HyundaiFlags.EV | HyundaiFlags.ALT_LIMITS,
flags=HyundaiFlags.ALT_LIMITS,
can_config=HyundaiCANConfig(fuel_type=FuelType.EV),
)
HYUNDAI_KONA_EV_2022 = HyundaiPlatformConfig(
[HyundaiCarDocs("Hyundai Kona Electric 2022-23", car_parts=CarParts.common([CarHarness.hyundai_o]))],
CarSpecs(mass=1743, wheelbase=2.6, steerRatio=13.42, tireStiffnessFactor=0.385),
flags=HyundaiFlags.CAMERA_SCC | HyundaiFlags.EV | HyundaiFlags.ALT_LIMITS,
flags=HyundaiFlags.ALT_LIMITS,
can_config=HyundaiCANConfig(camera_scc=True, fuel_type=FuelType.EV),
)
HYUNDAI_KONA_EV_2ND_GEN = HyundaiCanFDPlatformConfig(
[HyundaiCarDocs("Hyundai Kona Electric (with HDA II, Korea only) 2023", video="https://www.youtube.com/watch?v=U2fOCmcQ8hw",
@@ -284,12 +341,13 @@ class CAR(Platforms):
HYUNDAI_KONA_HEV = HyundaiPlatformConfig(
[HyundaiCarDocs("Hyundai Kona Hybrid 2020", car_parts=CarParts.common([CarHarness.hyundai_i]))], # TODO: check packages,
CarSpecs(mass=1425, wheelbase=2.6, steerRatio=13.42, tireStiffnessFactor=0.385),
flags=HyundaiFlags.HYBRID | HyundaiFlags.ALT_LIMITS,
flags=HyundaiFlags.ALT_LIMITS,
can_config=HyundaiCANConfig(fuel_type=FuelType.HYBRID),
)
HYUNDAI_NEXO_1ST_GEN = HyundaiPlatformConfig(
[HyundaiCarDocs("Hyundai Nexo 2021", "All", car_parts=CarParts.common([CarHarness.hyundai_h]))],
CarSpecs(mass=3990 * CV.LB_TO_KG, wheelbase=2.79, steerRatio=14.19), # https://www.hyundainews.com/assets/documents/original/42768-2021NEXOProductGuideSpecs.pdf
flags=HyundaiFlags.FCEV,
can_config=HyundaiCANConfig(fuel_type=FuelType.FCEV),
)
HYUNDAI_SANTA_FE = HyundaiPlatformConfig(
[HyundaiCarDocs("Hyundai Santa Fe 2019-20", "All", video="https://youtu.be/bjDR0YjM__s",
@@ -306,12 +364,14 @@ class CAR(Platforms):
HYUNDAI_SANTA_FE_HEV_2022 = HyundaiPlatformConfig(
[HyundaiCarDocs("Hyundai Santa Fe Hybrid 2022-23", "All", car_parts=CarParts.common([CarHarness.hyundai_l]))],
HYUNDAI_SANTA_FE.specs,
flags=HyundaiFlags.CHECKSUM_CRC8 | HyundaiFlags.HYBRID,
flags=HyundaiFlags.CHECKSUM_CRC8,
can_config=HyundaiCANConfig(fuel_type=FuelType.HYBRID),
)
HYUNDAI_SANTA_FE_PHEV_2022 = HyundaiPlatformConfig(
[HyundaiCarDocs("Hyundai Santa Fe Plug-in Hybrid 2022-23", "All", car_parts=CarParts.common([CarHarness.hyundai_l]))],
HYUNDAI_SANTA_FE.specs,
flags=HyundaiFlags.CHECKSUM_CRC8 | HyundaiFlags.HYBRID,
flags=HyundaiFlags.CHECKSUM_CRC8,
can_config=HyundaiCANConfig(fuel_type=FuelType.HYBRID),
)
HYUNDAI_SONATA = HyundaiPlatformConfig(
[HyundaiCarDocs("Hyundai Sonata 2020-23", "All", video="https://www.youtube.com/watch?v=ix63r9kE3Fw",
@@ -352,7 +412,8 @@ class CAR(Platforms):
HYUNDAI_SONATA_HYBRID = HyundaiPlatformConfig(
[HyundaiCarDocs("Hyundai Sonata Hybrid 2020-23", "All", car_parts=CarParts.common([CarHarness.hyundai_a]))],
HYUNDAI_SONATA.specs,
flags=HyundaiFlags.MANDO_RADAR | HyundaiFlags.CHECKSUM_CRC8 | HyundaiFlags.HYBRID,
flags=HyundaiFlags.MANDO_RADAR | HyundaiFlags.CHECKSUM_CRC8,
can_config=HyundaiCANConfig(fuel_type=FuelType.HYBRID),
)
HYUNDAI_IONIQ_5 = HyundaiCanFDPlatformConfig(
[
@@ -404,7 +465,8 @@ class CAR(Platforms):
KIA_K5_HEV_2020 = HyundaiPlatformConfig(
[HyundaiCarDocs("Kia K5 Hybrid 2020-22", car_parts=CarParts.common([CarHarness.hyundai_a]))],
KIA_K5_2021.specs,
flags=HyundaiFlags.MANDO_RADAR | HyundaiFlags.CHECKSUM_CRC8 | HyundaiFlags.HYBRID,
flags=HyundaiFlags.MANDO_RADAR | HyundaiFlags.CHECKSUM_CRC8,
can_config=HyundaiCANConfig(fuel_type=FuelType.HYBRID),
)
KIA_K7_2017 = HyundaiPlatformConfig(
[HyundaiCarDocs("Kia K7 2017", car_parts=CarParts.common([CarHarness.hyundai_c]))],
@@ -423,7 +485,8 @@ class CAR(Platforms):
HyundaiCarDocs("Kia Niro EV 2022", "All", video="https://www.youtube.com/watch?v=lT7zcG6ZpGo", car_parts=CarParts.common([CarHarness.hyundai_h])),
],
CarSpecs(mass=3543 * CV.LB_TO_KG, wheelbase=2.7, steerRatio=13.6, tireStiffnessFactor=0.385), # average of all the cars
flags=HyundaiFlags.MANDO_RADAR | HyundaiFlags.EV,
flags=HyundaiFlags.MANDO_RADAR,
can_config=HyundaiCANConfig(fuel_type=FuelType.EV),
)
KIA_NIRO_EV_2ND_GEN = HyundaiCanFDPlatformConfig(
[
@@ -440,7 +503,8 @@ class CAR(Platforms):
HyundaiCarDocs("Kia Niro Plug-in Hybrid 2020", car_parts=CarParts.common([CarHarness.hyundai_d])),
],
KIA_NIRO_EV.specs,
flags=HyundaiFlags.MANDO_RADAR | HyundaiFlags.HYBRID | HyundaiFlags.UNSUPPORTED_LONGITUDINAL | HyundaiFlags.MIN_STEER_32_MPH,
flags=HyundaiFlags.MANDO_RADAR | HyundaiFlags.UNSUPPORTED_LONGITUDINAL | HyundaiFlags.MIN_STEER_32_MPH,
can_config=HyundaiCANConfig(fuel_type=FuelType.HYBRID),
)
KIA_NIRO_PHEV_2022 = HyundaiPlatformConfig(
[
@@ -448,7 +512,8 @@ class CAR(Platforms):
HyundaiCarDocs("Kia Niro Plug-in Hybrid 2022", car_parts=CarParts.common([CarHarness.hyundai_f])),
],
KIA_NIRO_EV.specs,
flags=HyundaiFlags.HYBRID | HyundaiFlags.MANDO_RADAR,
flags=HyundaiFlags.MANDO_RADAR,
can_config=HyundaiCANConfig(fuel_type=FuelType.HYBRID),
)
KIA_NIRO_HEV_2021 = HyundaiPlatformConfig(
[
@@ -456,7 +521,7 @@ class CAR(Platforms):
HyundaiCarDocs("Kia Niro Hybrid 2022", car_parts=CarParts.common([CarHarness.hyundai_f])),
],
KIA_NIRO_EV.specs,
flags=HyundaiFlags.HYBRID,
can_config=HyundaiCANConfig(fuel_type=FuelType.HYBRID),
)
KIA_NIRO_HEV_2ND_GEN = HyundaiCanFDPlatformConfig(
[HyundaiCarDocs("Kia Niro Hybrid 2023-24", car_parts=CarParts.common([CarHarness.hyundai_a]))],
@@ -477,12 +542,14 @@ class CAR(Platforms):
KIA_OPTIMA_H = HyundaiPlatformConfig(
[HyundaiCarDocs("Kia Optima Hybrid 2017", "Advanced Smart Cruise Control", car_parts=CarParts.common([CarHarness.hyundai_c]))],
CarSpecs(mass=3558 * CV.LB_TO_KG, wheelbase=2.8, steerRatio=13.75, tireStiffnessFactor=0.5),
flags=HyundaiFlags.HYBRID | HyundaiFlags.LEGACY,
flags=HyundaiFlags.LEGACY,
can_config=HyundaiCANConfig(fuel_type=FuelType.HYBRID),
)
KIA_OPTIMA_H_G4_FL = HyundaiPlatformConfig(
[HyundaiCarDocs("Kia Optima Hybrid 2019", car_parts=CarParts.common([CarHarness.hyundai_h]))],
CarSpecs(mass=3558 * CV.LB_TO_KG, wheelbase=2.8, steerRatio=13.75, tireStiffnessFactor=0.5),
flags=HyundaiFlags.HYBRID | HyundaiFlags.UNSUPPORTED_LONGITUDINAL,
flags=HyundaiFlags.UNSUPPORTED_LONGITUDINAL,
can_config=HyundaiCANConfig(fuel_type=FuelType.HYBRID),
)
KIA_SELTOS = HyundaiPlatformConfig(
[HyundaiCarDocs("Kia Seltos 2021", car_parts=CarParts.common([CarHarness.hyundai_a]))],