Preserve Honda AOL through EPS re-pulses and brake release

This commit is contained in:
Dom
2026-11-18 10:45:13 -06:00
parent 8117682bc1
commit a5e4b31dd8
4 changed files with 235 additions and 23 deletions
+46 -14
View File
@@ -74,11 +74,14 @@ def temporary_steering_intent_current(self, sm, cp, cs, axis, stamp, now_ns, *,
structs.CarState.GearShifter.low, structs.CarState.GearShifter.brake) and
cs.cruiseState.available and not cs.accFaulted and not cs.doorOpen and
not cs.vehicleSensorsInvalid and not cs.steeringDisengage and not cs.buttonEvents)
honda_brake_release = bool(honda_eps and not cs.brakePressed and
0 < event_ns == self.temporary_eps_event_ns == getattr(self, 'honda_eps_brake_event_ns', 0) and
0 < getattr(self, 'honda_eps_source_ns', 0) <= now_ns <= self.honda_eps_source_ns + SAFETY_MAX_AGE_NS)
# Seatbelt blocks normal LONG, not admitted LAT intent. Keep warnings/native/output checks.
events = tuple(event for event in sm['onroadEvents'] if not (
stock_eps_user and event.name == stock_user and event.userDisable and
not event.softDisable and not event.immediateDisable) and not (
(subaru_brake or honda_eps and cs.brakePressed) and
(subaru_brake or honda_eps and (cs.brakePressed or honda_brake_release)) and
event.name == log.OnroadEvent.EventName.pedalPressed and event.userDisable and
not event.softDisable and not event.immediateDisable) and not (
self.lateral_only_baseline and cs.seatbeltUnlatched and not axis.desiredLongitudinal and
@@ -184,6 +187,8 @@ def temporary_steering_intent_current(self, sm, cp, cs, axis, stamp, now_ns, *,
self.volkswagen_eps_source_ns = int(axis.sourceCarStateMonoTime)
if subaru_brake and cs.brakePressed:
self.subaru_eps_brake_event_ns = event_ns
if honda_eps and cs.brakePressed and (matched_withdrawal or held_original):
self.honda_eps_brake_event_ns = event_ns
if honda_eps and matched_withdrawal:
self.honda_eps_source_ns = int(axis.sourceCarStateMonoTime)
if cs.steerFaultTemporary and matched_withdrawal:
@@ -203,7 +208,7 @@ def temporary_steering_intent_current(self, sm, cp, cs, axis, stamp, now_ns, *,
def honda_eps_recovery_intent_current(self, sm, cp, cs, axis, stamp, now_ns, *, latched, producer):
"""Join a cleared physical EPS sample to its still-withdrawn producer proof.
"""Join physical EPS transitions to their still-withdrawn producer proof.
Only existing intent survives, for at most the original native lease window
after the observed EPS source. Neither native permission nor output is granted.
@@ -215,39 +220,66 @@ def honda_eps_recovery_intent_current(self, sm, cp, cs, axis, stamp, now_ns, *,
source = getattr(self, 'honda_eps_source_ns', 0)
previous = self.signature
first_native_eps = bool(cs.steerFaultTemporary and axis.desiredLateral and
previous is not None and previous[5] == 'none' and previous[9] and previous[11] and previous[13] and
0 < previous[8] <= previous[2] <= now_ns <= previous[4] and
now_ns - previous[8] <= SAFETY_MAX_AGE_NS)
known_eps = bool(source and self.temporary_eps_event_ns)
if first_native_eps and (not known_eps or self.lateral_source_ns > source):
source = previous[8]
known_eps = False
event_successor = bool(known_eps and previous is not None and
self.temporary_eps_event_ns <= previous[6] <= axis.faultEventMonoTime and
0 < axis.faultEventMonoTime <= stamp and now_ns - axis.faultEventMonoTime <= AXIS_MAX_AGE_NS)
if (cp.brand != 'honda' or not qualified(cp, marked_only=True) or
not latched or self.failed or self.paused or self.pending_event or self.retention_started_ns or
not self.lateral_only_baseline or not self.lateral_inventory or not self.lateral_baseline_ns or
not 0 < source <= now_ns or now_ns - source > SAFETY_MAX_AGE_NS or
not self.temporary_eps_event_ns or previous is None or
previous[5] != 'none' or previous[9] or previous[10] or previous[12] or
previous[6] != self.temporary_eps_event_ns or
not (known_eps or first_native_eps) or previous is None or
previous[5] != 'none' or (previous[9] and not first_native_eps) or previous[10] or previous[12] or
(previous[6] != self.temporary_eps_event_ns and not (first_native_eps or event_successor)) or
not self.session or str(axis.sessionId) != self.session or
not producer or producer != self.availability_producer or
str(axis.intentProducerSessionId) != producer or int(axis.intentIntegrityEpoch) != self.availability_epoch or
previous[14:16] != (producer, self.availability_epoch) or
not cs.canValid or cs.canTimeout or cs.steerFaultTemporary or cs.steerFaultPermanent or
not cs.canValid or cs.canTimeout or (cs.steerFaultTemporary and not axis.desiredLateral) or cs.steerFaultPermanent or
cs.accFaulted or cs.doorOpen or cs.seatbeltUnlatched or cs.vehicleSensorsInvalid or cs.steeringDisengage or
cs.brakePressed or cs.regenBraking or cs.buttonEvents or not cs.cruiseState.available or cs.cruiseState.enabled or
(cs.brakePressed and not cs.steerFaultTemporary) or cs.regenBraking or cs.buttonEvents or not cs.cruiseState.available or cs.cruiseState.enabled or
cs.gearShifter not in (structs.CarState.GearShifter.drive, structs.CarState.GearShifter.sport,
structs.CarState.GearShifter.low, structs.CarState.GearShifter.brake) or
str(axis.faultReason) != 'none' or str(axis.mode) != 'off' or not axis.nativeAcknowledged or
axis.lateralActive or axis.longitudinalActive or axis.desiredLongitudinal or
str(axis.faultReason) != 'none' or
str(axis.mode) != ('lateralOnly' if first_native_eps and axis.lateralActive else 'off') or
not axis.nativeAcknowledged or
(axis.lateralActive and not first_native_eps) or axis.longitudinalActive or axis.desiredLongitudinal or
not source <= axis.sourceCarStateMonoTime <= stamp <= now_ns or
axis.sourceCarStateMonoTime < previous[8] or stamp < previous[2] or
now_ns - axis.sourceCarStateMonoTime > AXIS_MAX_AGE_NS or
axis.faultEventMonoTime != self.temporary_eps_event_ns or
axis.faultEventMonoTime < previous[6] or
(axis.faultEventMonoTime != self.temporary_eps_event_ns and not (first_native_eps or event_successor)) or
not sm.seen['onroadEvents'] or not sm.valid['onroadEvents'] or not sm.alive['onroadEvents']):
return False
events = sm['onroadEvents']
event_ns = int(sm.logMonoTime['onroadEvents'])
if (event_ns != self.temporary_eps_event_ns or not 0 < event_ns <= stamp or
brake_release = bool(known_eps and not cs.brakePressed and
event_ns == self.temporary_eps_event_ns == getattr(self, 'honda_eps_brake_event_ns', 0))
events = tuple(e for e in sm['onroadEvents'] if not (
(cs.steerFaultTemporary and cs.brakePressed or brake_release) and
e.name == log.OnroadEvent.EventName.pedalPressed and e.userDisable and
not e.softDisable and not e.immediateDisable))
if (event_ns != axis.faultEventMonoTime or not 0 < event_ns <= stamp or
now_ns - event_ns > 1_500_000_000 or
any(e.immediateDisable or e.userDisable or e.softDisable and
e.name != log.OnroadEvent.EventName.steerTempUnavailable for e in events)):
return False
native = _configured_transport_native(sm, cp, self.session, now_ns, allow_restricted_lateral=True)
return bool(native is not None and native.pandaInventory and native.requestedLateral and
not native.lateralAllowed and not native.requestedLongitudinal and not native.longitudinalAllowed and
retained = bool(native is not None and native.pandaInventory and (native.requestedLateral or known_eps) and
(not native.lateralAllowed or first_native_eps and axis.lateralActive and native.requestedLateral) and
not native.requestedLongitudinal and not native.longitudinalAllowed and
native.observedMonoTime >= self.lateral_native_ns and
self.lateral_inventory == (native.pandaSerial, tuple(p.hardwareSerial for p in native.pandaInventory)))
if retained:
if first_native_eps and not known_eps:
self.honda_eps_source_ns = source
self.temporary_eps_event_ns = event_ns
if cs.steerFaultTemporary and cs.brakePressed:
self.honda_eps_brake_event_ns = event_ns
return retained
@@ -132,3 +132,174 @@ def test_recovery_rejects_higher_sequence_with_rolled_back_source():
change(sm, 'aolAxisState', lambda a: setattr(a, 'sequence', a.sequence + 1))
change(sm, 'aolAxisState', lambda a: setattr(a, 'sourceCarStateMonoTime', stamp))
assert observe(case, stamp + 20_000_000)
_cleared_recovery_case = recovery_case
def pending_request_case(*, first=False, requested=True, new_event=False):
if first:
cp, state, feedback, _, _ = baseline()
stamp = NOW + 10_000_000
sm, native = eps_sample(cp, stamp, withdrawn=False)
change(sm, 'aolAxisState', lambda a: setattr(a, 'lateralActive', False))
change(sm, 'aolAxisState', lambda a: setattr(a, 'mode', 'off'))
else:
cp, state, feedback, sm, native, stamp = _cleared_recovery_case()
event = sm.messages['aolAxisState'].as_builder()
event.logMonoTime = stamp + 10_000_000
axis = event.aolAxisState
axis.sequence += 1
axis.observedMonoTime = axis.sourceCarStateMonoTime = stamp + 10_000_000
axis.validUntilMonoTime = stamp + 40_000_000
axis.desiredLateral = True
if new_event:
axis.faultEventMonoTime = stamp + 10_000_000
events = sm.messages['onroadEvents'].as_builder()
events.logMonoTime = axis.faultEventMonoTime
sm.messages['onroadEvents'] = events.as_reader()
sm.logMonoTime['onroadEvents'] = int(events.logMonoTime)
sm.messages['aolAxisState'] = event.as_reader()
sm.logMonoTime['aolAxisState'] = int(event.logMonoTime)
native = native_change(sm, native, requestedLateral=requested)
state.steerFaultTemporary = state.steeringPressed = True
return cp, state, feedback, sm, native, stamp
@pytest.mark.parametrize('first,requested,new_event', [(True, True, False),
(False, True, False), (False, False, False), (False, False, True)])
def test_native_first_and_repeated_eps_retain_only_current_latched_intent(first, requested, new_event):
case = pending_request_case(first=first, requested=requested, new_event=new_event)
_, state, feedback, _, native, stamp = case
leases = feedback.lateral_baseline_ns, feedback.lateral_source_ns, feedback.lateral_native_ns
assert not observe(case, stamp + 10_000_000)
assert not feedback.failed
assert not output(state, native).lateral_active
assert leases == (feedback.lateral_baseline_ns, feedback.lateral_source_ns, feedback.lateral_native_ns)
@pytest.mark.parametrize('first', [False, True])
@pytest.mark.parametrize('fault', ['regen', 'permanent', 'can', 'timeout', 'door', 'belt',
'sensor', 'disengage', 'main', 'reverse', 'user_event', 'hard_event', 'wrong_session', 'wrong_producer',
'wrong_epoch', 'wrong_profile', 'native_stale', 'native_missing', 'native_fault', 'native_rx',
'native_heartbeat', 'native_inventory', 'native_long', 'axis_stale', 'no_eps_source', 'expired_source'])
def test_pending_eps_request_preserves_all_independent_vetoes(first, fault, monkeypatch):
import sys
def case_for_fault():
case = pending_request_case(first=first, requested=first)
if first and fault == 'expired_source':
previous = list(case[2].signature)
previous[4] = case[5] - 1
case[2].signature = tuple(previous)
if first and fault == 'no_eps_source':
previous = list(case[2].signature)
previous[9] = False
case[2].signature = tuple(previous)
return case
monkeypatch.setattr(sys.modules[__name__], 'recovery_case', case_for_fault)
test_recovery_join_does_not_bypass_independent_vetoes(fault)
def braked_eps_case():
cp, state, feedback, _, _ = baseline()
state.steerFaultTemporary = state.steeringPressed = state.brakePressed = True
stamp = NOW + 10_000_000
sm, native = eps_sample(cp, stamp, withdrawn=True, brake=True)
assert not feedback.observe(sm, cp, state, stamp, latched=True, intent_producer_session=PRODUCER)
return cp, state, feedback, sm, native, stamp
@pytest.mark.parametrize('cleared_eps', [False, True])
def test_brake_release_joins_only_its_previously_observed_eps_pedal_event(cleared_eps):
case = braked_eps_case()
_, state, feedback, _, native, stamp = case
state.brakePressed = False
state.steerFaultTemporary = not cleared_eps
leases = feedback.lateral_baseline_ns, feedback.lateral_source_ns, feedback.lateral_native_ns
assert not observe(case, stamp + 10_000_000)
assert not output(state, native).lateral_active
assert leases == (feedback.lateral_baseline_ns, feedback.lateral_source_ns, feedback.lateral_native_ns)
@pytest.mark.parametrize('fault', ['unobserved_brake', 'expired_source', 'new_pedal_event'])
def test_brake_release_cannot_borrow_unmatched_or_expired_eps_history(fault):
case = braked_eps_case()
_, state, feedback, sm, _, stamp = case
state.brakePressed = False
if fault == 'unobserved_brake':
feedback.honda_eps_brake_event_ns = 0
elif fault == 'expired_source':
feedback.honda_eps_source_ns = stamp - 201_000_000
else:
event = sm.messages['onroadEvents'].as_builder()
event.logMonoTime = stamp + 5_000_000
sm.messages['onroadEvents'] = event.as_reader()
sm.logMonoTime['onroadEvents'] = int(event.logMonoTime)
change(sm, 'aolAxisState', lambda a: setattr(a, 'faultEventMonoTime', stamp + 5_000_000))
assert observe(case, stamp + 10_000_000)
@pytest.mark.parametrize('first', [False, True])
def test_pending_eps_with_current_brake_still_denies_all_output(first):
case = pending_request_case(first=first, requested=first)
_, state, feedback, sm, native, stamp = case
state.brakePressed = True
event = sm.messages['onroadEvents'].as_builder()
event.onroadEvents = [*(e.to_dict()for e in event.onroadEvents),
{'name':'pedalPressed','userDisable':True}]
sm.messages['onroadEvents'] = event.as_reader()
assert not observe(case, stamp + 10_000_000)
assert not feedback.failed and not output(state, native).lateral_active
@pytest.mark.parametrize('brake', [False, True])
@pytest.mark.parametrize('source_lag', [0, 20_000_000])
def test_fresh_active_publication_during_eps_keeps_only_intent(brake, source_lag):
case = pending_request_case(first=True)
_, state, feedback, sm, native, stamp = case
state.brakePressed = brake
previous = list(feedback.signature)
previous[8] -= source_lag
feedback.signature = tuple(previous)
feedback.lateral_source_ns -= source_lag
change(sm, 'aolAxisState', lambda a: setattr(a, 'lateralActive', True))
change(sm, 'aolAxisState', lambda a: setattr(a, 'mode', 'lateralOnly'))
native = native_change(sm, native, lateralAllowed=True)
before = feedback.lateral_baseline_ns, feedback.lateral_source_ns, feedback.lateral_native_ns
assert not observe(case, stamp + 10_000_000)
assert not output(state, native).lateral_active
assert before == (feedback.lateral_baseline_ns, feedback.lateral_source_ns, feedback.lateral_native_ns)
@pytest.mark.parametrize('new_pulse', [False, True])
def test_clean_event_update_during_pending_eps_recovery_does_not_erase_intent(new_pulse):
case = pending_request_case(requested=False, new_event=True)
_, state, feedback, _, native, stamp = case
state.steerFaultTemporary = new_pulse
source = feedback.honda_eps_source_ns
assert not observe(case, stamp + 10_000_000)
assert feedback.honda_eps_source_ns == source
assert not output(state, native).lateral_active
def test_unexplained_native_denial_without_physical_eps_still_revokes_intent():
case = pending_request_case(first=True)
_, state, _, _, _, stamp = case
state.steerFaultTemporary = False
assert observe(case, stamp + 10_000_000)
def test_fresh_history_cannot_replace_an_expired_current_source():
case = pending_request_case(first=True)
_, _, _, sm, _, stamp = case
change(sm, 'aolAxisState', lambda a: setattr(a, 'sourceCarStateMonoTime', NOW - 50_000_000))
assert observe(case, stamp + 10_000_000)
def test_new_eps_episode_uses_its_new_actual_active_predecessor():
case = pending_request_case(first=True)
_, state, feedback, _, native, stamp = case
feedback.honda_eps_source_ns = NOW - 10_000_000_000
assert not observe(case, stamp + 10_000_000)
assert feedback.honda_eps_source_ns == NOW
assert not output(state, native).lateral_active
@@ -62,6 +62,14 @@ class TestHondaCurrentCaller(unittest.TestCase):
self.run_current_caller(candidate=CAR.HONDA_CIVIC_2022, word=10, alpha=True, hybrid=True,
eps_pedal='gas', eps_end=82)
def test_radarless_alpha_repeated_eps_before_native_refresh(self):
self.run_current_caller(candidate=CAR.HONDA_CIVIC_2022, word=10, alpha=True, hybrid=True,
eps_pedal='gas', eps_end=82, eps_repeat=(85, 88))
def test_radarless_alpha_repeated_eps_with_brake_before_native_refresh(self):
self.run_current_caller(candidate=CAR.HONDA_CIVIC_2022, word=10, alpha=True, hybrid=True,
eps_pedal='brake', eps_end=82, eps_repeat=(85, 88))
def test_diagnostic_during_recovered_reverse(self):
self.run_current_caller(candidate=CAR.HONDA_CIVIC_BOSCH, word=0, fault='diagnostic')
@@ -69,7 +77,7 @@ class TestHondaCurrentCaller(unittest.TestCase):
self.run_current_caller(candidate=CAR.HONDA_CIVIC_BOSCH, word=0, fault='relay')
def run_current_caller(self, *, candidate, word, fault=None, alternate_brake=False, alpha=False, speed_mps=12.5,
pedal=False, host_scenario=None, serialized=False, eps_pedal=None, hybrid=False, eps_end=95):
pedal=False, host_scenario=None, serialized=False, eps_pedal=None, hybrid=False, eps_end=95, eps_repeat=None):
safety = libsafety_py.libsafety
with (
OpenpilotPrefix(),
@@ -171,13 +179,14 @@ class TestHondaCurrentCaller(unittest.TestCase):
card.aol_card_intent.settings = read_settings(saved)
sd.aol_settings = read_settings(saved)
# SET press/release is the real first ordinary native grant, preceding engaged HB.
eps_active = 80 <= tick < eps_end or eps_repeat is not None and eps_repeat[0] <= tick < eps_repeat[1]
incoming = stream.frames(
cruise_button=2 if host_scenario == 'cancel' and tick == 40 else
3 if tick == 20 or host_scenario == 'long_reengage' and tick == 130 else 0,
cruise=int(21 <= tick < 50 and not cancelled or reengage),
brake=50 <= tick < 55 or eps_pedal == 'brake' and 80 <= tick < eps_end,
eps=(2 if eps_pedal else 6) if 80 <= tick < eps_end else 0,
gas=20 if eps_pedal == 'gas' and 80 <= tick < eps_end else 0,
brake=50 <= tick < 55 or eps_pedal == 'brake' and eps_active,
eps=(2 if eps_pedal else 6) if eps_active else 0,
gas=20 if eps_pedal == 'gas' and eps_active else 0,
steering_torque=1301 if eps_pedal and 80 <= tick < 95 else 0,
gear=2 if 110 <= tick < 125 else None,
lkas=0, speed_kph=speed_mps * 3.6,
@@ -271,9 +280,9 @@ class TestHondaCurrentCaller(unittest.TestCase):
self.assertAlmostEqual(cs.vEgoRaw, speed_mps, places=5)
self.assertFalse(cs.standstill or cs.seatbeltUnlatched)
self.assertFalse(cs.steerFaultPermanent)
self.assertEqual(cs.steerFaultTemporary, 80 <= tick < eps_end)
self.assertEqual(cs.steerFaultTemporary, eps_active)
self.assertEqual(cs.gearShifter, structs.CarState.GearShifter.reverse if 110 <= tick < 125 else structs.CarState.GearShifter.drive)
self.assertEqual(cs.brakePressed, 50 <= tick < 55 or eps_pedal == 'brake' and 80 <= tick < eps_end)
self.assertEqual(cs.brakePressed, 50 <= tick < 55 or eps_pedal == 'brake' and eps_active)
self.assertTrue(cs.cruiseState.available)
self.assertEqual(cs.cruiseState.enabled, 21 <= tick < 50 and not cancelled or reengage)
intent = decode_intent(published['aolIntentWire'].aolIntentWire)
@@ -406,7 +415,7 @@ class TestHondaCurrentCaller(unittest.TestCase):
self.assertTrue(command.latActive, row)
self.assertTrue(any(t.get('accepted') and t.get('request') and t.get('torque') for t in row['TX']), row)
self.assertTrue(intent.allowedLatch, row)
if eps_pedal and 82 <= tick < eps_end:
if eps_pedal and tick >= 82 and eps_active:
self.assertTrue(cs.steerFaultTemporary and cs.steeringPressed, row)
self.assertTrue(cs.brakePressed if eps_pedal == 'brake' else cs.gasPressed, row)
self.assertTrue(card.aol_card_intent.allowed_latch, row)
@@ -417,7 +426,7 @@ class TestHondaCurrentCaller(unittest.TestCase):
self.assertFalse(command.latActive or command.longActive, row)
self.assertFalse(row['permission'] & 1, row)
if eps_end == 82 and 82 <= tick < 90:
self.assertFalse(cs.steerFaultTemporary, row)
self.assertEqual(cs.steerFaultTemporary, eps_active, row)
self.assertTrue(intent.allowedLatch, row)
self.assertFalse(command.latActive or command.longActive, row)
if eps_end == 82 and tick == 95:
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "bd066f25463a1a5f4a53a71e32270a07f76cc89451e6d29e249eaddca537313a", "schema_version": 1}
{"protected_inventory_sha256": "9f554965ee4157d295a6b8aa31627dfc635973fdcfeaee6bd47d787c10efb5be", "schema_version": 1}