Preserve Subaru MAIN rearming through brake and signal pauses

This commit is contained in:
firestar5683
2026-11-13 16:59:21 -06:00
parent b2f0af723a
commit 69667edae6
6 changed files with 72 additions and 7 deletions
@@ -282,8 +282,10 @@ def test_braked_main_retains_only_intent_until_fresh_native_grant(epoch):
@pytest.mark.parametrize('veto', ('permanent', 'temporary', 'invalid_can', 'timeout', 'acc', 'door', 'seatbelt',
'sensors', 'steering', 'gas', 'regen', 'main_off', 'reverse', 'cancel', 'event_fault', 'initializing',
'wrong_producer', 'axis_fault', 'expired_axis', 'bad_native', 'missing_native', 'native_heartbeat', 'native_fault'))
def test_pending_braked_main_preserves_independent_vetoes(veto):
cp, state, feedback = cold_main_baseline()
@pytest.mark.parametrize('prior_active', (False, True))
def test_pending_braked_main_preserves_independent_vetoes(veto, prior_active):
cp, state, feedback = baseline() if prior_active else cold_main_baseline()
state.brakePressed = True
now = NOW + 10_000_000
sm, native = braked_main_sample(cp, now, 2)
fields = {'permanent': 'steerFaultPermanent', 'temporary': 'steerFaultTemporary', 'invalid_can': 'canValid',
@@ -456,3 +458,42 @@ def test_stopped_feedback_retention_preserves_independent_vetoes(fault):
cp.carFingerprint = CAR.SUBARU_OUTBACK_2023
assert feedback.observe(sm, cp, state, now, latched=True,
intent_producer_session='changed' if fault == 'wrong_producer' else PRODUCER)
@pytest.mark.parametrize('epoch', (0, 1))
def test_new_main_after_prior_grant_waits_for_brake_without_renewing_leases(epoch):
cp, state, feedback = baseline()
assert feedback.ever_lateral_active and feedback.subaru_lateral_grant_ns == NOW
state.brakePressed = True
off = NOW + 10_000_000
sm, _ = sample(cp, off, off, 2, active=False, requested=False, allowed=False, event_stamp=off)
assert not feedback.observe(sm, cp, state, off, latched=False, intent_producer_session=PRODUCER)
before = leases(feedback)
arm = off + 10_000_000
for tick in range(100):
now = arm + tick * 10_000_000
sm, native = braked_main_sample(cp, now, tick + 3)
change(sm, 'aolAxisState', lambda axis: setattr(axis, 'intentIntegrityEpoch', epoch))
assert not feedback.observe(sm, cp, state, now, latched=True, intent_producer_session=PRODUCER, main_arm_ns=arm)
assert not feedback.failed and not native.lateralAllowed and leases(feedback) == before
assert feedback.subaru_lateral_grant_ns == NOW
state.brakePressed = False
now += 10_000_000
sm, native = sample(cp, now, now, 103, event_stamp=now)
change(sm, 'aolAxisState', lambda axis: setattr(axis, 'intentIntegrityEpoch', epoch))
assert not feedback.observe(sm, cp, state, now, latched=True, intent_producer_session=PRODUCER, main_arm_ns=arm)
assert native.lateralAllowed and feedback.subaru_lateral_grant_ns == now
@pytest.mark.parametrize('arm_offset', (-10_000_000, 0))
def test_braked_main_cannot_reinterpret_granted_gesture_as_first_grant(arm_offset):
from openpilot.starpilot.car.subaru.aol import retain_braked_main_intent
cp, state, feedback = baseline()
state.brakePressed = True
now = NOW + 10_000_000
sm, _ = braked_main_sample(cp, now, 2)
before = leases(feedback)
assert not retain_braked_main_intent(feedback, sm, cp, state, sm['aolAxisState'], now,
arm_ns=NOW + arm_offset, producer=PRODUCER)
assert feedback.subaru_braked_main is None and leases(feedback) == before
@@ -287,6 +287,7 @@ class TransportPauseFeedback:
self.lateral_only_baseline = False
self.temporary_eps_gas_override = False
self.subaru_braked_main = None
self.subaru_lateral_grant_ns = 0
self.subaru_main_retained_native_ns = 0
self.subaru_eps_brake_event_ns = 0
self.hkg_eps_join_until_ns = 0
@@ -1825,6 +1826,8 @@ class TransportPauseFeedback:
if lateral_baseline and native is not None:
self.ordinary_warning_retained = False
self.ever_lateral_active = True
if cp.brand == 'subaru' and self.availability_producer:
self.subaru_lateral_grant_ns = max(self.subaru_lateral_grant_ns, int(native.observedMonoTime))
self.subaru_braked_main = None
self.subaru_eps_brake_event_ns = 0
self.lag_withdrawal_ns = 0
+1 -1
View File
@@ -118,7 +118,7 @@ def retain_braked_main_intent(feedback, sm, cp, state, axis, now_ns, *, arm_ns,
pending = feedback.subaru_braked_main
epoch = int(axis.intentIntegrityEpoch)
if (cp.carFingerprint != CAR.SUBARU_IMPREZA_2020 or not qualified(cp, marked_only=True) or
feedback.failed or feedback.paused or feedback.pending_event or feedback.ever_lateral_active or
feedback.failed or feedback.paused or feedback.pending_event or arm_ns <= feedback.subaru_lateral_grant_ns or
not producer or axis.intentProducerSessionId != producer or
not 0 < arm_ns <= axis.sourceCarStateMonoTime <= now_ns or
str(axis.faultReason) != 'none' or not axis.nativeAcknowledged or not axis.desiredLateral or axis.lateralActive or
@@ -27,7 +27,7 @@ def test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(candidate,
deadline_gap=False, fixed_angle_handoff=False, host_first_stop=False,
source_outage=False, vm_angle_handoff=0, crawl=False, eps_brake_join=False,
high_angle_guard=False, main_on_brake=False, guard_brake_release=False,
stopped_feedback_gap=False):
stopped_feedback_gap=False, rearm_on_brake=0):
angle_handoff = fixed_angle_handoff or vm_angle_handoff
fw = firmware_records(candidate, FW_VERSIONS, 'subaru') if firmware is None else firmware
rows = []
@@ -42,6 +42,10 @@ def test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(candidate,
expected_word = (4096 if aol else 0) | (512 if prefs.get('SubaruRedneckCruise') else 0) | (8 if prefs.get('SubaruSNG') else 0)
assert cp.safetyConfigs[0].safetyParam == expected_word
assert cp.autoResumeSng == bool(prefs.get('SubaruSNG'))
if rearm_on_brake:
params.put_bool('PauseLateralOnSignal', True, block=True)
params.put('PauseLateralSpeed', 100., block=True)
params.put('LateralResumeDelay', 0., block=True)
sd, controls = SelfdriveD(CP=cp), Controls()
stream = CompleteCan(ci)
safety.init_tests()
@@ -77,7 +81,8 @@ def test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(candidate,
now += 3_919_864
cruise = not main_only and (30 <= tick < 110 or tick >= 410)
brake = (stopped_feedback_gap and 125 <= tick < 135 or 90 <= tick < 110 or eps_brake_join and 225 <= tick < 270 or
main_on_brake and 30 <= tick < 55 or guard_brake_release and 225 <= tick < 245)
main_on_brake and 30 <= tick < 55 or guard_brake_release and 225 <= tick < 245 or
rearm_on_brake and 345 <= tick < 365)
reverse = 150 <= tick < 185
temporary = not guard_brake_release and 225 <= tick < 260
main = not 310 <= tick < 350 and (tick >= 30 or not main_only)
@@ -100,6 +105,9 @@ def test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(candidate,
'ES_DashStatus': {'Cruise_On': int(main), 'Cruise_Set_Speed': 100},
'Transmission': {'Gear': 3 if reverse else 121},
}
if rearm_on_brake in (1, 2):
values['Dashlights'] = {'LEFT_BLINKER': int(rearm_on_brake == 1 and 340 <= tick < 355),
'RIGHT_BLINKER': int(rearm_on_brake == 2 and 340 <= tick < 355)}
if high_angle_guard:
values['Brake_Pedal'] = {'Speed': 8}
values['Brake_Pressure_L_R'] = {'Steering_Angle': 101 if 110 <= tick < 120 else 83 if 120 <= tick < 125 else 0}
@@ -330,7 +338,13 @@ def test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(candidate,
main_rearm = aol and candidate in (CAR.SUBARU_CROSSTREK_2025, CAR.SUBARU_IMPREZA_2020, CAR.SUBARU_OUTBACK_2023)
if 330 <= tick < (350 if main_rearm else 400):
assert not command.latActive and not bool(intent and intent.allowedLatch), row
if main_rearm and 375 <= tick < 400:
if rearm_on_brake and 355 <= tick < 365:
assert row['cardLatch'] and row['armed'] and not row['lat'] and row['permission'] == 0, ('SUBARU_REPEAT_BRAKED_MAIN_LOST', row)
if rearm_on_brake in (1, 2) and 355 <= tick < 400:
assert cs.leftBlinker or cs.rightBlinker, row
assert row['cardLatch'] and row['armed'] and not row['lat'] and not row['long'], ('SUBARU_SIGNAL_PAUSE_LOST_INTENT', row)
assert all(not frame['request'] and frame['output'] == 0 and frame['nativeAccepted'] for frame in row['steering']), row
if main_rearm and 375 <= tick < 400 and rearm_on_brake not in (1, 2):
assert command.latActive and row['cardLatch'] and row['permission'] == 1 and not row['controls'], row
if tick >= 440:
assert command.latActive and bool(intent and intent.allowedLatch) == aol and row['permission'] == int(aol), row
@@ -512,3 +526,9 @@ def test_actual_stopped_feedback_gap_retains_only_armed_intent(subaru_native_pai
test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(
CAR.SUBARU_IMPREZA_2020, subaru_native_pair, tmp_path, main_only=True,
stop_resume=True, hard_stop_native_first=True, stopped_feedback_gap=True)
@pytest.mark.parametrize('signal', (1, 2, 3))
def test_actual_repeat_main_with_brake_and_signal_pause(subaru_native_pair, tmp_path, signal):
test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(
CAR.SUBARU_IMPREZA_2020, subaru_native_pair, tmp_path, main_only=True, rearm_on_brake=signal)
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "39aee5e95e82545cafe70d7850d760f70b88c0c23f6bdde8e03c30a02d283b2e", "schema_version": 1}
{"protected_inventory_sha256": "dc0113a767a21134cbc514b2f55ac2643b0712a264d0473634970dbe4fe4193b", "schema_version": 1}
+1
View File
@@ -273,6 +273,7 @@ DEBUG_SAFETY_CLASS_TARGETS = {
RELEASE_TARGETS = (
"openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py::test_actual_stopped_feedback_gap_retains_only_armed_intent",
"openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py::test_actual_repeat_main_with_brake_and_signal_pause",
"openpilot/starpilot/aol/tests/test_subaru_temporary_eps.py",
"opendbc_repo/opendbc/car/subaru/tests/test_jacobw_angle.py",
"opendbc_repo/opendbc/car/rivian/tests/test_radar_reachability.py",