Preserve Honda AOL across stock ACC EPS recovery boundaries

This commit is contained in:
Dom
2026-11-18 15:30:58 -06:00
4 changed files with 148 additions and 11 deletions
+15 -8
View File
@@ -216,7 +216,7 @@ def honda_eps_recovery_intent_current(self, sm, cp, cs, axis, stamp, now_ns, *,
"""
from opendbc.car.honda.stock_aol import qualified
from opendbc.car import structs
from openpilot.starpilot.aol.transport_pause import _configured_transport_native
from openpilot.starpilot.aol.transport_pause import _configured_transport_native, stock_lateral_user_event
source = getattr(self, 'honda_eps_source_ns', 0)
previous = self.signature
@@ -228,6 +228,10 @@ def honda_eps_recovery_intent_current(self, sm, cp, cs, axis, stamp, now_ns, *,
if first_native_eps and (not known_eps or self.lateral_source_ns > source):
source = previous[8]
known_eps = False
event_ns = int(sm.logMonoTime['onroadEvents'])
active_recovery = bool(known_eps and cs.steerFaultTemporary and axis.desiredLateral and axis.lateralActive)
brake_continuation = bool(known_eps and cs.brakePressed and
event_ns == self.temporary_eps_event_ns == getattr(self, 'honda_eps_brake_event_ns', 0))
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)
@@ -236,7 +240,7 @@ def honda_eps_recovery_intent_current(self, sm, cp, cs, axis, stamp, now_ns, *,
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 (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[5] != 'none' or (previous[9] and not (first_native_eps or active_recovery)) 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
@@ -244,13 +248,14 @@ def honda_eps_recovery_intent_current(self, sm, cp, cs, axis, stamp, now_ns, *,
previous[14:16] != (producer, self.availability_epoch) 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 and not cs.steerFaultTemporary) or cs.regenBraking or cs.buttonEvents or not cs.cruiseState.available or cs.cruiseState.enabled or
(cs.brakePressed and not cs.steerFaultTemporary and not brake_continuation) or
cs.regenBraking or cs.buttonEvents or not cs.cruiseState.available or cs.cruiseState.enabled and not cp.pcmCruise 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) != ('lateralOnly' if first_native_eps and axis.lateralActive else 'off') or
str(axis.mode) != ('lateralOnly' if (first_native_eps or active_recovery) and axis.lateralActive else 'off') or
not axis.nativeAcknowledged or
(axis.lateralActive and not first_native_eps) or axis.longitudinalActive or axis.desiredLongitudinal or
(axis.lateralActive and not (first_native_eps or active_recovery)) 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
@@ -258,11 +263,12 @@ def honda_eps_recovery_intent_current(self, sm, cp, cs, axis, stamp, now_ns, *,
(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
event_ns = int(sm.logMonoTime['onroadEvents'])
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))
stock_user = stock_lateral_user_event(cp) if not cs.cruiseState.enabled else None
events = tuple(e for e in sm['onroadEvents'] if not (
(cs.steerFaultTemporary and cs.brakePressed or brake_release) and
e.name == stock_user and e.userDisable and not e.softDisable and not e.immediateDisable) and not (
(cs.steerFaultTemporary and cs.brakePressed or brake_continuation 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
@@ -272,7 +278,7 @@ def honda_eps_recovery_intent_current(self, sm, cp, cs, axis, stamp, now_ns, *,
return False
native = _configured_transport_native(sm, cp, self.session, now_ns, allow_restricted_lateral=True)
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.lateralAllowed or native.requestedLateral and (known_eps or first_native_eps and axis.lateralActive)) 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)))
@@ -283,3 +289,4 @@ def honda_eps_recovery_intent_current(self, sm, cp, cs, axis, stamp, now_ns, *,
if cs.steerFaultTemporary and cs.brakePressed:
self.honda_eps_brake_event_ns = event_ns
return retained
@@ -303,3 +303,112 @@ def test_new_eps_episode_uses_its_new_actual_active_predecessor():
assert not observe(case, stamp + 10_000_000)
assert feedback.honda_eps_source_ns == NOW
assert not output(state, native).lateral_active
def stock_acc_recovery_case(identity='HONDA_CIVIC_BOSCH', cruise_enabled=False):
from opendbc.car.honda.tests.test_stock_aol import final_cp
from opendbc.car.honda.values import CAR
from openpilot.starpilot.aol.transport_pause import TransportPauseFeedback
from openpilot.starpilot.tests.test_ford_reverse_intent import sample
cp = final_cp(getattr(CAR, identity))
cp.alternativeExperience = 32
state = structs.CarState(canValid=True, gearShifter='drive', vEgo=15.)
state.cruiseState.available = True
state.cruiseState.enabled = cruise_enabled
feedback = TransportPauseFeedback(cp)
sm, _ = sample(cp, NOW, NOW, 1)
change(sm, 'onroadEvents', lambda events: setattr(events[0], 'userDisable', False))
assert not feedback.observe(sm, cp, state, NOW, latched=True, intent_producer_session=PRODUCER)
assert feedback.lateral_only_baseline
stamp = NOW + 10_000_000
state.steerFaultTemporary = state.steeringPressed = True
sm, native = eps_sample(cp, stamp, withdrawn=True)
event = sm.messages['onroadEvents'].as_builder()
if not cruise_enabled:
event.onroadEvents = [*(e.to_dict() for e in event.onroadEvents), {'name': 'cruiseDisabled', 'userDisable': True}]
sm.messages['onroadEvents'] = event.as_reader()
assert not feedback.observe(sm, cp, state, stamp, latched=True, intent_producer_session=PRODUCER)
state.steerFaultTemporary = False
return cp, state, feedback, sm, native, stamp
@pytest.mark.parametrize('identity', ['HONDA_CIVIC_BOSCH', 'HONDA_CIVIC', 'HONDA_CIVIC_2022', 'HONDA_CRV_6G'])
@pytest.mark.parametrize('cruise_enabled', [False, True])
def test_stock_acc_eps_recovery_uses_lateral_owner_event_policy(identity, cruise_enabled):
cp, state, feedback, sm, native, stamp = stock_acc_recovery_case(identity, cruise_enabled)
lease = feedback.lateral_source_ns, feedback.lateral_native_ns, feedback.honda_eps_source_ns
assert not feedback.observe(sm, cp, state, stamp + 10_000_000, latched=True, intent_producer_session=PRODUCER)
assert not feedback.failed and not output(state, native).lateral_active
assert lease == (feedback.lateral_source_ns, feedback.lateral_native_ns, feedback.honda_eps_source_ns)
event = sm.messages['onroadEvents'].as_builder()
event.onroadEvents = [*(e.to_dict() for e in event.onroadEvents), {'name': 'buttonCancel', 'userDisable': True}]
sm.messages['onroadEvents'] = event.as_reader()
assert feedback.observe(sm, cp, state, stamp + 20_000_000, latched=True, intent_producer_session=PRODUCER)
@pytest.mark.parametrize('flag', ['softDisable', 'immediateDisable'])
def test_stock_cruise_disabled_fault_flags_remain_authoritative(flag):
case = stock_acc_recovery_case()
_, _, _, sm, _, stamp = case
event = sm.messages['onroadEvents'].as_builder()
event.onroadEvents = [{'name': 'cruiseDisabled', 'userDisable': True, flag: True}]
sm.messages['onroadEvents'] = event.as_reader()
assert observe(case, stamp + 10_000_000)
def test_native_grant_before_host_recovery_does_not_erase_original_eps_baseline():
case = stock_acc_recovery_case()
cp, state, feedback, sm, native, stamp = case
change(sm, 'aolAxisState', lambda a: setattr(a, 'desiredLateral', True))
change(sm, 'aolAxisState', lambda a: setattr(a, 'sequence', a.sequence + 1))
native = native_change(sm, native, requestedLateral=True, lateralAllowed=True)
lease = feedback.lateral_baseline_ns, feedback.lateral_source_ns, feedback.lateral_native_ns, feedback.honda_eps_source_ns
assert not observe(case, stamp + 10_000_000)
assert lease == (feedback.lateral_baseline_ns, feedback.lateral_source_ns, feedback.lateral_native_ns, feedback.honda_eps_source_ns)
# The host recovers from its clear sample while Card has already observed a new EPS pulse.
state.steerFaultTemporary = True
change(sm, 'aolAxisState', lambda a: setattr(a, 'sequence', a.sequence + 1))
change(sm, 'aolAxisState', lambda a: setattr(a, 'lateralActive', True))
change(sm, 'aolAxisState', lambda a: setattr(a, 'mode', 'lateralOnly'))
assert not observe(case, stamp + 20_000_000)
assert not output(state, native).lateral_active
assert lease == (feedback.lateral_baseline_ns, feedback.lateral_source_ns, feedback.lateral_native_ns, feedback.honda_eps_source_ns)
def test_brake_held_after_eps_clear_keeps_only_original_braked_episode():
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)
state.steerFaultTemporary = False
case = cp, state, feedback, sm, native, stamp
assert not observe(case, stamp + 10_000_000)
assert not output(state, native).lateral_active
assert feedback.honda_eps_source_ns == stamp
feedback.honda_eps_brake_event_ns = 0
assert observe(case, stamp + 20_000_000)
@pytest.mark.parametrize('fault', ['expired_source', 'wrong_producer', 'native_fault', 'native_long'])
def test_recovered_native_grant_does_not_override_independent_vetoes(fault):
case = stock_acc_recovery_case()
_, state, feedback, sm, native, stamp = case
state.steerFaultTemporary = True
change(sm, 'aolAxisState', lambda a: setattr(a, 'desiredLateral', True))
change(sm, 'aolAxisState', lambda a: setattr(a, 'sequence', a.sequence + 1))
change(sm, 'aolAxisState', lambda a: setattr(a, 'lateralActive', True))
change(sm, 'aolAxisState', lambda a: setattr(a, 'mode', 'lateralOnly'))
native = native_change(sm, native, requestedLateral=True, lateralAllowed=True)
if fault == 'expired_source':
feedback.honda_eps_source_ns = stamp - 201_000_000
elif fault == 'wrong_producer':
change(sm, 'aolAxisState', lambda a: setattr(a, 'intentProducerSessionId', 'different'))
elif fault == 'native_fault':
native_change(sm, native, pandaInventory=(replace(native.pandaInventory[0], faults=1),))
else:
native_change(sm, native, requestedLongitudinal=True)
assert observe(case, stamp + 10_000_000)
assert not output(state, native).lateral_active
@@ -70,6 +70,26 @@ class TestHondaCurrentCaller(unittest.TestCase):
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_classic_stock_repeated_eps_with_gas_before_native_refresh(self):
self.run_current_caller(candidate=CAR.HONDA_CIVIC_BOSCH, word=0,
eps_pedal='gas', eps_end=82, eps_repeat=(85, 88))
def test_classic_stock_repeated_eps_with_brake_before_native_refresh(self):
self.run_current_caller(candidate=CAR.HONDA_CIVIC_BOSCH, word=0,
eps_pedal='brake', eps_end=82, eps_repeat=(85, 88))
def test_nidec_stock_repeated_eps_with_gas_before_native_refresh(self):
self.run_current_caller(candidate=CAR.HONDA_CIVIC, word=0,
eps_pedal='gas', eps_end=82, eps_repeat=(85, 88))
def test_nidec_stock_repeated_eps_with_brake_before_native_refresh(self):
self.run_current_caller(candidate=CAR.HONDA_CIVIC, word=0,
eps_pedal='brake', eps_end=82, eps_repeat=(85, 88))
def test_classic_stock_brake_held_across_short_eps_recovery(self):
self.run_current_caller(candidate=CAR.HONDA_CIVIC_BOSCH, word=0,
eps_pedal='brake', eps_end=82, eps_brake_end=95)
def test_diagnostic_during_recovered_reverse(self):
self.run_current_caller(candidate=CAR.HONDA_CIVIC_BOSCH, word=0, fault='diagnostic')
@@ -77,7 +97,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, eps_repeat=None):
pedal=False, host_scenario=None, serialized=False, eps_pedal=None, hybrid=False, eps_end=95, eps_repeat=None, eps_brake_end=None):
safety = libsafety_py.libsafety
with (
OpenpilotPrefix(),
@@ -184,7 +204,7 @@ class TestHondaCurrentCaller(unittest.TestCase):
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 eps_active,
brake=50 <= tick < 55 or eps_pedal == 'brake' and (eps_active or eps_brake_end is not None and 80 <= tick < eps_brake_end),
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,
@@ -487,3 +507,4 @@ class TestHondaCurrentCaller(unittest.TestCase):
finally:
pandad.close()
card.vehicle_startup.close()
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "5881b7a9c7dcde8bde8f5676ba28c678e6da52231deb75cd07695d73519b3d49", "schema_version": 1}
{"protected_inventory_sha256": "050d6fe1b738f5e46c3c067c3a2b750926d5c8eaf0452d5df87c4266e5e59a70", "schema_version": 1}