Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions selfdrive/car/hyundai/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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, \
CANFD_UNSUPPORTED_LONGITUDINAL_CAR, EV_CAR, HYBRID_CAR, LEGACY_SAFETY_MODE_CAR, \
UNSUPPORTED_LONGITUDINAL_CAR, Buttons
UNSUPPORTED_LONGITUDINAL_CAR, PAUSE_RESUME_BTN_CAR, Buttons
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
Expand Down Expand Up @@ -32,6 +32,9 @@ 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)

if candidate in PAUSE_RESUME_BTN_CAR:
ret.flags |= HyundaiFlags.PAUSE_RESUME_BTN.value

if candidate in CANFD_CAR:
# detect if car is hybrid
if 0x105 in fingerprint[CAN.ECAN]:
Expand Down Expand Up @@ -125,6 +128,8 @@ def _get_params(ret, candidate, fingerprint, car_fw, experimental_long, docs):
if candidate in CAMERA_SCC_CAR:
ret.safetyConfigs[0].safetyParam |= Panda.FLAG_HYUNDAI_CAMERA_SCC

if ret.flags & HyundaiFlags.PAUSE_RESUME_BTN:
ret.safetyConfigs[-1].safetyParam |= Panda.FLAG_HYUNDAI_PAUSE_RESUME_BTN
if ret.openpilotLongitudinalControl:
ret.safetyConfigs[-1].safetyParam |= Panda.FLAG_HYUNDAI_LONG
if ret.flags & HyundaiFlags.HYBRID:
Expand Down Expand Up @@ -156,12 +161,24 @@ def _update(self, c):
ret = self.CS.update(self.cp, self.cp_cam)

if self.CS.CP.openpilotLongitudinalControl:
ret.buttonEvents = create_button_events(self.CS.cruise_buttons[-1], self.CS.prev_cruise_buttons, BUTTONS_DICT)
ret.buttonEvents= create_button_events(self.CS.cruise_buttons[-1], self.CS.prev_cruise_buttons, BUTTONS_DICT)

pause_resume_btn = bool(self.CP.flags & HyundaiFlags.PAUSE_RESUME_BTN)
cruise_speed_set = ret.cruiseState.speed > 0

resume_button = self.CS.cruise_buttons[-1] == Buttons.RES_ACCEL
cancel_button = self.CS.cruise_buttons[-1] == Buttons.CANCEL
# main button is considered if it's the first time it is pressed
main_button = self.CS.main_buttons[-1] == 1 and sum(1 for x in self.CS.main_buttons if x != Buttons.NONE) == 1

allow_enable = (
(resume_button and cruise_speed_set and not pause_resume_btn) or
(cancel_button and pause_resume_btn) or # cancel acts like a pause/resume button on newer cars
(main_button and pause_resume_btn)
)
else:
allow_enable = any(btn in ENABLE_BUTTONS for btn in self.CS.cruise_buttons) or any(self.CS.main_buttons)

# On some newer model years, the CANCEL button acts as a pause/resume button based on the PCM state
# To avoid re-engaging when openpilot cancels, check user engagement intention via buttons
# Main button also can trigger an engagement on these cars
allow_enable = any(btn in ENABLE_BUTTONS for btn in self.CS.cruise_buttons) or any(self.CS.main_buttons)
events = self.create_common_events(ret, pcm_enable=self.CS.CP.pcmCruise, allow_enable=allow_enable)

# low speed steer alert hysteresis logic (only for cars with steer cut off above 10 m/s)
Expand All @@ -170,7 +187,7 @@ def _update(self, c):
if ret.vEgo > (self.CP.minSteerSpeed + 4.):
self.low_speed_alert = False
if self.low_speed_alert:
events.add(car.CarEvent.EventName.belowSteerSpeed)
events.add(EventName.belowSteerSpeed)

ret.events = events.to_msg()

Expand Down
3 changes: 3 additions & 0 deletions selfdrive/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

PAUSE_RESUME_BTN = 2 ** 24


class Footnote(Enum):
CANFD = CarFootnote(
Expand Down Expand Up @@ -727,6 +729,7 @@ def match_fw_to_car_fuzzy(live_fw_versions, vin, offline_fw_versions) -> set[str
"use_tcu_gears": CAR.with_flags(HyundaiFlags.TCU_GEARS),
}

PAUSE_RESUME_BTN_CAR = CAR.with_flags(HyundaiFlags.PAUSE_RESUME_BTN)
CANFD_CAR = CAR.with_flags(HyundaiFlags.CANFD)
CANFD_RADAR_SCC_CAR = CAR.with_flags(HyundaiFlags.RADAR_SCC)

Expand Down