From c486690f464ffabebc4e8fcd12013b7253e51d99 Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Tue, 14 Apr 2026 11:38:12 -0500 Subject: [PATCH] Hyundai: scope AOL set-latch to full OP --- opendbc_repo/opendbc/car/hyundai/values.py | 1 + opendbc_repo/opendbc/car/interfaces.py | 2 ++ .../opendbc/safety/modes/hyundai_common.h | 9 +++++++++ opendbc_repo/opendbc/safety/safety.h | 2 +- .../opendbc/safety/tests/hyundai_common.py | 20 +++++++++++++++++++ .../opendbc/safety/tests/test_hyundai.py | 13 ++++++++++-- .../safety/tests/test_hyundai_canfd.py | 16 +++++++++++++-- 7 files changed, 58 insertions(+), 5 deletions(-) diff --git a/opendbc_repo/opendbc/car/hyundai/values.py b/opendbc_repo/opendbc/car/hyundai/values.py index 6e5a26577..d5ffc4705 100644 --- a/opendbc_repo/opendbc/car/hyundai/values.py +++ b/opendbc_repo/opendbc/car/hyundai/values.py @@ -70,6 +70,7 @@ class HyundaiSafetyFlags(IntFlag): class HyundaiStarPilotSafetyFlags(IntFlag): HAS_LDA_BUTTON = 1024 + AOL_LKAS_ON_ENGAGE = 2048 class HyundaiFlags(IntFlag): diff --git a/opendbc_repo/opendbc/car/interfaces.py b/opendbc_repo/opendbc/car/interfaces.py index 97f9c19d4..d7babe170 100644 --- a/opendbc_repo/opendbc/car/interfaces.py +++ b/opendbc_repo/opendbc/car/interfaces.py @@ -218,6 +218,8 @@ class CarInterfaceBase(ABC): if CP.flags & HyundaiFlags.HAS_LDA_BUTTON: fp_ret.safetyConfigs[-1].safetyParam |= HyundaiStarPilotSafetyFlags.HAS_LDA_BUTTON.value + if CP.openpilotLongitudinalControl and starpilot_toggles.always_on_lateral_lkas: + fp_ret.safetyConfigs[-1].safetyParam |= HyundaiStarPilotSafetyFlags.AOL_LKAS_ON_ENGAGE.value elif platform in TOYOTA: fp_ret.canUsePedal = not CP.autoResumeSng diff --git a/opendbc_repo/opendbc/safety/modes/hyundai_common.h b/opendbc_repo/opendbc/safety/modes/hyundai_common.h index e81fd56c7..d0165308a 100644 --- a/opendbc_repo/opendbc/safety/modes/hyundai_common.h +++ b/opendbc_repo/opendbc/safety/modes/hyundai_common.h @@ -45,6 +45,9 @@ bool hyundai_alt_limits_2 = false; extern bool hyundai_has_lda_button; bool hyundai_has_lda_button = false; +extern bool hyundai_aol_lkas_on_engage; +bool hyundai_aol_lkas_on_engage = false; + static uint8_t hyundai_last_button_interaction; // button messages since the user pressed an enable button void hyundai_common_init(uint16_t param) { @@ -57,6 +60,7 @@ void hyundai_common_init(uint16_t param) { const uint16_t HYUNDAI_PARAM_ALT_LIMITS_2 = 512; const int HYUNDAI_PARAM_HAS_LDA_BUTTON = 1024; + const uint16_t HYUNDAI_PARAM_AOL_LKAS_ON_ENGAGE = 2048; hyundai_ev_gas_signal = GET_FLAG(param, HYUNDAI_PARAM_EV_GAS); hyundai_hybrid_gas_signal = !hyundai_ev_gas_signal && GET_FLAG(param, HYUNDAI_PARAM_HYBRID_GAS); @@ -67,6 +71,7 @@ void hyundai_common_init(uint16_t param) { hyundai_alt_limits_2 = GET_FLAG(param, HYUNDAI_PARAM_ALT_LIMITS_2); hyundai_has_lda_button = GET_FLAG(param, HYUNDAI_PARAM_HAS_LDA_BUTTON); + hyundai_aol_lkas_on_engage = GET_FLAG(param, HYUNDAI_PARAM_AOL_LKAS_ON_ENGAGE); hyundai_last_button_interaction = HYUNDAI_PREV_BUTTON_SAMPLES; @@ -108,6 +113,10 @@ void hyundai_common_cruise_buttons_check(const int cruise_button, const bool mai bool res = (cruise_button != HYUNDAI_BTN_RESUME) && (cruise_button_prev == HYUNDAI_BTN_RESUME); if (set || res) { controls_allowed = true; + + if (hyundai_aol_lkas_on_engage && ((alternative_experience & ALT_EXP_ALWAYS_ON_LATERAL) != 0)) { + lkas_on = true; + } } // exit controls on cancel press diff --git a/opendbc_repo/opendbc/safety/safety.h b/opendbc_repo/opendbc/safety/safety.h index ecfd58b49..2db13911b 100644 --- a/opendbc_repo/opendbc/safety/safety.h +++ b/opendbc_repo/opendbc/safety/safety.h @@ -374,7 +374,7 @@ static void generic_rx_checks(void) { } steering_disengage_prev = steering_disengage; - aol_allowed = (alternative_experience & ALT_EXP_ALWAYS_ON_LATERAL) != 0U; + aol_allowed = (acc_main_on || lkas_on) && (alternative_experience & ALT_EXP_ALWAYS_ON_LATERAL); } static void stock_ecu_check(bool stock_ecu_detected) { diff --git a/opendbc_repo/opendbc/safety/tests/hyundai_common.py b/opendbc_repo/opendbc/safety/tests/hyundai_common.py index caa55cbe8..b0ec19d4f 100644 --- a/opendbc_repo/opendbc/safety/tests/hyundai_common.py +++ b/opendbc_repo/opendbc/safety/tests/hyundai_common.py @@ -1,5 +1,6 @@ import unittest +from opendbc.safety import ALTERNATIVE_EXPERIENCE import opendbc.safety.tests.common as common from opendbc.safety.tests.libsafety import libsafety_py from opendbc.safety.tests.common import make_msg @@ -171,3 +172,22 @@ class HyundaiLongitudinalBase(common.LongitudinalAccelSafetyTest): self.assertFalse(self.safety.get_relay_malfunction()) self._rx(make_msg(bus, addr, 8)) self.assertTrue(self.safety.get_relay_malfunction()) + + +class HyundaiAolLkasOnEngageBase: + def test_aol_lkas_auto_enables_on_set_engagement(self): + torque_cmd = self.MAX_RATE_UP + + self.safety.set_alternative_experience(ALTERNATIVE_EXPERIENCE.ALWAYS_ON_LATERAL) + self.safety.set_controls_allowed(False) + + self._set_prev_torque(0) + self.assertFalse(self._tx(self._torque_cmd_msg(torque_cmd))) + + self._rx(self._button_msg(Buttons.SET)) + self._rx(self._button_msg(Buttons.NONE)) + self.assertTrue(self.safety.get_controls_allowed()) + + self.safety.set_controls_allowed(False) + self._set_prev_torque(0) + self.assertTrue(self._tx(self._torque_cmd_msg(torque_cmd))) diff --git a/opendbc_repo/opendbc/safety/tests/test_hyundai.py b/opendbc_repo/opendbc/safety/tests/test_hyundai.py index fa08faede..a913db3f5 100755 --- a/opendbc_repo/opendbc/safety/tests/test_hyundai.py +++ b/opendbc_repo/opendbc/safety/tests/test_hyundai.py @@ -2,12 +2,12 @@ import random import unittest -from opendbc.car.hyundai.values import HyundaiSafetyFlags +from opendbc.car.hyundai.values import HyundaiSafetyFlags, HyundaiStarPilotSafetyFlags from opendbc.car.structs import CarParams from opendbc.safety.tests.libsafety import libsafety_py import opendbc.safety.tests.common as common from opendbc.safety.tests.common import CANPackerSafety -from opendbc.safety.tests.hyundai_common import HyundaiButtonBase, HyundaiLongitudinalBase +from opendbc.safety.tests.hyundai_common import HyundaiAolLkasOnEngageBase, HyundaiButtonBase, HyundaiLongitudinalBase # 4 bit checkusm used in some hyundai messages @@ -279,5 +279,14 @@ class TestHyundaiSafetyFCEVLong(TestHyundaiLongitudinalSafety, TestHyundaiSafety self.safety.init_tests() +class TestHyundaiLongitudinalAolLkasOnEngageSafety(HyundaiAolLkasOnEngageBase, TestHyundaiLongitudinalSafety): + def setUp(self): + self.packer = CANPackerSafety("hyundai_kia_generic") + self.safety = libsafety_py.libsafety + self.safety.set_safety_hooks(CarParams.SafetyModel.hyundai, + HyundaiSafetyFlags.LONG | HyundaiStarPilotSafetyFlags.AOL_LKAS_ON_ENGAGE) + self.safety.init_tests() + + if __name__ == "__main__": unittest.main() diff --git a/opendbc_repo/opendbc/safety/tests/test_hyundai_canfd.py b/opendbc_repo/opendbc/safety/tests/test_hyundai_canfd.py index 5c4cbae11..8464e6ff8 100755 --- a/opendbc_repo/opendbc/safety/tests/test_hyundai_canfd.py +++ b/opendbc_repo/opendbc/safety/tests/test_hyundai_canfd.py @@ -2,12 +2,12 @@ from parameterized import parameterized_class import unittest -from opendbc.car.hyundai.values import HyundaiSafetyFlags +from opendbc.car.hyundai.values import HyundaiSafetyFlags, HyundaiStarPilotSafetyFlags from opendbc.car.structs import CarParams from opendbc.safety.tests.libsafety import libsafety_py import opendbc.safety.tests.common as common from opendbc.safety.tests.common import CANPackerSafety -from opendbc.safety.tests.hyundai_common import HyundaiButtonBase, HyundaiLongitudinalBase +from opendbc.safety.tests.hyundai_common import HyundaiAolLkasOnEngageBase, HyundaiButtonBase, HyundaiLongitudinalBase # All combinations of radar/camera-SCC and gas/hybrid/EV cars ALL_GAS_EV_HYBRID_COMBOS = [ @@ -326,6 +326,18 @@ class TestHyundaiCanfdLFASteeringLongAltButtons(TestHyundaiCanfdLFASteeringLongB pass +class TestHyundaiCanfdLKASteeringLongAolLkasOnEngageEV(HyundaiAolLkasOnEngageBase, TestHyundaiCanfdLKASteeringLongEV): + def setUp(self): + self.packer = CANPackerSafety("hyundai_canfd_generated") + self.safety = libsafety_py.libsafety + self.safety.set_safety_hooks(CarParams.SafetyModel.hyundaiCanfd, + HyundaiSafetyFlags.CANFD_LKA_STEERING | + HyundaiSafetyFlags.LONG | + HyundaiSafetyFlags.EV_GAS | + HyundaiStarPilotSafetyFlags.AOL_LKAS_ON_ENGAGE) + self.safety.init_tests() + + if __name__ == "__main__": unittest.main()