From 768a7c476e7fff184cb2c67176a936a6be7c7fa0 Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Fri, 13 Nov 2026 13:46:53 -0600 Subject: [PATCH] Restore MQB MAIN arming and lateral-only Cancel --- .../safety/modes/volkswagen_stock_aol.h | 23 +++-- .../tests/test_volkswagen_direct_aol.py | 3 +- .../safety/tests/test_volkswagen_stock_aol.py | 5 +- openpilot/selfdrive/selfdrived/selfdrived.py | 7 +- .../aol/tests/test_mqb_actual_callers.py | 49 +++++++++-- .../aol/tests/test_volkswagen_main_boot.py | 85 +++++++++++++++++++ openpilot/starpilot/aol/transport_pause.py | 8 +- openpilot/starpilot/car/volkswagen/aol.py | 44 +++++++++- prebuilt.json | 2 +- 9 files changed, 201 insertions(+), 25 deletions(-) mode change 100755 => 100644 openpilot/selfdrive/selfdrived/selfdrived.py diff --git a/opendbc_repo/opendbc/safety/modes/volkswagen_stock_aol.h b/opendbc_repo/opendbc/safety/modes/volkswagen_stock_aol.h index 8672cde238..614158a104 100644 --- a/opendbc_repo/opendbc/safety/modes/volkswagen_stock_aol.h +++ b/opendbc_repo/opendbc/safety/modes/volkswagen_stock_aol.h @@ -85,7 +85,7 @@ static uint8_t vw_aol_request_mask(void) { (safety_get_ts_elapsed(microsecond_timer_get(), aol_host_request_ts) > AOL_HOST_REQUEST_TIMEOUT_US); const uint32_t grant_age = safety_get_ts_elapsed(microsecond_timer_get(), vw_aol_grant_ts); const bool pending_expired = vw_aol_pending && (grant_age > AOL_HOST_REQUEST_TIMEOUT_US); - const bool vw_controls_heartbeat_lost = !heartbeat_engaged && (!vw_aol_longitudinal || vw_aol_session); + const bool vw_controls_heartbeat_lost = !heartbeat_engaged && (!vw_aol_longitudinal || vw_aol_session) && !vw_aol_main_neutral; uint8_t request = 0U; if (!vw_aol_enabled || relay_malfunction || expired || safety_rx_checks_invalid || vw_controls_heartbeat_lost || pending_expired || !aol_rx_healthy() || !vw_aol_current()) { @@ -178,15 +178,16 @@ static void vw_aol_rx(const CANPacket_t *msg) { vw_aol_cruise_engaged = engaged; vw_aol_seen |= 1U; vw_aol_main_ts = microsecond_timer_get(); - if ((!heartbeat_engaged && (!vw_aol_longitudinal || vw_aol_session)) || - !aol_rx_healthy() || !vw_aol_current() || safety_rx_checks_invalid) { + if (!aol_rx_healthy() || !vw_aol_current() || safety_rx_checks_invalid) { vw_aol_clear(); } else if (!acc_main_on) { vw_aol_initial_main = false; vw_aol_clear(); - // Only a valid OFF observation may prepare a subsequent main-ON edge. + // A fresh physical OFF may wait for the host heartbeat; all output remains denied. vw_aol_main_neutral = ((msg->data[3] & 7U) < 2U); - } else if (heartbeat_engaged && vw_aol_initial_main && vw_aol_gear_drive && vw_aol_eps_ready && !brake_pressed) { + } else if (!heartbeat_engaged && (!vw_aol_longitudinal || vw_aol_session) && !vw_aol_main_neutral) { + vw_aol_clear(); + } else if (heartbeat_engaged && vehicle_moving && vw_aol_initial_main && vw_aol_gear_drive && vw_aol_eps_ready && !brake_pressed) { // Fresh complete physical MAIN-on startup grants LAT only. It never restores a cleared drive session. vw_aol_initial_main = false; vw_aol_token = true; @@ -194,15 +195,21 @@ static void vw_aol_rx(const CANPacket_t *msg) { // A fresh stock engagement supplies native arm; host still requires its own current intent. vw_aol_token = true; vw_aol_main_neutral = false; - } else if (vw_aol_main_neutral) { + } else if (vw_aol_main_neutral && heartbeat_engaged && vehicle_moving && vw_aol_gear_drive && vw_aol_eps_ready && !brake_pressed) { vw_aol_token = true; vw_aol_main_neutral = false; } else { } } else if (msg_matches(msg, MSG_GRA_ACC_01, 0U, 8U)) { if (GET_BIT(msg, 13U)) { - vw_aol_initial_main = false; - vw_aol_clear(); + // CANCEL preserves an acknowledged lateral session, never a pending SET/RES grant. + if (!vw_aol_session || vw_aol_pending) { + vw_aol_token = false; + vw_aol_initial_main = false; + } + vw_aol_long_armed = false; + vw_aol_buttons = 0U; + vw_aol_pending = false; } else if (vw_aol_longitudinal) { const bool healthy = (heartbeat_engaged || !vw_aol_session) && !relay_malfunction && aol_rx_healthy() && vw_aol_current() && !safety_rx_checks_invalid; const uint8_t buttons = (GET_BIT(msg, 16U) ? 1U : 0U) | (GET_BIT(msg, 19U) ? 2U : 0U); diff --git a/opendbc_repo/opendbc/safety/tests/test_volkswagen_direct_aol.py b/opendbc_repo/opendbc/safety/tests/test_volkswagen_direct_aol.py index fe29b3578d..45da984d14 100644 --- a/opendbc_repo/opendbc/safety/tests/test_volkswagen_direct_aol.py +++ b/opendbc_repo/opendbc/safety/tests/test_volkswagen_direct_aol.py @@ -59,8 +59,9 @@ def test_direct_reverse_temporary_brake_and_permanent_semantics(owner): owner.feed(engaged=True) assert owner.safety.aol_get_permission_mask() == 1 owner.feed(cancel=True) + assert not owner.safety.get_controls_allowed() owner.feed() - assert owner.safety.aol_get_permission_mask() == 0 + assert owner.safety.aol_get_permission_mask() == 1 @pytest.mark.parametrize('gear,drive', ((0, False), (1, False), (2, False), (3, False), (4, False), diff --git a/opendbc_repo/opendbc/safety/tests/test_volkswagen_stock_aol.py b/opendbc_repo/opendbc/safety/tests/test_volkswagen_stock_aol.py index a1c885d084..0529aa8beb 100644 --- a/opendbc_repo/opendbc/safety/tests/test_volkswagen_stock_aol.py +++ b/opendbc_repo/opendbc/safety/tests/test_volkswagen_stock_aol.py @@ -77,9 +77,10 @@ class TestVolkswagenStockAol(unittest.TestCase): assert self.safety.aol_get_permission_mask() == 0 assert self.safety.safety_fwd_hook(2, 0x126) == 0 self.feed(cancel=True) - assert self.safety.aol_get_permission_mask() == 0 + assert not self.safety.get_controls_allowed() + assert self.safety.aol_get_permission_mask() == 1 self.feed() - assert self.safety.aol_get_permission_mask() == 0 + assert self.safety.aol_get_permission_mask() == 1 def test_temporary_brake_and_fault_recovery_preserves_only_arm(self): for word in (8, 24): diff --git a/openpilot/selfdrive/selfdrived/selfdrived.py b/openpilot/selfdrive/selfdrived/selfdrived.py old mode 100755 new mode 100644 index e2ed988b0f..5bca21debf --- a/openpilot/selfdrive/selfdrived/selfdrived.py +++ b/openpilot/selfdrive/selfdrived/selfdrived.py @@ -1802,7 +1802,8 @@ class SelfdriveD: from openpilot.starpilot.car.ford.aol import physical_cancel_lateral_allowed as ford_cancel_lateral_allowed from openpilot.starpilot.car.subaru.aol import sng_standstill_lateral_inhibit from openpilot.starpilot.car.volkswagen.aol import (lateral_output_inhibited as volkswagen_lateral_output_inhibited, - below_engage_lateral_allowed as volkswagen_below_engage_lateral_allowed) + below_engage_lateral_allowed as volkswagen_below_engage_lateral_allowed, + physical_cancel_lateral_allowed as volkswagen_cancel_lateral_allowed) from openpilot.starpilot.aol.dm import lateral_event_context from openpilot.starpilot.car.toyota.legacy_lateral import below_engage_lateral_allowed as toyota_below_engage_lateral_allowed from openpilot.starpilot.car.hyundai.aol import raw_longitudinal_withdrawal @@ -1837,6 +1838,10 @@ class SelfdriveD: source_ns=getattr(self, 'aol_car_state_log_ns', 0), now_ns=now_ns, axis_session_id=getattr(self, 'aol_session_id', '')) or mazda_cancel_lateral_allowed(self.CP, CS, intent, native, + settings=self.aol_settings, previous=getattr(self, 'aol_axis_decision', None), + source_ns=getattr(self, 'aol_car_state_log_ns', 0), now_ns=now_ns, + axis_session_id=getattr(self, 'aol_session_id', '')) or + volkswagen_cancel_lateral_allowed(self.CP, CS, intent, native, settings=self.aol_settings, previous=getattr(self, 'aol_axis_decision', None), source_ns=getattr(self, 'aol_car_state_log_ns', 0), now_ns=now_ns, axis_session_id=getattr(self, 'aol_session_id', '')), diff --git a/openpilot/starpilot/aol/tests/test_mqb_actual_callers.py b/openpilot/starpilot/aol/tests/test_mqb_actual_callers.py index ec8e1e8324..48ac25a142 100644 --- a/openpilot/starpilot/aol/tests/test_mqb_actual_callers.py +++ b/openpilot/starpilot/aol/tests/test_mqb_actual_callers.py @@ -31,7 +31,8 @@ from openpilot.starpilot.aol.tests.stock_lateral_test_helpers import authority_c @pytest.mark.parametrize('fixed', (False,)) def test_mqb_full_engagement_brake_reverse_drive_actual_callers(gearbox, alpha, offset, fixed, engage_on_set, stop_and_resume=False, candidate=CAR.VOLKSWAGEN_GOLF_MK7, - brake_held_engagement=False, creep_start=False, early_brake=False): + brake_held_engagement=False, creep_start=False, early_brake=False, + parked_boot=False, cruise_cancel=False, main_cycle=False): with ExitStack() as cleanup: cleanup.enter_context(OpenpilotPrefix()) cleanup.enter_context(mock.patch.dict('os.environ', {'SIMULATION': '0', 'AOL_REPLAY_RUNTIME': '1'})) @@ -78,6 +79,7 @@ def test_mqb_full_engagement_brake_reverse_drive_actual_callers(gearbox, alpha, sd, controls, step = case._authority_callers(False, cp=cp, genuine_events=True) card = card_module.Car(CI=CarInterface(card_cp), RI=CarInterface.RadarInterface(card_cp)) assert card.CP.to_dict() == sd.CP.to_dict() + sd.aol_settings = card.aol_settings if offset: original_update = sd.sm.update_msgs def measured_pandas(timestamp, messages): @@ -147,7 +149,7 @@ def test_mqb_full_engagement_brake_reverse_drive_actual_callers(gearbox, alpha, native.init_tests() native.set_alternative_experience(32) native.set_safety_hooks(15, (24 if gearbox == 'manual' else 40 if gearbox == 'direct' else 8) | int(alpha)) - native.set_aol_test_heartbeat(True) + native.set_aol_test_heartbeat(not parked_boot) card.CI.update([]) dbc = ParsedDBC('vw_mqb') packer = CANPacker('vw_mqb') @@ -156,7 +158,7 @@ def test_mqb_full_engagement_brake_reverse_drive_actual_callers(gearbox, alpha, for tick in range(120): now = 10_000_000_000 + tick * 10_000_000 native.set_timer(1_000_000 + tick * 10_000) - if creep_start and tick >= 12: + if parked_boot or main_cycle or creep_start and tick >= 12: native.set_aol_test_heartbeat(bool(card.aol_card_intent.allowed_latch or request)) if quiet is not None: quiet.set_timer(1_000_000 + tick * 10_000) @@ -167,9 +169,9 @@ def test_mqb_full_engagement_brake_reverse_drive_actual_callers(gearbox, alpha, brake = (60 if early_brake else 65) <= tick < 75 or (brake_held_engagement and tick < 29) reverse = 85 <= tick < 95 - ordinary = engage_on_set and 21 <= tick < 65 + ordinary = engage_on_set and 21 <= tick < (55 if cruise_cancel else 65) overrides = { - 'TSK_06': {'TSK_Status': 3 if ordinary and not alpha else 2}, + 'TSK_06': {'TSK_Status': 0 if main_cycle and 45 <= tick < 50 else 3 if ordinary and not alpha else 2}, 'LH_EPS_03': {'EPS_HCA_Status': 3, 'EPS_Lenkmoment': 100 if early_brake and 52 <= tick <= 61 else 0}, 'Motor_20': {'MO_Fahrpedalrohwert_01': 0}, 'Motor_14': {'MO_Fahrer_bremst': int(brake), 'MO_Kuppl_schalter': 0}, @@ -179,9 +181,11 @@ def test_mqb_full_engagement_brake_reverse_drive_actual_callers(gearbox, alpha, 'Motor_EV_01': {'MO_Waehlpos': 3 if reverse else 5}, 'ESP_19': dict.fromkeys(('ESP_VL_Radgeschw_02', 'ESP_VR_Radgeschw_02', 'ESP_HL_Radgeschw_02', 'ESP_HR_Radgeschw_02'), (72 if tick < 12 else 0 if tick < 20 else 1 if tick < 24 else 2 if tick < 46 else 72) if creep_start else - 0 if (stop_and_resume and 45 <= tick < 56) or (brake_held_engagement and tick < 30) else 72), + 0 if (stop_and_resume and 45 <= tick < 56) or (brake_held_engagement and tick < 30) else + 0 if parked_boot and tick < 30 else 72), 'Airbag_02': {'AB_Gurtschloss_FA': 0 if 105 <= tick < 111 else 3}, - 'GRA_ACC_01': {'GRA_Hauptschalter': 1, 'GRA_Tip_Setzen': int(engage_on_set and (tick in (20, 50) if creep_start else tick == 20))}, + 'GRA_ACC_01': {'GRA_Abbrechen': int(cruise_cancel and tick == 55), 'GRA_Hauptschalter': int(not main_cycle or not 45 <= tick < 50), + 'GRA_Tip_Setzen': int(engage_on_set and (tick in (20, 50) if creep_start else tick == 20))}, 'ACC_02': {'ACC_Gesetzte_Zeitluecke': 1}, } incoming = [] @@ -218,6 +222,8 @@ def test_mqb_full_engagement_brake_reverse_drive_actual_callers(gearbox, alpha, card.state_publish(state, radar) if tick >= 15: assert state.canValid and not state.canTimeout + if parked_boot and 15 <= tick < 30: + assert not card.aol_card_intent.allowed_latch, 'VW_PARKED_START_CONSUMED_MAIN_ARM' intent = card.pm.messages['aolIntentWire'].as_builder() axis, selfdrive, command = step(tick, observed_state=state, intent_message=intent, gas=state.gasPressed, steering=state.steeringPressed, brake=state.brakePressed, @@ -235,6 +241,17 @@ def test_mqb_full_engagement_brake_reverse_drive_actual_callers(gearbox, alpha, assert not command.longActive and not (permission & 2) if brake_held_engagement and 38 <= tick < 45: assert command.longActive and axis.longitudinalActive and permission & 2, "VW_BRAKE_RELEASE_NO_LONG" + if parked_boot and tick < 30: + assert not command.latActive and not command.longActive + assert log.OnroadEvent.EventName.controlsMismatch not in sd.events.names + if cruise_cancel and 58 <= tick < 65: + assert card.aol_card_intent.allowed_latch, 'VW_CANCEL_CLEARED_LATERAL_INTENT' + assert command.latActive and permission & 1, 'VW_CANCEL_WITHDREW_LATERAL_PERMISSION' + assert not command.longActive and not permission & 2, 'VW_CANCEL_RESTORED_LONG' + if main_cycle and 62 <= tick < 65: + assert card.aol_card_intent.allowed_latch + assert command.latActive, 'VW_MAIN_ON_REQUIRES_SET_AFTER_HEARTBEAT_WITHDRAWAL' + assert not command.longActive if tick >= 112: assert command.driverMonitoringEscalation if stop_and_resume and 45 <= tick < 56: @@ -348,3 +365,21 @@ def test_native_brake_precedes_parsed_pedal_during_driver_steering(gearbox): test_mqb_full_engagement_brake_reverse_drive_actual_callers( gearbox, True, 0, False, True, early_brake=True, candidate=CAR.SEAT_ATECA_MK1 if gearbox == 'automatic' else CAR.VOLKSWAGEN_GOLF_MK7) + + +@pytest.mark.parametrize('gearbox', ('automatic', 'manual', 'direct')) +@pytest.mark.parametrize('alpha', (False, True)) +def test_mqb_parked_main_start_waits_for_steering_speed_without_set(gearbox, alpha): + test_mqb_full_engagement_brake_reverse_drive_actual_callers(gearbox, alpha, 0, False, False, parked_boot=True) + + +@pytest.mark.parametrize('gearbox', ('automatic', 'manual', 'direct')) +@pytest.mark.parametrize('alpha', (False, True)) +def test_mqb_default_cancel_withdraws_only_cruise_actual_callers(gearbox, alpha): + test_mqb_full_engagement_brake_reverse_drive_actual_callers(gearbox, alpha, 0, False, True, cruise_cancel=True) + + +@pytest.mark.parametrize('gearbox', ('automatic', 'manual', 'direct')) +@pytest.mark.parametrize('alpha', (False, True)) +def test_mqb_main_cycle_without_set_recovers_only_lateral_actual_callers(gearbox, alpha): + test_mqb_full_engagement_brake_reverse_drive_actual_callers(gearbox, alpha, 0, False, False, main_cycle=True) diff --git a/openpilot/starpilot/aol/tests/test_volkswagen_main_boot.py b/openpilot/starpilot/aol/tests/test_volkswagen_main_boot.py index 89a76d7e0b..3fe15703db 100644 --- a/openpilot/starpilot/aol/tests/test_volkswagen_main_boot.py +++ b/openpilot/starpilot/aol/tests/test_volkswagen_main_boot.py @@ -98,3 +98,88 @@ def test_missing_initial_can_fields_cannot_consume_main_boot_request(main_action owner.update(state, now_ns=1_010_000_000, fault_active=False) assert owner.allowed_latch == (main_action == 0) assert not owner.main_startup_pending + + +@pytest.mark.parametrize('alpha', (False, True)) +def test_mqb_parked_delayed_start_keeps_main_request_unconsumed(alpha): + from openpilot.selfdrive.selfdrived.selfdrived import SelfdriveD + from openpilot.starpilot.aol.runtime import AxisDecision + from openpilot.selfdrive.selfdrived.events import Events + from types import SimpleNamespace + from openpilot.selfdrive.selfdrived.state import StateMachine + from unittest.mock import patch + from openpilot.cereal import log + fp = gen_empty_fingerprint() + fp[1][0xFD] = 8 + cp = CarInterface.get_params(CAR.VOLKSWAGEN_GOLF_MK7, fp, [], alpha, False, False) + # The regular factory owner marks CP before creating Card intent. + from openpilot.starpilot.car.volkswagen.aol import policy_for + policy = policy_for(cp) + cp.safetyConfigs[-1].safetyParam |= policy.safety_param_addition + cp.alternativeExperience |= policy.alternative_experience_addition + owner = VolkswagenStockCardIntent(cp, AolSettings(True, 0., 0, 0, (0, 0, 0), (0, 0, 0))) + cs = structs.CarState(canValid=True, standstill=True, gearShifter=structs.CarState.GearShifter.drive) + cs.cruiseState.available = True + owner.update(cs, now_ns=1_000_000_000, fault_active=False) + assert not owner.allowed_latch, 'VW_PARKED_START_CONSUMED_MAIN_ARM' + assert owner.main_startup_pending + # A delayed host source expires normally; no accepted actuation exists to lose. + sd = SelfdriveD.__new__(SelfdriveD) + sd.CP = cp + sd.aol_replay = sd.axis_transport_required = True + sd.aol_car_state_log_ns = 1_000_000_000 + sd.conditional_car_state_valid = True + sd.aol_axis_decision = AxisDecision() + sd.aol_last_intent = SimpleNamespace(allowedLatch=owner.allowed_latch, carStateLogMonoTime=1_000_000_000) + sd.aol_publication_retained_intent = None + sd.aol_fault_reason = 'none' + sd.aol_authority_lost = False + sd.initialized = True + sd.enabled = sd.active = False + sd.events = Events() + sd.state_machine = StateMachine() + with patch('openpilot.selfdrive.selfdrived.selfdrived.REPLAY', False), patch.object(sd, 'retain_ordinary_source_state', return_value=False): + sd._expire_axis_source(cs, 1_100_000_001) + assert not sd.aol_authority_lost + assert log.OnroadEvent.EventName.controlsMismatch not in sd.events.names + cs.standstill = False + cs.vEgo = 1. + owner.update(cs, now_ns=1_200_000_000, fault_active=False) + assert owner.allowed_latch and not owner.main_startup_pending + + +@pytest.mark.parametrize('word', (8, 24, 9, 25)) +def test_parked_native_start_waits_for_current_main_and_movement(word): + from opendbc.safety.tests import test_volkswagen_long_aol as long_tests + owner, debug = long_tests.configure(word) + owner.manual = word in (24, 25) + try: + owner.safety.set_aol_test_heartbeat(False) + for _ in range(100): + owner.feed(moving=False) + owner.safety.aol_set_host_request(0) + assert owner.safety.aol_get_permission_mask() == 0 + owner.safety.set_aol_test_heartbeat(True) + for _ in range(12): + owner.feed() + assert not owner.safety.get_controls_allowed() + assert owner.safety.aol_get_permission_mask() == (1 if word in (8, 24) or debug else 0) + finally: + owner.tearDown() + + +@pytest.mark.parametrize('alpha', (False, True)) +def test_main_on_during_permanent_fault_does_not_queue_automatic_rearm(alpha): + fp = gen_empty_fingerprint() + fp[1][0xFD] = 8 + cp = CarInterface.get_params(CAR.VOLKSWAGEN_GOLF_MK7, fp, [], alpha, False, False) + owner = VolkswagenStockCardIntent(cp, AolSettings(True, 0., 0, 0, (0, 0, 0), (0, 0, 0))) + cs = structs.CarState(canValid=True, vEgo=20., gearShifter=structs.CarState.GearShifter.drive) + owner.update(cs, now_ns=1_000_000_000, fault_active=False) + cs.cruiseState.available = True + cs.steerFaultPermanent = True + owner.update(cs, now_ns=1_010_000_000, fault_active=True) + assert not owner.allowed_latch and not owner.main_startup_pending + cs.steerFaultPermanent = False + owner.update(cs, now_ns=1_020_000_000, fault_active=False) + assert not owner.allowed_latch diff --git a/openpilot/starpilot/aol/transport_pause.py b/openpilot/starpilot/aol/transport_pause.py index a3c652874d..d6f3e38691 100644 --- a/openpilot/starpilot/aol/transport_pause.py +++ b/openpilot/starpilot/aol/transport_pause.py @@ -363,7 +363,10 @@ class TransportPauseFeedback: # Ford angle/curvature: intent-only LONG echo join. # Require fresh LAT and all health/fault checks. ford_long = bool(ford_qualified(cp, marked_only=True) and cp.openpilotLongitudinalControl) - early_long = gm or cp.brand == 'hyundai' and early_native_long_withdrawal_supported(cp) or ev9 or ford_withdrawal or ford_long + from opendbc.car.volkswagen.long_aol import qualified as volkswagen_long_qualified + volkswagen_withdrawal = bool(volkswagen_long_qualified(cp, marked_only=True) and cs.cruiseState.available and + (physical_cancel(cs, cp) or not axis.desiredLongitudinal and not axis.longitudinalActive)) + early_long = gm or cp.brand == 'hyundai' and early_native_long_withdrawal_supported(cp) or ev9 or ford_withdrawal or ford_long or volkswagen_withdrawal from openpilot.starpilot.car.gm.aol import f1_conventional_lateral_owner, gm_physical_pedal_withdrawal gm_pedal = gm_physical_pedal_withdrawal(cp, cs) and not f1_conventional_lateral_owner(cp) classic_brake = classic_brake_withdrawal(cp, cs) @@ -385,13 +388,14 @@ class TransportPauseFeedback: not 0 < self.lateral_source_ns <= axis.sourceCarStateMonoTime <= axis.observedMonoTime <= now_ns or now_ns - axis.sourceCarStateMonoTime > AXIS_MAX_AGE_NS or not cs.canValid or cs.canTimeout or cs.steerFaultTemporary or cs.steerFaultPermanent or cs.accFaulted or - cs.steeringDisengage or physical_cancel(cs, cp) and not ford_withdrawal or + cs.steeringDisengage or physical_cancel(cs, cp) and not (ford_withdrawal or volkswagen_withdrawal) or not sm.seen['onroadEvents'] or not sm.valid['onroadEvents'] or not sm.alive['onroadEvents'] or not 0 < int(sm.logMonoTime['onroadEvents']) <= now_ns or now_ns - int(sm.logMonoTime['onroadEvents']) > 1_500_000_000 or any(event.immediateDisable or event.softDisable or event.userDisable and not (ev9_main_off and event.name == log.OnroadEvent.EventName.wrongCarMode or (gm_pedal or classic_brake) and event.name == log.OnroadEvent.EventName.pedalPressed or + volkswagen_withdrawal and event.name in (log.OnroadEvent.EventName.buttonCancel, log.OnroadEvent.EventName.pcmDisable) or ford_withdrawal and event.name in (log.OnroadEvent.EventName.pedalPressed, log.OnroadEvent.EventName.pcmDisable, log.OnroadEvent.EventName.buttonCancel)) for event in sm['onroadEvents'])): diff --git a/openpilot/starpilot/car/volkswagen/aol.py b/openpilot/starpilot/car/volkswagen/aol.py index 73f049e72f..2be05b8324 100644 --- a/openpilot/starpilot/car/volkswagen/aol.py +++ b/openpilot/starpilot/car/volkswagen/aol.py @@ -74,6 +74,7 @@ class VolkswagenStockCardIntent(AolCardIntent): def __init__(self, cp, settings): self.cp = cp + self.mqb = stock_qualified(cp) or long_qualified(cp) self.physical_eps_pause = False self.eps_recovery_ns = 0 self.main_seen = False @@ -81,7 +82,8 @@ class VolkswagenStockCardIntent(AolCardIntent): self.main_available = False self.main_neutral = False self.main_pulse = False - super().__init__(settings, explicit_latch=True, lkas_button_supported=False) + super().__init__(settings, explicit_latch=True, lkas_button_supported=False, + preserve_unassigned_cancel=self.mqb) def update(self, CS, **kwargs): from openpilot.starpilot.aol.runtime import SAFETY_MAX_AGE_NS @@ -110,8 +112,13 @@ class VolkswagenStockCardIntent(AolCardIntent): available = bool(state.cruiseState.available) if (not self.settings.enabled or self.settings.main_action == AOL_TOGGLE or self.settings.lkas_action == AOL_TOGGLE or (state.canValid and not state.canTimeout and (state.steerFaultPermanent or state.accFaulted)) or - any(event.type == ButtonType.cancel and event.pressed for event in CS.buttonEvents)): + any(event.type == ButtonType.cancel and event.pressed for event in CS.buttonEvents) and + (not self.mqb or any(self.settings.cancel_actions))): self.main_startup_pending = False + if (self.mqb and self.settings.enabled and state.canValid and not state.canTimeout and + not state.steerFaultPermanent and not state.accFaulted and available and self.main_neutral and + not self.main_available and self.settings.main_action != AOL_TOGGLE and self.settings.lkas_action != AOL_TOGGLE): + self.main_startup_pending = True default_main_edge = (available and (self.main_startup_pending or (self.main_neutral and not self.main_available)) and self.settings.main_action != AOL_TOGGLE and self.settings.lkas_action != AOL_TOGGLE) if state.canValid and not state.canTimeout: @@ -132,7 +139,8 @@ class VolkswagenStockCardIntent(AolCardIntent): state.buttonEvents = events super().update(state.as_reader(), **kwargs) if (default_main_edge and state.canValid and not state.canTimeout and self.settings.enabled and - not state.steerFaultPermanent and not state.accFaulted and not self._fault_inhibit): + not state.steerFaultPermanent and not state.accFaulted and not self._fault_inhibit and + (not self.mqb or not lateral_output_inhibited(self.cp, state))): self.allowed_latch = True self.main_startup_pending = False self.main_neutral = False @@ -201,3 +209,33 @@ def retain_eps_recovery(feedback, sm, cp, state, axis, now_ns, *, latched, produ (native.pandaSerial, tuple(p.hardwareSerial for p in native.pandaInventory)) == feedback.lateral_inventory) except (AttributeError, KeyError, IndexError, TypeError, ValueError, OverflowError): return False + + +def physical_cancel_lateral_allowed(cp, cs, intent, native, *, settings, previous, + source_ns, now_ns, axis_session_id) -> bool: + """Let the mapped intent owner apply Cancel while retaining a granted LAT axis.""" + from openpilot.starpilot.aol.intent import ButtonType + from openpilot.starpilot.aol.runtime import (AXIS_MAX_AGE_NS, INTENT_MAX_AGE_NS, SAFETY_MAX_AGE_NS, + native_inventory_matches_cp) + try: + return bool((stock_qualified(cp, marked_only=True) or long_qualified(cp, marked_only=True)) and + settings is not None and settings.enabled and not any(settings.cancel_actions) and + previous is not None and previous.lateral_active and previous.native_acknowledged and + intent is not None and intent.settingsQualified and intent.allowedLatch and intent.lateralArmed and + not intent.pauseLateral and intent.producerSessionId and intent.carStateLogMonoTime == source_ns and + 0 < source_ns <= intent.observedMonoTime <= now_ns <= intent.validUntilMonoTime and + now_ns - source_ns <= AXIS_MAX_AGE_NS and now_ns - intent.observedMonoTime <= INTENT_MAX_AGE_NS and + intent.validUntilMonoTime - intent.observedMonoTime <= SAFETY_MAX_AGE_NS and + cs.canValid and not cs.canTimeout and cs.cruiseState.available and not cs.steerFaultTemporary and + not cs.steerFaultPermanent and not cs.accFaulted and not cs.doorOpen and + any(event.type == ButtonType.cancel for event in cs.buttonEvents) and + native is not None and native.compatible and int(native.protocolVersion) == 1 and + axis_session_id and native.axisSessionId == axis_session_id and native.requestedLateral and native.lateralAllowed and + native_accepts_cp(cp, native.safetyModel, native.safetyParam) and native.pandaInventory and + native_inventory_matches_cp(native, cp) and + 0 < native.observedMonoTime <= now_ns <= native.validUntilMonoTime and + now_ns - native.observedMonoTime <= SAFETY_MAX_AGE_NS and + native.validUntilMonoTime - native.observedMonoTime <= SAFETY_MAX_AGE_NS) + except (AttributeError, KeyError, IndexError, TypeError, ValueError, OverflowError): + return False + diff --git a/prebuilt.json b/prebuilt.json index ffdb597df6..fff4cdedfb 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "ee6a57e864f05bf431a993a0ab5ecf3ed8cdf7ee8596fb85d44bc49f0bfbfb87", "schema_version": 1} +{"protected_inventory_sha256": "749f98078d37f2169b443a42f5f04f58edc7e9b96b668ced762f534ccb4f3a57", "schema_version": 1}