mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-28 01:52:06 +08:00
Hyundai: use hybrid & ev flags (#31236)
* hyundai: use hybrid & ev flags * Update ref_commit * todo * match order old-commit-hash: b40660692b7f713cde1265d73d4a271a24e85221
This commit is contained in:
@@ -8,7 +8,7 @@ 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, Buttons, CarControllerParams
|
||||
from openpilot.selfdrive.car.interfaces import CarStateBase
|
||||
|
||||
PREV_BUTTON_SAMPLES = 8
|
||||
@@ -36,8 +36,8 @@ class CarState(CarStateBase):
|
||||
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"
|
||||
@@ -120,8 +120,8 @@ class CarState(CarStateBase):
|
||||
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.
|
||||
@@ -132,7 +132,7 @@ class CarState(CarStateBase):
|
||||
|
||||
# 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"]
|
||||
@@ -172,8 +172,8 @@ class CarState(CarStateBase):
|
||||
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:
|
||||
@@ -233,7 +233,7 @@ class CarState(CarStateBase):
|
||||
# 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]
|
||||
@@ -278,7 +278,7 @@ class CarState(CarStateBase):
|
||||
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 += [
|
||||
@@ -286,7 +286,7 @@ class CarState(CarStateBase):
|
||||
("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
|
||||
@@ -330,7 +330,7 @@ class CarState(CarStateBase):
|
||||
("DOORS_SEATBELTS", 4),
|
||||
]
|
||||
|
||||
if CP.carFingerprint in EV_CAR:
|
||||
if CP.flags & HyundaiFlags.EV:
|
||||
messages += [
|
||||
("MANUAL_SPEED_LIMIT_ASSIST", 10),
|
||||
]
|
||||
|
||||
@@ -45,6 +45,12 @@ class CarInterface(CarInterfaceBase):
|
||||
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:
|
||||
@@ -313,9 +319,9 @@ class CarInterface(CarInterfaceBase):
|
||||
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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -1 +1 @@
|
||||
6a61df84e67e3177f0ba73865a1bb239385c0ade
|
||||
eaab6bd55c5eab33fc9a0d8de8289b912e923887
|
||||
|
||||
Reference in New Issue
Block a user