Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hyundai: Car Port for Nexo 2021 #933

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
14 changes: 12 additions & 2 deletions opendbc/car/hyundai/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def __init__(self, CP):
self.shifter_values = can_define.dv["CLU15"]["CF_Clu_Gear"]
elif self.CP.carFingerprint in CAN_GEARS["use_tcu_gears"]:
self.shifter_values = can_define.dv["TCU12"]["CUR_GR"]
elif CP.flags & HyundaiFlags.FCEV:
self.shifter_values = can_define.dv["EMS20"]["HYDROGEN_GEAR_SHIFTER"]
else: # preferred and elect gear methods use same definition
self.shifter_values = can_define.dv["LVR12"]["CF_Lvr_Gear"]

Expand Down Expand Up @@ -127,8 +129,10 @@ def update(self, cp, cp_cam, *_) -> structs.CarState:
ret.espActive = cp.vl["TCS11"]["ABS_ACT"] == 1
ret.accFaulted = cp.vl["TCS13"]["ACCEnable"] != 0 # 0 ACC CONTROL ENABLED, 1-3 ACC CONTROL DISABLED

if self.CP.flags & (HyundaiFlags.HYBRID | HyundaiFlags.EV):
if self.CP.flags & HyundaiFlags.HYBRID:
if self.CP.flags & (HyundaiFlags.HYBRID | HyundaiFlags.EV | HyundaiFlags.FCEV):
if self.CP.flags & HyundaiFlags.FCEV:
ret.gas = cp.vl["ACCELERATOR"]["ACCELERATOR_PEDAL"] / 254.
elif self.CP.flags & HyundaiFlags.HYBRID:
ret.gas = cp.vl["E_EMS11"]["CR_Vcu_AccPedDep_Pos"] / 254.
else:
ret.gas = cp.vl["E_EMS11"]["Accel_Pedal_Pos"] / 254.
Expand All @@ -141,6 +145,8 @@ def update(self, cp, cp_cam, *_) -> structs.CarState:
# as this seems to be standard over all cars, but is not the preferred method.
if self.CP.flags & (HyundaiFlags.HYBRID | HyundaiFlags.EV):
gear = cp.vl["ELECT_GEAR"]["Elect_Gear_Shifter"]
elif self.CP.flags & HyundaiFlags.FCEV:
gear = cp.vl["EMS20"]["HYDROGEN_GEAR_SHIFTER"]
elif self.CP.carFingerprint in CAN_GEARS["use_cluster_gears"]:
gear = cp.vl["CLU15"]["CF_Clu_Gear"]
elif self.CP.carFingerprint in CAN_GEARS["use_tcu_gears"]:
Expand Down Expand Up @@ -294,6 +300,8 @@ def get_can_parser(self, CP):

