Skip to content

Commit

Permalink
Hyundai: use hybrid & ev flags (commaai#31236)
Browse files Browse the repository at this point in the history
* hyundai: use hybrid & ev flags

* Update ref_commit

* todo

* match order
  • Loading branch information
sshane authored Jan 31, 2024
1 parent 9c48e85 commit b406606
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
24 changes: 12 additions & 12 deletions selfdrive/car/hyundai/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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, Buttons, CarControllerParams
from openpilot.selfdrive.car.interfaces import CarStateBase

PREV_BUTTON_SAMPLES = 8
Expand Down Expand Up @@ -36,8 +36,8 @@ def __init__(self, CP):
else: # preferred and elect gear methods use same definition
self.shifter_values = can_define.dv["LVR12"]["CF_Lvr_Gear"]

self.accelerator_msg_canfd = "ACCELERATOR" if CP.carFingerprint in EV_CAR else \
"ACCELERATOR_ALT" if CP.carFingerprint in HYBRID_CAR else \
self.accelerator_msg_canfd = "ACCELERATOR" if CP.flags & HyundaiFlags.EV else \
"ACCELERATOR_ALT" if CP.flags & HyundaiFlags.HYBRID else \
"ACCELERATOR_BRAKE_ALT"
self.cruise_btns_msg_canfd = "CRUISE_BUTTONS_ALT" if CP.flags & HyundaiFlags.CANFD_ALT_BUTTONS else \
"CRUISE_BUTTONS"
Expand Down Expand Up @@ -120,8 +120,8 @@ def update(self, cp, cp_cam):
ret.parkingBrake = cp.vl["TCS13"]["PBRAKE_ACT"] == 1
ret.accFaulted = cp.vl["TCS13"]["ACCEnable"] != 0 # 0 ACC CONTROL ENABLED, 1-3 ACC CONTROL DISABLED

if self.CP.carFingerprint in (HYBRID_CAR | EV_CAR):
if self.CP.carFingerprint in HYBRID_CAR:
if self.CP.flags & (HyundaiFlags.HYBRID | HyundaiFlags.EV):
if 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 @@ -132,7 +132,7 @@ def update(self, cp, cp_cam):

# Gear Selection via Cluster - For those Kia/Hyundai which are not fully discovered, we can use the Cluster Indicator for Gear Selection,
# as this seems to be standard over all cars, but is not the preferred method.
if self.CP.carFingerprint in (HYBRID_CAR | EV_CAR):
if self.CP.flags & (HyundaiFlags.HYBRID | HyundaiFlags.EV):
gear = cp.vl["ELECT_GEAR"]["Elect_Gear_Shifter"]
elif self.CP.carFingerprint in CAN_GEARS["use_cluster_gears"]:
gear = cp.vl["CLU15"]["CF_Clu_Gear"]
Expand Down Expand Up @@ -172,8 +172,8 @@ def update_canfd(self, cp, cp_cam):
self.is_metric = cp.vl["CRUISE_BUTTONS_ALT"]["DISTANCE_UNIT"] != 1
speed_factor = CV.KPH_TO_MS if self.is_metric else CV.MPH_TO_MS

if self.CP.carFingerprint in (EV_CAR | HYBRID_CAR):
offset = 255. if self.CP.carFingerprint in EV_CAR else 1023.
if self.CP.flags & (HyundaiFlags.EV | HyundaiFlags.HYBRID):
offset = 255. if self.CP.flags & HyundaiFlags.EV else 1023.
ret.gas = cp.vl[self.accelerator_msg_canfd]["ACCELERATOR_PEDAL"] / offset
ret.gasPressed = ret.gas > 1e-5
else:
Expand Down Expand Up @@ -233,7 +233,7 @@ def update_canfd(self, cp, cp_cam):
# It limits the vehicle speed, overridable by pressing the accelerator past a certain point.
# The car will brake, but does not respect positive acceleration commands in this mode
# TODO: find this message on ICE & HYBRID cars + cruise control signals (if exists)
if self.CP.carFingerprint in EV_CAR:
if self.CP.flags & HyundaiFlags.EV:
ret.cruiseState.nonAdaptive = cp.vl["MANUAL_SPEED_LIMIT_ASSIST"]["MSLA_ENABLED"] == 1

self.prev_cruise_buttons = self.cruise_buttons[-1]
Expand Down Expand Up @@ -278,15 +278,15 @@ def get_can_parser(self, CP):
if CP.enableBsm:
messages.append(("LCA11", 50))

if CP.carFingerprint in (HYBRID_CAR | EV_CAR):
if CP.flags & (HyundaiFlags.HYBRID | HyundaiFlags.EV):
messages.append(("E_EMS11", 50))
else:
messages += [
("EMS12", 100),
("EMS16", 100),
]

if CP.carFingerprint in (HYBRID_CAR | EV_CAR):
if CP.flags & (HyundaiFlags.HYBRID | HyundaiFlags.EV):
messages.append(("ELECT_GEAR", 20))
elif CP.carFingerprint in CAN_GEARS["use_cluster_gears"]:
pass
Expand Down Expand Up @@ -330,7 +330,7 @@ def get_can_parser_canfd(self, CP):
("DOORS_SEATBELTS", 4),
]

if CP.carFingerprint in EV_CAR:
if CP.flags & HyundaiFlags.EV:
messages += [
("MANUAL_SPEED_LIMIT_ASSIST", 10),
]
Expand Down
10 changes: 8 additions & 2 deletions selfdrive/car/hyundai/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ def _get_params(ret, candidate, fingerprint, car_fw, experimental_long, docs):
hda2 = Ecu.adas in [fw.ecu for fw in car_fw]
CAN = CanBus(None, hda2, fingerprint)

# TODO: detect EV and hybrid
if candidate in HYBRID_CAR:
ret.flags |= HyundaiFlags.HYBRID.value
elif candidate in EV_CAR:
ret.flags |= HyundaiFlags.EV.value

if candidate in CANFD_CAR:
# detect HDA2 with ADAS Driving ECU
if hda2:
Expand Down Expand Up @@ -313,9 +319,9 @@ def _get_params(ret, candidate, fingerprint, car_fw, experimental_long, docs):
ret.safetyConfigs[-1].safetyParam |= Panda.FLAG_HYUNDAI_CAMERA_SCC
if ret.openpilotLongitudinalControl:
ret.safetyConfigs[-1].safetyParam |= Panda.FLAG_HYUNDAI_LONG
if candidate in HYBRID_CAR:
if ret.flags & HyundaiFlags.HYBRID:
ret.safetyConfigs[-1].safetyParam |= Panda.FLAG_HYUNDAI_HYBRID_GAS
elif candidate in EV_CAR:
elif ret.flags & HyundaiFlags.EV:
ret.safetyConfigs[-1].safetyParam |= Panda.FLAG_HYUNDAI_EV_GAS

if candidate in (CAR.KONA, CAR.KONA_EV, CAR.KONA_HEV, CAR.KONA_EV_2022):
Expand Down
2 changes: 2 additions & 0 deletions selfdrive/car/hyundai/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class HyundaiFlags(IntFlag):
SEND_LFA = 128
USE_FCA = 256
CANFD_HDA2_ALT_STEERING = 512
HYBRID = 1024
EV = 2048


class CAR(StrEnum):
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/test/process_replay/ref_commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6a61df84e67e3177f0ba73865a1bb239385c0ade
eaab6bd55c5eab33fc9a0d8de8289b912e923887

0 comments on commit b406606

Please sign in to comment.