Narrow Card and Selfdrive Receipts

This commit is contained in:
firestar5683
2026-11-28 16:10:50 -06:00
parent 6ee19cfb61
commit 303a5a4383
3 changed files with 64 additions and 45 deletions
+48 -35
View File
@@ -398,7 +398,9 @@ class Car:
subscribed_services.append('slcState')
self.sm = messaging.SubMaster(subscribed_services)
for ignored in (self.sm.ignore_alive, self.sm.ignore_valid, self.sm.ignore_average_freq):
if 'slcState' not in ignored:
if isinstance(ignored, set):
ignored.add('slcState')
elif 'slcState' not in ignored:
ignored.append('slcState')
if 'slcDashboardObservation' not in self.pm.sock:
self.pm.sock['slcDashboardObservation'] = messaging.pub_sock('slcDashboardObservation')
@@ -577,40 +579,40 @@ class Car:
if self.aol_process_fault_context is None:
self.aol_process_fault_context = AolProcessFaultContext()
self.aol_process_fault_context.observe(self.sm, now_ns)
if getattr(self, 'aol_transport_feedback', None) is None:
self.aol_transport_feedback = TransportPauseFeedback(self.CP)
feedback = getattr(self, 'aol_transport_feedback', None)
if feedback is None:
feedback = self.aol_transport_feedback = TransportPauseFeedback(self.CP)
cancel_source_ns = self.aol_cancel_source(CS, now_ns)
brake_source_ns = self.aol_honda_brake_source(CS, now_ns)
gm_withdrawal_source_ns = self.aol_gm_withdrawal_source(CS, now_ns)
hkg_cancel_retained = hkg_cancel_intent_retained(self.CP, CS, self.sm, self.aol_transport_feedback,
hkg_cancel_retained = hkg_cancel_intent_retained(self.CP, CS, self.sm, feedback,
self.aol_card_intent, cancel_source_ns=cancel_source_ns, now_ns=now_ns,
producer=getattr(self, 'slc_producer_session', ''))
cancel_feedback = self.aol_transport_feedback
if hkg_cancel_retained and cancel_feedback is not None and not cancel_feedback.longitudinal_cancel_ns:
if hkg_cancel_retained and not feedback.longitudinal_cancel_ns:
# The pure guard proved this exact raw CANCEL/FULL join. Bind
# its first local receipt for the existing bounded withdrawal handshake;
# held samples never renew it or any source/native/output deadline.
if cancel_source_ns > cancel_feedback.last_cancel_source_ns:
cancel_feedback.longitudinal_cancel_ns = cancel_source_ns
cancel_feedback.last_cancel_source_ns = cancel_source_ns
rivian_brake_retained = rivian_brake_intent_retained(self.CP, CS, self.sm, self.aol_transport_feedback,
if cancel_source_ns > feedback.last_cancel_source_ns:
feedback.longitudinal_cancel_ns = cancel_source_ns
feedback.last_cancel_source_ns = cancel_source_ns
rivian_brake_retained = rivian_brake_intent_retained(self.CP, CS, self.sm, feedback,
self.aol_card_intent, now_ns=now_ns, producer=self.slc_producer_session)
angle_arm_pending = pending_stock_angle_arm(self.CP, CS, self.sm, self.aol_card_intent,
now_ns=now_ns, producer=self.slc_producer_session,
acknowledged_arm_ns=getattr(self, '_angle_aol_acknowledged_arm_ns', 0))
ford_initial_wait = bool(not self.aol_transport_feedback.ever_lateral_active and
ford_initial_wait = bool(not feedback.ever_lateral_active and
self.aol_card_intent.allowed_latch and qualified_ford_aol(self.CP, marked_only=True) and
ford_awaiting_initial_request(self.CP, CS, self.sm,
current_native(self.sm, self.CP, now_ns=now_ns, axis_session_id=self.aol_axis_session()),
self.aol_transport_feedback, self.aol_card_intent, now_ns=now_ns, producer=self.slc_producer_session))
feedback, self.aol_card_intent, now_ns=now_ns, producer=self.slc_producer_session))
from openpilot.starpilot.car.volkswagen.aol import awaiting_initial_request as volkswagen_initial_request
volkswagen_initial_wait = self.CP.brand == 'volkswagen' and volkswagen_initial_request(
self.CP, CS, self.sm,
current_native(self.sm, self.CP, now_ns=now_ns, axis_session_id=self.aol_axis_session()),
self.aol_transport_feedback, self.aol_card_intent, now_ns=now_ns,
feedback, self.aol_card_intent, now_ns=now_ns,
producer=getattr(self, 'slc_producer_session', ''))
transport_reset = not (hkg_cancel_retained or rivian_brake_retained or angle_arm_pending or
ford_initial_wait or volkswagen_initial_wait) and self.aol_transport_feedback.observe(
ford_initial_wait or volkswagen_initial_wait) and feedback.observe(
self.sm, self.CP, CS, now_ns,
latched=self.aol_card_intent.allowed_latch, cancel_source_ns=cancel_source_ns,
brake_source_ns=brake_source_ns,
@@ -629,7 +631,6 @@ class Car:
if (getattr(self.aol_card_intent, 'requires_fault_observation', self.aol_card_intent.explicit_latch) and
self.sm.updated['onroadEvents'] and
self.sm.valid['onroadEvents'] and 0 < event_ns <= now_ns and now_ns - event_ns <= 1_500_000_000):
feedback = self.aol_transport_feedback
# Reuse only this call's healthy observation; fault/physical paths reobserve.
reuse_transport = rivian_brake_retained or bool(not transport_reset and not cancel_source_ns and not brake_source_ns and
not gm_withdrawal_source_ns and CS.canValid and not CS.canTimeout and
@@ -676,7 +677,8 @@ class Car:
ford_initial_wait and not self.sm['aolAxisState'].desiredLateral or
restrict(self.CP, CS) or
((angle_aol or ford_aol or mazda_aol or preap_aol or rivian_aol) and self.aol_card_intent.pause_lateral) or
(angle_aol and CS.brakePressed and (not CS.standstill) and (CS.vEgo < self.aol_settings.pause_brake_mps)) or
(angle_aol and self.aol_settings is not None and CS.brakePressed and
not CS.standstill and CS.vEgo < self.aol_settings.pause_brake_mps) or
ford_brake_pause_active(self.CP, CS, self.aol_settings) or
(volkswagen_aol and (self.aol_card_intent.pause_lateral or
(CS.brakePressed and (not CS.standstill) and (CS.vEgo < self.aol_card_intent.settings.pause_brake_mps))))),
@@ -705,7 +707,7 @@ class Car:
rejected = native_reset or (not angle_arm_pending and not subaru_braked_main_pending and not subaru_paddle_pending and
not volkswagen_initial_wait and not volkswagen_reverse_pending and not honda_eps_pending and not mazda_restriction_pending and
native_latch_rejected(self.CP, native, state=CS if angle_panda_ready else None))
rejection_ns = now_ns if native_reset else int(native.observedMonoTime) if rejected else 0
rejection_ns = now_ns if native_reset else int(native.observedMonoTime) if rejected and native is not None else 0
observe_physical = getattr(self.aol_card_intent, 'observe_physical_samples', None)
if observe_physical is not None:
observe_physical(self.CI.CS, now_ns=now_ns)
@@ -773,7 +775,7 @@ class Car:
gesture, drive_id, fingerprint, _, _ = self.manual_receipt
self.manual_button_tracker.claim(gesture, drive_id, fingerprint)
gm_buttons = (self.gm_distance_map.sample(self.params, distance_observation, now_ns)
if distance_owner is not None else None)
if distance_owner is not None and self.gm_distance_map is not None else None)
if self.traffic_button_tracker is not None:
self.traffic_receipt = conditional_traffic_candidate(
CS, self.traffic_button_tracker, self.params, self.manual_settings_owner,
@@ -938,12 +940,13 @@ class Car:
if not aol_policy_for(self.CP).intent_supported:
return True
from openpilot.starpilot.aol.vehicle import intent_disarming_fault
if getattr(self, 'aol_transport_feedback', None) is None:
self.aol_transport_feedback = TransportPauseFeedback(self.CP)
hkg_cancel_retained = hkg_cancel_intent_retained(self.CP, CS, self.sm, self.aol_transport_feedback,
feedback = getattr(self, 'aol_transport_feedback', None)
if feedback is None:
feedback = self.aol_transport_feedback = TransportPauseFeedback(self.CP)
hkg_cancel_retained = hkg_cancel_intent_retained(self.CP, CS, self.sm, feedback,
self.aol_card_intent, cancel_source_ns=self.aol_cancel_source(CS, now_ns), now_ns=now_ns,
producer=getattr(self, 'slc_producer_session', ''))
if not transport_observed_healthy and not hkg_cancel_retained and self.aol_transport_feedback.observe(self.sm, self.CP, CS, now_ns,
if not transport_observed_healthy and not hkg_cancel_retained and feedback.observe(self.sm, self.CP, CS, now_ns,
latched=getattr(getattr(self, 'aol_card_intent', None), 'allowed_latch', True),
cancel_source_ns=self.aol_cancel_source(CS, now_ns), brake_source_ns=self.aol_honda_brake_source(CS, now_ns),
gm_withdrawal_source_ns=self.aol_gm_withdrawal_source(CS, now_ns),
@@ -958,20 +961,22 @@ class Car:
getattr(self.aol_card_intent, 'reverse_pause', False)))):
return True
events = self.sm['onroadEvents']
if self.aol_transport_feedback.retention_qualified or self.aol_transport_feedback.retention_pending:
if feedback.retention_qualified or feedback.retention_pending:
from openpilot.starpilot.aol.transport_pause import AVAILABILITY_EVENTS
events = [event for event in events if not
(event.name in AVAILABILITY_EVENTS and event.softDisable and not event.immediateDisable)]
if getattr(self.aol_transport_feedback, 'temporary_host_qualified', False):
if getattr(feedback, 'temporary_host_qualified', False):
events = [event for event in events if not (event.name in
(log.OnroadEvent.EventName.locationdTemporaryError, log.OnroadEvent.EventName.commIssue) and
event.softDisable and not event.immediateDisable)]
intent = self.aol_card_intent
fault_context = self.aol_process_fault_context
return intent_disarming_fault(self.CP, events, CS,
startup_calibration_pending=bool(getattr(self.aol_card_intent, 'startup_calibration_pending', False) and
self.aol_card_intent.settings.enabled and self.aol_card_intent.main_action != 9),
temporary_ui_process_failure=self.aol_process_fault_context.temporary_ui_failure(event_ns, now_ns),
startup_calibration_pending=bool(intent is not None and getattr(intent, 'startup_calibration_pending', False) and
intent.settings.enabled and intent.main_action != 9),
temporary_ui_process_failure=fault_context is not None and fault_context.temporary_ui_failure(event_ns, now_ns),
temporary_selfdrive_lagging=(qualified_gm(self.CP) or aol_policy_for(self.CP).intent_supported),
temporary_source_pause=(self.aol_transport_feedback.qualified or self.aol_transport_feedback.awaiting))
temporary_source_pause=(feedback.qualified or feedback.awaiting))
def aol_permission_owners(self) -> tuple[bool, bool, bool, bool, bool, bool]:
# CP is fixed once the drive starts; these checks ran five times per 100 Hz frame.
@@ -995,7 +1000,7 @@ class Car:
feedback = self.aol_transport_feedback
# A pre-publication OFF cannot revoke this newer host request.
# Unmatched denial still uses the existing bounded pending timeout.
host_requested = bool(axis is not None and axis.sessionId == native.axisSessionId and
host_requested = bool(feedback is not None and axis is not None and axis.sessionId == native.axisSessionId and
axis.observedMonoTime == self.sm.logMonoTime['aolAxisState'] and
axis.validUntilMonoTime == axis.observedMonoTime + AXIS_MAX_AGE_NS and
axis.faultSessionId == axis.sessionId and str(axis.faultReason) == 'none' and
@@ -1036,7 +1041,9 @@ class Car:
if (self.sm.updated['onroadEvents'] and self.sm.valid['onroadEvents'] and
0 < event_ns <= now_ns and now_ns - event_ns <= 1_500_000_000):
calibration_events = self.sm['onroadEvents']
self.aol_card_intent.observe_calibration(CS, events=calibration_events, standard_enabled=standard_enabled)
intent = self.aol_card_intent
if intent is not None:
intent.observe_calibration(CS, events=calibration_events, standard_enabled=standard_enabled)
def state_publish(self, CS: car.CarState, RD: structs.RadarDataT | None):
"""carState and carParams publish loop"""
@@ -1671,7 +1678,8 @@ class Car:
0 < receipt_ns <= now_ns and now_ns - receipt_ns <= 150_000_000) or
CC.enabled or CC.latActive or CC.longActive or CC.actuators.torque != 0.0 or CC.actuators.accel != 0.0):
return
if (ev6_startup or classic_startup) and not self.vehicle_startup.owner.prepared_for(self.CP):
startup_owner = self.vehicle_startup.owner
if (ev6_startup or classic_startup) and (startup_owner is None or not startup_owner.prepared_for(self.CP)):
return
if getattr(self, 'volt_cc_selected', False):
@@ -1698,7 +1706,9 @@ class Car:
from opendbc.car.hyundai.ecu_startup import Outcome
pending_carnival = (isinstance(self.vehicle_startup.owner, GenericHDA2Startup) and
self.vehicle_startup.owner.outcome is Outcome.PENDING)
if initialize_only and (pending_carnival or (self.mixed_startup_keepalive() and self.vehicle_startup.owner.pending_target)):
startup_owner = self.vehicle_startup.owner
if initialize_only and (pending_carnival or
(self.mixed_startup_keepalive() and (startup_owner is None or startup_owner.pending_target))):
# Fresh disabled controls alone are insufficient: finish the host's
# selfdriveInitializing phase before suppressing factory ADAS output.
return
@@ -1804,6 +1814,8 @@ class Car:
return
if mixed_startup:
owner = self.vehicle_startup.owner
if owner is None:
return
now_boot_ns = time.clock_gettime_ns(time.CLOCK_BOOTTIME)
if (not owner.pending_target and self.startup_panda_configured() and
owner.sources_current(self.CI, now_boot_ns)):
@@ -1861,7 +1873,7 @@ class Car:
return
if self.sm.valid['carControl'] and self.sm.all_alive(['carControl']):
if self.mixed_startup_keepalive() and not self.vehicle_startup.owner.handed_off:
if self.mixed_startup_keepalive() and (startup_owner is None or not startup_owner.handed_off):
# The first admitted replacement cycle is always neutral; the actual
# send receipt, not reaching apply(), transfers diagnostic continuity.
CC = car.CarControl.new_message().as_reader()
@@ -2025,9 +2037,10 @@ def main():
car.prepare_pe_restoration()
finally:
car.vehicle_startup.close()
if getattr(car, 'ioniq6_keepalive', None) is not None:
keepalive = getattr(car, 'ioniq6_keepalive', None)
if keepalive is not None:
car.ioniq6_long_lost = True
car.ioniq6_keepalive.stop()
keepalive.stop()
if getattr(car, 'ioniq6_restore_callbacks', None) is not None and not getattr(car, 'ioniq6_restore_attempted', False):
# This Card is no longer an output owner, even if it had published a
# qualified CP. Restore stock ECU traffic before a later Card starts.
+14 -9
View File
@@ -843,12 +843,14 @@ class SelfdriveD:
timed_out = self.sm.frame * DT_CTRL > 6.
if all_valid or timed_out or (SIMULATION and not REPLAY):
available_streams = VisionIpcClient.available_streams("camerad", block=False)
if VisionStreamType.VISION_STREAM_NARROW_ROAD not in available_streams:
self.sm.ignore_alive.add('narrowRoadCameraState')
self.sm.ignore_valid.add('narrowRoadCameraState')
if VisionStreamType.VISION_STREAM_WIDE_ROAD not in available_streams:
self.sm.ignore_alive.add('wideRoadCameraState')
self.sm.ignore_valid.add('wideRoadCameraState')
for stream, service in ((VisionStreamType.VISION_STREAM_NARROW_ROAD, 'narrowRoadCameraState'),
(VisionStreamType.VISION_STREAM_WIDE_ROAD, 'wideRoadCameraState')):
if stream not in available_streams:
for ignored in (self.sm.ignore_alive, self.sm.ignore_valid):
if isinstance(ignored, set):
ignored.add(service)
elif service not in ignored:
ignored.append(service)
if REPLAY and any(ps.controlsAllowed for ps in self.sm['pandaStates']):
self.state_machine.state = State.enabled
@@ -1392,7 +1394,7 @@ class SelfdriveD:
def ordinary_source_withdrawal(self):
accepted = self.aol_ordinary_source_anchor[2]
native = self.aol_ordinary_source_native
lateral_grant = bool(accepted.allowedLatch and accepted.lateralArmed and not accepted.pauseLateral and
lateral_grant = bool(accepted is not None and native is not None and accepted.allowedLatch and accepted.lateralArmed and not accepted.pauseLateral and
not getattr(self, 'aol_dm_lateral_inhibit', False) and
native.requestedLateral and native.lateralAllowed)
# Both commands remain inactive. This ACK describes only an actual native
@@ -2178,7 +2180,7 @@ class SelfdriveD:
"""An established host LAT request lost its native grant, not a cold wait."""
pause = getattr(self, 'aol_transport_pause', None)
prior = getattr(pause, 'observed_native', None)
if (not honda_aol_qualified(self.CP, marked_only=True) or not source_current or
if (pause is None or not honda_aol_qualified(self.CP, marked_only=True) or not source_current or
not self.initialized or not previous.lateral_active or not requested.desired_lateral or
native is None or previous_intent is None or intent is None or not previous_intent.producerSessionId or
previous_intent.producerSessionId != intent.producerSessionId or
@@ -2207,6 +2209,9 @@ class SelfdriveD:
healthy_transport(self.sm, self.CP, CS, self.aol_session_id, now_ns, native))
def _reconciled_input_pairs(self, companion):
return dict(companion.samples) if companion is not None and self.aol_reconciled_sources else {}
def step(self):
self.aol_lag_takeover_alert = False
self.aol_soft_takeover_alert = False
@@ -2264,7 +2269,7 @@ class SelfdriveD:
self.aol_decision_native = native
if self.aol_replay:
previous_intent = getattr(self, 'aol_last_intent', None)
reconciled_pairs = dict(intent_companion.samples) if intent_companion is not None and self.aol_reconciled_sources else {}
reconciled_pairs = self._reconciled_input_pairs(intent_companion)
reconciled_epoch = intent_companion.integrity_epoch if intent_companion is not None else -1
source_pair = intent_companion.samples.get(self.aol_car_state_log_ns) if intent_companion is not None else None
verified = intent_companion.verified_sm_projection if intent_companion is not None else None
@@ -109,7 +109,8 @@ def stock_lateral_fault_proof(self, CS, message, now_ns):
native = getattr(self, 'aol_decision_native', None)
anchor = getattr(self, 'aol_ordinary_source_anchor', None)
axis = message.aolAxisState
if (published is None or anchor is None or anchor[1] is None or not message.valid or not axis.qualified or published[1] != 'critical' or
if (published is None or anchor is None or anchor[1] is None or intent is None or native is None or
not message.valid or not axis.qualified or published[1] != 'critical' or
any(published[4:]) or not stock_lateral_role(self, CS, native, intent) or
self.aol_authority_lost or getattr(self, 'aol_availability_long_inhibit', False) or
getattr(self, 'car_state_queue_invalid', False) or getattr(self, 'aol_selected_pair_future', False) or