mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-26 14:55:11 +08:00
Subaru AOL: manual-mode ratio gears pause output, not intent
In paddle/manual mode the Subaru transmission reports the simulated ratio instead of D, which parses as GearShifter.unknown. The generic disarming_fault() treated the resulting soft wrongGear event as a disarming fault and cleared the AOL latch; with no fresh MAIN edge on the return to Drive, AOL never resumed (pre-7.0 it resumed automatically). Add a Subaru-scoped intent_disarming_fault() that filters the soft wrongGear event for qualified cars at unknown gear, dispatched like the existing Volkswagen/Chrysler overrides. Output stays paused in manual mode through the normal runtime and panda gates; only the intent revocation is removed. Generic classification is unchanged. Tests: openpilot/starpilot/car/subaru/tests/test_aol_manual_gear.py
This commit is contained in:
@@ -186,4 +186,6 @@ def intent_disarming_fault(CP, events, state, **context):
|
||||
return volkswagen.intent_disarming_fault(CP, events, state, **context)
|
||||
if CP.brand == 'chrysler':
|
||||
return chrysler.intent_disarming_fault(CP, events, state, **context)
|
||||
if CP.brand == 'subaru':
|
||||
return subaru.intent_disarming_fault(CP, events, state, **context)
|
||||
return gm.intent_disarming_fault(CP, events, state, **context)
|
||||
|
||||
@@ -78,6 +78,28 @@ def policy_for(cp):
|
||||
safety_param_addition=IMPREZA_MAIN_AOL if admitted and cp.carFingerprint == CAR.SUBARU_IMPREZA_2020 else 0)
|
||||
|
||||
|
||||
def intent_disarming_fault(cp, events, state, **context):
|
||||
"""Manual-mode ratio gears read as GearShifter.unknown on stock Subarus.
|
||||
|
||||
The transmission reports the simulated ratio ("1"-"6") instead of "D" while
|
||||
paddle/manual mode is engaged, and GEAR_SHIFTER_MAP has no entry for those
|
||||
values, so gearShifter is unknown for the whole manual episode. That is a
|
||||
known non-driving gear: it pauses AOL output through the normal runtime
|
||||
gates, but it must not revoke the driver's latched intent, or AOL cannot
|
||||
resume on the return to Drive (no fresh MAIN edge occurs to re-arm it).
|
||||
Filter the soft wrongGear event for qualified cars in that state, the same
|
||||
way disarming_fault() already treats park/reverse/neutral; every other
|
||||
event keeps the generic classification.
|
||||
"""
|
||||
from openpilot.cereal import log
|
||||
from openpilot.starpilot.aol.intent import disarming_fault
|
||||
context.pop('startup_calibration_pending', False)
|
||||
if qualified(cp) and state.gearShifter == structs.CarState.GearShifter.unknown:
|
||||
events = [event for event in events if not (
|
||||
event.name == log.OnroadEvent.EventName.wrongGear and event.softDisable and not event.immediateDisable)]
|
||||
return disarming_fault(events, state, **context)
|
||||
|
||||
|
||||
def native_profile_supported(model, param):
|
||||
return model == int(structs.CarParams.SafetyModel.subaru) and param in (
|
||||
0, 1, 8, 16, 17, 145, 177, 209, 401, 465, 512, 520, 1169, 1425, 2225, 4096, 4104, 4608, 4616)
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
"""Regression tests: a Subaru paddle/manual-mode episode must pause AOL
|
||||
output without revoking the driver's latched AOL intent.
|
||||
|
||||
In manual mode the transmission Gear signal reports the simulated ratio
|
||||
("1"-"6") instead of "D". GEAR_SHIFTER_MAP has no entry for the ratios, so
|
||||
CarState.gearShifter is GearShifter.unknown for the whole episode. Before
|
||||
this fix, the generic disarming_fault() treated the resulting soft
|
||||
wrongGear event at unknown gear as a disarming fault, clearing the AOL
|
||||
latch; on the return to Drive no fresh MAIN edge occurs, so AOL stayed off
|
||||
until the driver re-armed it manually (the pre-7.0 behavior was an
|
||||
automatic resume).
|
||||
"""
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from opendbc.car import gen_empty_fingerprint, structs
|
||||
from opendbc.car.subaru.interface import CarInterface
|
||||
from opendbc.car.subaru.stock_aol import qualified
|
||||
from opendbc.car.subaru.values import CAR
|
||||
from openpilot.cereal import log
|
||||
from openpilot.starpilot.aol.intent import AolSettings, disarming_fault
|
||||
from openpilot.starpilot.aol.vehicle import intent_disarming_fault as vehicle_disarming_fault
|
||||
from openpilot.starpilot.car.subaru.aol import SubaruStockCardIntent, intent_disarming_fault
|
||||
|
||||
Gear = structs.CarState.GearShifter
|
||||
Name = log.OnroadEvent.EventName
|
||||
|
||||
|
||||
def make_cp():
|
||||
cp = CarInterface.get_params(CAR.SUBARU_IMPREZA_2020, gen_empty_fingerprint(), [], False, False, False)
|
||||
assert qualified(cp)
|
||||
return cp
|
||||
|
||||
|
||||
def make_state(gear):
|
||||
cs = structs.CarState(canValid=True, vEgo=15.0, gearShifter=gear)
|
||||
cs.cruiseState.available = True
|
||||
return cs
|
||||
|
||||
|
||||
def wrong_gear_event():
|
||||
return SimpleNamespace(name=Name.wrongGear, softDisable=True, immediateDisable=False, noEntry=True)
|
||||
|
||||
|
||||
def test_generic_classifier_still_disarms_on_unknown_gear():
|
||||
# The generic rule is unchanged: other brands (e.g. GM) rely on unknown
|
||||
# gear being disarming. The Subaru fix is scoped to the Subaru port.
|
||||
assert disarming_fault([wrong_gear_event()], make_state(Gear.unknown))
|
||||
|
||||
|
||||
def test_subaru_manual_episode_is_not_a_disarming_fault():
|
||||
cp = make_cp()
|
||||
state = make_state(Gear.unknown)
|
||||
assert not intent_disarming_fault(cp, [wrong_gear_event()], state)
|
||||
assert not vehicle_disarming_fault(cp, [wrong_gear_event()], state)
|
||||
|
||||
|
||||
def test_subaru_known_gears_were_never_disarming():
|
||||
cp = make_cp()
|
||||
for gear in (Gear.drive, Gear.park, Gear.neutral, Gear.reverse):
|
||||
assert not intent_disarming_fault(cp, [wrong_gear_event()], make_state(gear))
|
||||
|
||||
|
||||
def test_subaru_real_faults_still_disarm_in_manual_mode():
|
||||
cp = make_cp()
|
||||
state = make_state(Gear.unknown)
|
||||
hard_event = SimpleNamespace(name=Name.controlsMismatch, softDisable=False, immediateDisable=True, noEntry=False)
|
||||
assert intent_disarming_fault(cp, [hard_event], state)
|
||||
state.steerFaultPermanent = True
|
||||
assert intent_disarming_fault(cp, [wrong_gear_event()], state)
|
||||
|
||||
|
||||
def test_latch_survives_manual_episode_and_resumes_in_drive():
|
||||
cp = make_cp()
|
||||
settings = AolSettings(True, 0., 0, 0, (0, 0, 0), (0, 0, 0))
|
||||
intent = SubaruStockCardIntent(settings)
|
||||
|
||||
cs = make_state(Gear.drive)
|
||||
cs.cruiseState.enabled = True
|
||||
|
||||
def observe(enabled, active, stamp):
|
||||
intent.observe_full_engagement(cs.as_reader(), enabled=enabled, active=active, source_ns=stamp,
|
||||
observation_valid=True, now_ns=stamp, fault_active=False)
|
||||
|
||||
intent.update(cs.as_reader(), now_ns=1)
|
||||
observe(False, False, 10)
|
||||
observe(True, False, 20)
|
||||
observe(True, True, 30)
|
||||
assert intent.allowed_latch
|
||||
|
||||
# Paddle downshift: manual mode, gear reads unknown, wrongGear soft event.
|
||||
cs.gearShifter = Gear.unknown
|
||||
cs.cruiseState.enabled = False
|
||||
fault = vehicle_disarming_fault(cp, [wrong_gear_event()], cs.as_reader())
|
||||
intent.update(cs.as_reader(), fault_active=fault, now_ns=40)
|
||||
assert intent.allowed_latch, "manual-mode episode revoked AOL intent"
|
||||
|
||||
# Back to Drive with MAIN never cycled: no re-arm gesture, latch is enough.
|
||||
cs.gearShifter = Gear.drive
|
||||
intent.update(cs.as_reader(), fault_active=False, now_ns=50)
|
||||
assert intent.allowed_latch
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pytest.main([__file__, "-v"])
|
||||
Reference in New Issue
Block a user