diff --git a/openpilot/starpilot/aol/intent.py b/openpilot/starpilot/aol/intent.py index b2b00b24aa..d3188014a0 100644 --- a/openpilot/starpilot/aol/intent.py +++ b/openpilot/starpilot/aol/intent.py @@ -147,11 +147,14 @@ def disarming_fault(events, CS, *, temporary_ui_process_failure: bool = False, class AolCardIntent: def __init__(self, settings: AolSettings, *, explicit_latch: bool = False, lkas_button_supported: bool = True, - independent_cruise_buttons: bool = False, preserve_unassigned_cancel: bool = False): + independent_cruise_buttons: bool = False, preserve_unassigned_cancel: bool = False, + confirm_main_available: bool = False): self.settings = settings self.explicit_latch = explicit_latch self.independent_cruise_buttons = independent_cruise_buttons self.preserve_unassigned_cancel = preserve_unassigned_cancel + self.confirm_main_available = confirm_main_available + self._pending_main_arm_ns = 0 self.lkas_button_supported = lkas_button_supported self.allowed_latch = False # Observational only: records the exact branch that changed True to False. @@ -278,6 +281,12 @@ class AolCardIntent: self._record_latch_clear('disarming_fault') self.allowed_latch = False self._gesture_neutral_seen = False + if self._pending_main_arm_ns and ( + not 0 < now_ns - self._pending_main_arm_ns <= 100_000_000 or not self.settings.enabled or + self._fault_inhibit or native_rejection_ns or not CS.canValid or CS.canTimeout or CS.accFaulted or + CS.vehicleSensorsInvalid or CS.gearShifter not in (GearShifter.drive, GearShifter.sport, GearShifter.low, GearShifter.brake) or + any(event.pressed for event in CS.buttonEvents)): + self._pending_main_arm_ns = 0 if not CS.canValid or CS.canTimeout: self._record_latch_clear('can_invalid_or_timeout') self.allowed_latch = False @@ -365,10 +374,21 @@ class AolCardIntent: lateral_engaged = not self.pause_lateral and (self.allowed_latch or standard_enabled) if lateral_engaged: self._record_latch_clear('physical_toggle') - self.allowed_latch = not lateral_engaged - self.pause_lateral = lateral_engaged - if not lateral_engaged: - self.physical_arm_ns = now_ns + if (self.confirm_main_available and not lateral_engaged and self._main_held and not self._lkas_held and + not CS.cruiseState.available and now_ns > 0): + if (not native_rejection_ns and not CS.vehicleSensorsInvalid and + CS.gearShifter in (GearShifter.drive, GearShifter.sport, GearShifter.low, GearShifter.brake)): + self._pending_main_arm_ns = now_ns + else: + self.allowed_latch = not lateral_engaged + self.pause_lateral = lateral_engaged + if not lateral_engaged: + self.physical_arm_ns = now_ns + + if self._pending_main_arm_ns and CS.cruiseState.available: + self.physical_arm_ns = self._pending_main_arm_ns + self._pending_main_arm_ns = 0 + self._arm_from_full_engagement(CS, source_ns=now_ns) for event in CS.buttonEvents: button = int(event.type.raw) diff --git a/openpilot/starpilot/aol/tests/test_full_engagement.py b/openpilot/starpilot/aol/tests/test_full_engagement.py index 84158b8703..3fef4f84b9 100644 --- a/openpilot/starpilot/aol/tests/test_full_engagement.py +++ b/openpilot/starpilot/aol/tests/test_full_engagement.py @@ -282,3 +282,48 @@ def test_mixed_hda2_arms_from_engagement_and_preserves_only_unassigned_cancel(en assert not owner.output(cs)[0] owner.update(cs, now_ns=8, fault_active=True) assert not owner.output(cs)[0] + + +@pytest.mark.parametrize('interrupt', [None, 'expired', 'invalid', 'fault', 'cancel', 'neutral']) +def test_mixed_stock_main_waits_for_factory_availability(interrupt): + from opendbc.car.hyundai.values import CAR + from opendbc.car import gen_empty_fingerprint + from opendbc.car.hyundai.interface import CarInterface + from openpilot.starpilot.car.hyundai.aol import create_intent + + observed = gen_empty_fingerprint() + observed[2][0x50] = 16 + cp = CarInterface.get_params(CAR.HYUNDAI_PALISADE_2023, observed, [], False, False, False) + assert cp.safetyConfigs[0].safetyParam == 0x2010 + owner, cs = create_intent(cp, SETTINGS), state() + start = 545_907_606_000 + cs.cruiseState.available = False + cs.gasPressed = True + owner.update(cs, now_ns=start - 10_000_000) + observe(owner, cs, start - 10_000_000, enabled=False, active=False) + cs.buttonEvents = [car.CarState.ButtonEvent(type='mainCruise', pressed=True)] + owner.update(cs, now_ns=start) + assert not owner.allowed_latch + cs.buttonEvents = [] + if interrupt == 'cancel': + cs.buttonEvents = [car.CarState.ButtonEvent(type='cancel', pressed=True)] + if interrupt == 'neutral': + cs.gearShifter = 'neutral' + cs.canValid = interrupt != 'invalid' + owner.update(cs, now_ns=start + 8_485_000, fault_active=interrupt == 'fault') + assert not owner.allowed_latch + cs.canValid, cs.gearShifter, cs.buttonEvents = True, 'drive', [] + cs.cruiseState.available = cs.cruiseState.enabled = True + ready = start + (100_000_001 if interrupt == 'expired' else 25_005_000) + owner.update(cs, now_ns=ready, fault_active=False) + assert owner.output(cs)[0] == (interrupt is None) + if interrupt is None: + observe(owner, cs, ready + 5_000_000) + cs.buttonEvents = [car.CarState.ButtonEvent(type='mainCruise', pressed=False)] + owner.update(cs, now_ns=ready + 33_000_000) + cs.buttonEvents = [] + cs.brakePressed, cs.gasPressed, cs.cruiseState.enabled = True, False, False + owner.update(cs, now_ns=604_026_441_000) + assert owner.output(cs)[0] + owner.update(cs, now_ns=604_036_508_000, native_rejection_ns=604_032_234_000) + assert not owner.allowed_latch diff --git a/openpilot/starpilot/car/hyundai/aol.py b/openpilot/starpilot/car/hyundai/aol.py index 71e35726bb..a5dd2aac2f 100644 --- a/openpilot/starpilot/car/hyundai/aol.py +++ b/openpilot/starpilot/car/hyundai/aol.py @@ -321,9 +321,10 @@ def create_intent(CP, settings): from openpilot.starpilot.aol.intent import AolCardIntent independent_cruise_buttons = independent_cruise_buttons_supported(CP) + mixed_hda2_stock = _mixed_hda2_stock(CP) return AolCardIntent(settings, explicit_latch=policy_for(CP).explicit_latch, independent_cruise_buttons=independent_cruise_buttons, - preserve_unassigned_cancel=_mixed_hda2_stock(CP)) + preserve_unassigned_cancel=mixed_hda2_stock, confirm_main_available=mixed_hda2_stock) def ordinary_axis_request_allowed(CP, CS) -> bool: diff --git a/prebuilt.json b/prebuilt.json index f54d017add..1ca68b2a93 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "057824d720a04e683d1f871eb6f91ef324a4c2ad77e8dbfca80fe5607e42c9f9", "schema_version": 1} +{"protected_inventory_sha256": "b654c1de92fc640efdfba76cc5ca084188ab88d64fedd25fe6f63533f225d080", "schema_version": 1}