if CP.flags & (HyundaiFlags.HYBRID | HyundaiFlags.EV):
messages.append(("E_EMS11", 50))
elif CP.flags & HyundaiFlags.FCEV:
messages.append(("ACCELERATOR", 100))
else:
messages += [
("EMS12", 100),
Expand All @@ -302,6 +310,8 @@ def get_can_parser(self, CP):

if CP.flags & (HyundaiFlags.HYBRID | HyundaiFlags.EV):
messages.append(("ELECT_GEAR", 20))
elif CP.flags & HyundaiFlags.FCEV:
messages.append(("EMS20", 100))
elif CP.carFingerprint in CAN_GEARS["use_cluster_gears"]:
pass
elif CP.carFingerprint in CAN_GEARS["use_tcu_gears"]:
Expand Down
6 changes: 5 additions & 1 deletion opendbc/car/hyundai/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from opendbc.car.hyundai.hyundaicanfd import CanBus
from opendbc.car.hyundai.values import HyundaiFlags, CAR, DBC, CANFD_CAR, CAMERA_SCC_CAR, CANFD_RADAR_SCC_CAR, \
CANFD_UNSUPPORTED_LONGITUDINAL_CAR, EV_CAR, HYBRID_CAR, LEGACY_SAFETY_MODE_CAR, \
UNSUPPORTED_LONGITUDINAL_CAR, Buttons
UNSUPPORTED_LONGITUDINAL_CAR, Buttons, FCEV_CAR
from opendbc.car.hyundai.radar_interface import RADAR_START_ADDR
from opendbc.car.interfaces import CarInterfaceBase
from opendbc.car.disable_ecu import disable_ecu
Expand Down Expand Up @@ -58,6 +58,8 @@ def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experime
ret.flags |= HyundaiFlags.HYBRID.value
elif candidate in EV_CAR:
ret.flags |= HyundaiFlags.EV.value
elif candidate in FCEV_CAR:
ret.flags |= HyundaiFlags.FCEV.value
sunnyhaibin marked this conversation as resolved.
Show resolved Hide resolved

# Send LFA message on cars with HDA
if 0x485 in fingerprint[2]:
Expand Down Expand Up @@ -125,6 +127,8 @@ def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experime
ret.safetyConfigs[-1].safetyParam |= Panda.FLAG_HYUNDAI_HYBRID_GAS
elif ret.flags & HyundaiFlags.EV:
ret.safetyConfigs[-1].safetyParam |= Panda.FLAG_HYUNDAI_EV_GAS
elif ret.flags & HyundaiFlags.FCEV:
ret.safetyConfigs[-1].safetyParam |= Panda.FLAG_HYUNDAI_FCEV_GAS

if candidate in (CAR.HYUNDAI_KONA, CAR.HYUNDAI_KONA_EV, CAR.HYUNDAI_KONA_HEV, CAR.HYUNDAI_KONA_EV_2022):
ret.flags |= HyundaiFlags.ALT_LIMITS.value
Expand Down
9 changes: 9 additions & 0 deletions opendbc/car/hyundai/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class HyundaiFlags(IntFlag):

MIN_STEER_32_MPH = 2 ** 23

FCEV = 2 ** 24


class Footnote(Enum):
CANFD = CarFootnote(
Expand Down Expand Up @@ -240,6 +242,11 @@ class CAR(Platforms):
CarSpecs(mass=1425, wheelbase=2.6, steerRatio=13.42, tireStiffnessFactor=0.385),
flags=HyundaiFlags.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,
)
HYUNDAI_SANTA_FE = HyundaiPlatformConfig(
[HyundaiCarDocs("Hyundai Santa Fe 2019-20", "All", video_link="https://youtu.be/bjDR0YjM__s",
car_parts=CarParts.common([CarHarness.hyundai_d]))],
Expand Down Expand Up @@ -745,6 +752,8 @@ def match_fw_to_car_fuzzy(live_fw_versions, vin, offline_fw_versions) -> set[str

EV_CAR = CAR.with_flags(HyundaiFlags.EV)

FCEV_CAR = CAR.with_flags(HyundaiFlags.FCEV)
sunnyhaibin marked this conversation as resolved.
Show resolved Hide resolved

LEGACY_SAFETY_MODE_CAR = CAR.with_flags(HyundaiFlags.LEGACY)

UNSUPPORTED_LONGITUDINAL_CAR = CAR.with_flags(HyundaiFlags.LEGACY) | CAR.with_flags(HyundaiFlags.UNSUPPORTED_LONGITUDINAL)
Expand Down
1 change: 1 addition & 0 deletions opendbc/car/torque_data/override.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ legend = ["LAT_ACCEL_FACTOR", "MAX_LAT_ACCEL_MEASURED", "FRICTION"]
"HYUNDAI_CUSTIN_1ST_GEN" = [2.5, 2.5, 0.1]
"LEXUS_GS_F" = [2.5, 2.5, 0.08]
"HYUNDAI_STARIA_4TH_GEN" = [1.8, 2.0, 0.15]
"HYUNDAI_NEXO_1ST_GEN" = [2.5, 2.5, 0.1]

# Dashcam or fallback configured as ideal car
"MOCK" = [10.0, 10, 0.0]
Expand Down
8 changes: 7 additions & 1 deletion opendbc/dbc/hyundai_kia_generic.dbc
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,9 @@ BO_ 129 EMS_DCT12: 8 EMS
SG_ CF_Ems_Alive2 : 56|4@1+ (1.0,0.0) [0.0|15.0] "" TCU
SG_ CF_Ems_ChkSum2 : 60|4@1+ (1.0,0.0) [0.0|15.0] "" TCU

BO_ 145 ACCELERATOR: 8 XXX
SG_ ACCELERATOR_PEDAL : 48|8@1+ (1,0) [0|255] "" XXX

BO_ 897 MDPS11: 8 MDPS
SG_ CF_Mdps_WLmp : 0|2@1+ (1.0,0.0) [0.0|3.0] "" CLU,CUBIS,EMS,IBOX,SPAS
SG_ CF_Mdps_Flex : 2|3@1+ (1.0,0.0) [0.0|3.0] "" CLU,LDWS_LKAS
Expand Down Expand Up @@ -1429,7 +1432,7 @@ BO_ 1280 ACU14: 1 ACU
SG_ CF_SBR_Ind : 4|2@1+ (1.0,0.0) [0.0|3.0] "" BCM,CLU

BO_ 512 EMS20: 6 EMS
SG_ FCO : 0|16@1+ (0.128,0.0) [0.0|8388.48] "ul" CLU,CUBIS,FPCM,IBOX
SG_ HYDROGEN_GEAR_SHIFTER : 11|3@1+ (1,0) [0|7] "" XXX
SG_ CF_Ems_PumpTPres : 16|8@1+ (3.137254902,0.0) [0.0|800.0] "kPa" FPCM,IBOX
SG_ Split_Stat : 32|1@1+ (1.0,0.0) [0.0|1.0] "" FPCM

Expand Down Expand Up @@ -1648,11 +1651,14 @@ BO_ 1348 Navi_HU: 8 XXX
SG_ SpeedLim_Nav_Cam : 30|1@0+ (1,0) [0|1] "" XXX

CM_ "BO_ E_EMS11: All (plug-in) hybrids use this gas signal: CR_Vcu_AccPedDep_Pos, and all EVs use the Accel_Pedal_Pos signal. See hyundai/values.py for a specific car list";
CM_ 145 "Contains signal with accelerator pedal press. Used by fuel cell hydrogen-powered (FCEV) cars such as the 2021 Hyundai Nexo.";
CM_ 512 "Contains signal with gear shifter. Used by fuel cell hydrogen-powered (FCEV) cars such as the 2021 Hyundai Nexo.";
CM_ SG_ 871 CF_Lvr_IsgState "Idle Stop and Go";
CM_ SG_ 1056 SCCInfoDisplay "Goes to 1 for a second while transitioning from Cruise Control to No Message";
CM_ SG_ 1348 SpeedLim_Nav_Clu "Speed limit displayed on Nav, Cluster and HUD";

VAL_ 274 CUR_GR 1 "D" 2 "D" 3 "D" 4 "D" 5 "D" 6 "D" 7 "D" 8 "D" 14 "R" 0 "P";
VAL_ 512 HYDROGEN_GEAR_SHIFTER 5 "D" 8 "S" 6 "N" 7 "R" 0 "P";
VAL_ 871 CF_Lvr_IsgState 0 "enabled" 1 "activated" 2 "unknown" 3 "disabled";
VAL_ 871 CF_Lvr_Gear 12 "T" 5 "D" 8 "S" 6 "N" 7 "R" 0 "P";
VAL_ 882 Elect_Gear_Shifter 5 "D" 8 "S" 6 "N" 7 "R" 0 "P";
Expand Down
Loading