Latch mixed HDA II AOL after factory Cruise Main is ready

This commit is contained in:
firestar5683
2026-11-26 12:30:01 -06:00
parent 553f2f8cd0
commit e81f4ff1c7
4 changed files with 73 additions and 7 deletions
+25 -5
View File
@@ -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)
@@ -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
+2 -1
View File
@@ -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:
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "057824d720a04e683d1f871eb6f91ef324a4c2ad77e8dbfca80fe5607e42c9f9", "schema_version": 1}
{"protected_inventory_sha256": "b654c1de92fc640efdfba76cc5ca084188ab88d64fedd25fe6f63533f225d080", "schema_version": 1}