diff --git a/openpilot/starpilot/aol/tests/test_mqb_actual_callers.py b/openpilot/starpilot/aol/tests/test_mqb_actual_callers.py index ea2e8bcb10..8780942c44 100644 --- a/openpilot/starpilot/aol/tests/test_mqb_actual_callers.py +++ b/openpilot/starpilot/aol/tests/test_mqb_actual_callers.py @@ -40,7 +40,7 @@ def test_mqb_full_engagement_brake_reverse_drive_actual_callers(gearbox, alpha, startup_delivery_delay=0, startup_delivery_services=(), receipt_sink=None, route2c_start=False, startup_block_until=0, startup_expect_expiry=False, startup_probe_denials=False, startup_stall=None, startup_stall_mode='frozen', - startup_floor_dip=False, cancel_delivery_delay=0, brake_delivery_delay=0): + startup_floor_dip=False, cancel_delivery_delay=0, brake_delivery_delay=0, rushed_start=False): pq = candidate == CAR.VOLKSWAGEN_SHARAN_MK2 with ExitStack() as cleanup: cleanup.enter_context(OpenpilotPrefix()) @@ -344,10 +344,14 @@ def test_mqb_full_engagement_brake_reverse_drive_actual_callers(gearbox, alpha, allowed=bool(permission & 1), long_allowed=bool(permission & 2), native_request_lat=bool(request & 1), native_request_long=bool(request & 2), panda_controls_allowed=native.get_controls_allowed(), + car_output_valid=not rushed_start or not 28 <= tick < 42, **({'car_state_message': card.pm.messages['carState'].as_builder(), 'authority_message': card.pm.messages['starpilotCarState'].as_builder() if 'starpilotCarState' in card.pm.messages else None, 'companion': 'starpilotCarState' in card.pm.messages, 'timeout': stalled and startup_stall_mode == 'frozen-timeout'} if startup_stall is not None else {})) + if rushed_start and 30 <= tick < 42: + assert not card.aol_card_intent.allowed_latch, 'VW_STARTUP_ARMED_BEFORE_HOST_READY' + assert not command.latActive and not command.longActive if startup_floor_dip and state.vEgo <= cp.minSteerSpeed: assert not command.latActive and not command.longActive if startup_floor_dip and command.latActive and not card.aol_card_intent.startup_granted: @@ -544,7 +548,10 @@ def test_mqb_full_engagement_brake_reverse_drive_actual_callers(gearbox, alpha, assert not any(lat_commands[35:]) and not any(long_commands) assert card.aol_card_intent.startup_aborted and not card.aol_card_intent.allowed_latch return - assert any(lat_commands[60:74] if startup_floor_dip else lat_commands[45:60] if reverse_boot else lat_commands[35:60]) + if rushed_start: + assert any(lat_commands[43:75]) + else: + assert any(lat_commands[60:74] if startup_floor_dip else lat_commands[45:60] if reverse_boot else lat_commands[35:60]) assert any(lat_commands[76:84]) # braking released long, not qualified lateral intent assert not any(lat_commands[86:95]) assert any(lat_commands[100:]) @@ -1112,3 +1119,10 @@ def test_mqb_cancel_receipt_binds_exact_current_raw_press(veto): def test_mqb_brake_withdraws_long_and_preserves_lateral(phase, delay): test_mqb_full_engagement_brake_reverse_drive_actual_callers( 'manual', True, 0, False, True, native_phase=phase, brake_delivery_delay=delay) + + +@pytest.mark.parametrize('phase', range(10)) +def test_mqb_cold_drive_waits_for_healthy_startup(phase): + test_mqb_full_engagement_brake_reverse_drive_actual_callers( + 'manual', True, 0, False, False, parked_boot=True, delayed_heartbeat=True, + native_phase=phase, rushed_start=True) diff --git a/openpilot/starpilot/aol/tests/test_volkswagen_main_boot.py b/openpilot/starpilot/aol/tests/test_volkswagen_main_boot.py index 3fe15703db..3e50fe8fed 100644 --- a/openpilot/starpilot/aol/tests/test_volkswagen_main_boot.py +++ b/openpilot/starpilot/aol/tests/test_volkswagen_main_boot.py @@ -143,9 +143,12 @@ def test_mqb_parked_delayed_start_keeps_main_request_unconsumed(alpha): assert not sd.aol_authority_lost assert log.OnroadEvent.EventName.controlsMismatch not in sd.events.names cs.standstill = False - cs.vEgo = 1. + cs.vEgo = cs.vEgoRaw = 1. owner.update(cs, now_ns=1_200_000_000, fault_active=False) - assert owner.allowed_latch and not owner.main_startup_pending + # A speed crossing alone cannot start a manual Alpha Long request after a source gap. + # The actual Card/Panda callers exercise arming after healthy feedback returns. + assert owner.allowed_latch is not alpha + assert owner.main_startup_pending is alpha @pytest.mark.parametrize('word', (8, 24, 9, 25)) diff --git a/openpilot/starpilot/car/volkswagen/aol.py b/openpilot/starpilot/car/volkswagen/aol.py index e78b17b109..5ecef97b45 100644 --- a/openpilot/starpilot/car/volkswagen/aol.py +++ b/openpilot/starpilot/car/volkswagen/aol.py @@ -93,6 +93,7 @@ class VolkswagenStockCardIntent(AolCardIntent): self.startup_granted = False self.startup_aborted = False self.startup_ready = False + self.startup_drive_identity = None self.startup_identity = None self.startup_observation_identity = None self.startup_floor_pending = False @@ -177,6 +178,11 @@ class VolkswagenStockCardIntent(AolCardIntent): (not self.cruise_lateral or not lateral_output_inhibited(self.cp, state))): deferred = self.startup_deferred or (was_reverse and self.main_startup_pending and not self.allowed_latch and longitudinal_speed_event(self.cp, state) and abs(state.vEgo) < self.cp.minEnableSpeed) + if (not deferred and not was_reverse and self.main_startup_pending and not self.startup_arm_ns and + long_qualified(self.cp, marked_only=True) and self.cp.transmissionType == structs.CarParams.TransmissionType.manual): + if not self.startup_ready: + return + self.startup_drive_identity = self.startup_observation_identity if deferred and not self.startup_granted: if not self.startup_arm_ns: self.startup_arm_ns = now_ns @@ -209,7 +215,7 @@ class VolkswagenStockCardIntent(AolCardIntent): not long_qualified(self.cp, marked_only=True) or self.cp.transmissionType != structs.CarParams.TransmissionType.manual): return - if not self.startup_deferred and (not self.main_startup_pending or not self.reverse_pause): + if not self.startup_deferred and not self.main_startup_pending: return try: axis = current_axis(sm, now_ns=now_ns) @@ -225,6 +231,20 @@ class VolkswagenStockCardIntent(AolCardIntent): tuple(p.hardwareSerial for p in proof.pandaInventory)) if not self.startup_deferred: self.startup_observation_identity = identity + if not self.reverse_pause: + event_ns = int(sm.logMonoTime['onroadEvents']) + self.startup_ready = bool( + axis.observedMonoTime == int(sm.logMonoTime['aolAxisState']) and axis.sequence > 0 and + 0 < axis.sourceCarStateMonoTime <= axis.observedMonoTime <= now_ns and + now_ns - axis.sourceCarStateMonoTime <= AXIS_MAX_AGE_NS and + 0 < axis.validUntilMonoTime - axis.observedMonoTime <= AXIS_MAX_AGE_NS and + sm.seen['onroadEvents'] and sm.valid['onroadEvents'] and sm.alive['onroadEvents'] and + 0 < event_ns == axis.faultEventMonoTime <= axis.observedMonoTime and now_ns - event_ns <= 1_500_000_000 and + not any(e.immediateDisable or e.softDisable or e.userDisable for e in sm['onroadEvents']) and + not (axis.desiredLateral or axis.lateralActive or axis.desiredLongitudinal or axis.longitudinalActive) and + not (proof.requestedLateral or proof.lateralAllowed or proof.requestedLongitudinal or proof.longitudinalAllowed) and + min(abs(cs.vEgo), abs(cs.vEgoRaw)) > max(self.cp.minSteerSpeed, .3) and + not (cs.doorOpen or cs.seatbeltUnlatched or cs.vehicleSensorsInvalid or cs.steeringDisengage or cs.buttonEvents)) return if identity != self.startup_identity: return @@ -435,11 +455,22 @@ def awaiting_initial_request(cp, cs, sm, native, feedback, intent, *, now_ns, pr reverse_event_pending = bool(axis is not None and 0 < event_ns < arm <= axis.sourceCarStateMonoTime and event_ns < axis.faultEventMonoTime <= axis.observedMonoTime and any(event.name == log.OnroadEvent.EventName.reverseGear and event.userDisable for event in sm['onroadEvents'])) + drive_identity = getattr(intent, 'startup_drive_identity', None) + identity = None if drive_identity is None or axis is None or native is None else ( + cp_identity(cp), str(axis.sessionId), producer, int(axis.intentIntegrityEpoch), native.pandaSerial, + tuple(p.hardwareSerial for p in native.pandaInventory)) + granted_in_window = bool(drive_identity is not None and identity == drive_identity and + axis is not None and axis.desiredLateral and not axis.lateralActive and + arm <= axis.sourceCarStateMonoTime <= arm + SAFETY_MAX_AGE_NS and + native is not None and native.pandaInventory and native.requestedLateral and native.lateralAllowed and + 0 < arm <= native.observedMonoTime <= arm + SAFETY_MAX_AGE_NS and + 0 <= now_ns - native.observedMonoTime <= AXIS_MAX_AGE_NS) return bool(intent.settings.enabled and intent.settings.main_action != AOL_TOGGLE and intent.settings.lkas_action != AOL_TOGGLE and intent.allowed_latch and not intent.pause_lateral and not feedback.ever_lateral_active and not feedback.failed and not feedback.paused and not feedback.pending_event and not feedback.retention_started_ns and feedback.cp == cp_identity(cp) and - 0 < arm <= now_ns <= arm + SAFETY_MAX_AGE_NS and + 0 < arm <= now_ns and (now_ns <= arm + SAFETY_MAX_AGE_NS or granted_in_window) and + (drive_identity is None or identity == drive_identity) and cs.canValid and not cs.canTimeout and cs.cruiseState.available and not lateral_output_inhibited(cp, cs) and not cs.accFaulted and not cs.vehicleSensorsInvalid and not cs.doorOpen and not cs.seatbeltUnlatched and not cs.steeringDisengage and not cs.brakePressed and not cs.regenBraking and not cs.buttonEvents and @@ -455,7 +486,7 @@ def awaiting_initial_request(cp, cs, sm, native, feedback, intent, *, now_ns, pr axis.intentProducerSessionId == producer and producer and 0 < axis.sourceCarStateMonoTime <= axis.observedMonoTime <= now_ns and now_ns - axis.sourceCarStateMonoTime <= AXIS_MAX_AGE_NS and - native is not None and not native.lateralAllowed and not native.requestedLongitudinal and + native is not None and (not native.lateralAllowed or granted_in_window) and not native.requestedLongitudinal and not native.longitudinalAllowed and native.observedMonoTime <= now_ns and _configured_transport_native(sm, cp, axis.sessionId, now_ns, native, require_longitudinal=False, allow_restricted_lateral=True) is not None and diff --git a/prebuilt.json b/prebuilt.json index e0791136f9..b7f3606ca8 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "3b11b00ff35671c4775ee301e86072b6b2bee27c59a74ef18b0018f00b105df0", "schema_version": 1} +{"protected_inventory_sha256": "8e850568bb76cb9927ab74e0a08bbd1c7553ae0d15430af6ad9ada022ef95448", "schema_version": 1}