fix(hyundai): preserve EV6 AOL for remapped LKAS actions

This commit is contained in:
Dom
2026-11-15 12:06:19 -06:00
parent 3e57276216
commit 8fa9684f98
6 changed files with 107 additions and 7 deletions
+2 -2
View File
@@ -26,10 +26,10 @@ class Ev6PhysicalAuthorization:
# Retain actual held-button history: withdrawal is not a synthetic new edge.
self.main_on = self.lkas_on = False
def observe(self, main, lkas, cruise, *, main_available):
def observe(self, main, lkas, cruise, *, main_available, lkas_toggle=True):
if main and not self.previous_main:
self.main_on = not self.main_on
if lkas and not self.previous_lkas:
if lkas_toggle and lkas and not self.previous_lkas:
self.lkas_on = not self.lkas_on
if self.lkas_on_engage and cruise != self.previous_cruise and self.previous_cruise in (Buttons.SET_DECEL, Buttons.RES_ACCEL):
self.lkas_on = True
+2
View File
@@ -31,6 +31,7 @@ class AolSettings:
custom_actions: tuple[int, int, int] = (0, 0, 0)
default_physical_buttons: bool = True
main_wheel_action: bool = False
lkas_wheel_action: bool = False
def _button_value(params, key: str) -> int | None:
@@ -68,6 +69,7 @@ def read_settings(params) -> AolSettings:
lkas_action=_axis_action(lkas), main_action=_axis_action(main),
default_physical_buttons=lkas == 0 and main == 0,
main_wheel_action=main == ADOPT_SPEED_LIMIT,
lkas_wheel_action=lkas in (1, 2, 5, 6, 7, 8, 10, 11, 12, 13, 14),
distance_actions=(_button_action(params, 'DistanceButtonControl'),
_button_action(params, 'LongDistanceButtonControl'),
_button_action(params, 'VeryLongDistanceButtonControl')),
@@ -97,8 +97,8 @@ class TestEv6ConfiguredDesire(unittest.TestCase):
def owner(self, *, main=0, lkas=0, enabled=True, cancel=(0, 0, 0)):
return Ev6CardIntent(AolSettings(enabled, 0., lkas, main, (0, 0, 0), cancel))
def sample(self, owner, samples, *, available=True, active=False, events=(), valid=True, fault=False, acc_fault=False, cruise_enabled=False):
state = structs.CarState(canValid=valid, canTimeout=False, gearShifter='drive', buttonEvents=list(events))
def sample(self, owner, samples, *, available=True, active=False, events=(), valid=True, fault=False, acc_fault=False, cruise_enabled=False, brake=False):
state = structs.CarState(canValid=valid, canTimeout=False, gearShifter='drive', buttonEvents=list(events), brakePressed=brake)
state.cruiseState.available = available
state.cruiseState.enabled = cruise_enabled
state.accFaulted = acc_fault
@@ -0,0 +1,95 @@
"""EV6 route25: an adopted speed limit must not silently withdraw lateral."""
import pytest
from openpilot.starpilot.aol.intent import AOL_TOGGLE, read_settings
from openpilot.starpilot.aol.tests import test_ev6_physical_authorization as fixture
from opendbc.car.hyundai.values import Buttons
from opendbc.car import structs
from openpilot.starpilot.controllers.wheel_actions import DELIVERED_ACTIONS
@pytest.mark.parametrize("action", (1, 2, 5, 6, 7, 8, 10, 11, 12, 13, 14))
def test_remapped_lkas_keeps_established_lateral_after_brake(action, tmp_path):
from openpilot.common.params import Params
params = Params(str(tmp_path))
params.put_bool("AlwaysOnLateral", True, block=True)
params.put("LKASButtonControl", action, block=True)
params.put("MainCruiseButtonControl", 0, block=True)
case = fixture.TestEv6ConfiguredDesire(methodName="runTest")
owner = case.owner()
owner.settings = read_settings(params)
case.sample(owner, [(0, 0, Buttons.NONE)])
# Fresh SET/release and successful engagement establish independent lateral.
cs = case.sample(owner, [(0, 0, Buttons.SET_DECEL), (0, 0, Buttons.NONE)], active=True, cruise_enabled=True)
assert owner.output(cs)[0]
press = structs.CarState.ButtonEvent(type="lkas", pressed=True)
release = structs.CarState.ButtonEvent(type="lkas", pressed=False)
cs = case.sample(owner, [(0, 1, Buttons.NONE)], events=[press], active=True, cruise_enabled=True)
assert owner.output(cs)[0]
assert not owner._engagement_manual_withdrawal
case.sample(owner, [(0, 0, Buttons.NONE)], events=[release], active=True, cruise_enabled=True)
# Cruise withdrawal at the later brake must leave this established latch alone.
cs = case.sample(owner, [], active=False, cruise_enabled=False, brake=True)
assert owner.output(cs)[0]
# Explicit OFF still owns the latch and cannot be reversed by a remapped press.
owner._perform(AOL_TOGGLE)
assert not owner.output(cs)[0]
cs = case.sample(owner, [(0, 1, Buttons.NONE), (0, 0, Buttons.NONE)], active=True)
assert not owner.output(cs)[0]
def test_remapped_lkas_never_creates_authority(tmp_path):
from openpilot.common.params import Params
params = Params(str(tmp_path))
params.put_bool("AlwaysOnLateral", True, block=True)
params.put("LKASButtonControl", 10, block=True)
params.put("MainCruiseButtonControl", 0, block=True)
case = fixture.TestEv6ConfiguredDesire(methodName="runTest")
owner = case.owner()
owner.settings = read_settings(params)
case.sample(owner, [(0, 0, Buttons.NONE)])
cs = case.sample(owner, [(0, 1, Buttons.NONE), (0, 0, Buttons.NONE)])
assert not owner.output(cs)[0]
assert not owner.physical.authorized
def test_lkas_wheel_action_catalog_matches_publisher(tmp_path):
from openpilot.common.params import Params
params = Params(str(tmp_path))
for action in range(15):
params.put("LKASButtonControl", action, block=True)
assert read_settings(params).lkas_wheel_action == (action in DELIVERED_ACTIONS)
@pytest.mark.parametrize("boundary", ("fault", "acc_fault", "invalid", "native_rejection"))
def test_remapped_press_does_not_restore_rejected_authority(boundary):
from dataclasses import replace
case = fixture.TestEv6ConfiguredDesire(methodName="runTest")
owner = case.owner()
owner.settings = replace(owner.settings, lkas_wheel_action=True)
case.sample(owner, [(0, 0, Buttons.NONE)])
cs = case.sample(owner, [(0, 0, Buttons.SET_DECEL), (0, 0, Buttons.NONE)], active=True)
assert owner.output(cs)[0]
if boundary == "native_rejection":
owner.update(cs, now_ns=owner._test_clock_ns, native_rejection_ns=owner._test_clock_ns)
else:
case.sample(owner, [], fault=boundary == "fault", acc_fault=boundary == "acc_fault", valid=boundary != "invalid")
case.sample(owner, [(0, 0, Buttons.NONE)])
cs = case.sample(owner, [(0, 1, Buttons.NONE), (0, 0, Buttons.NONE)])
assert not owner.physical.authorized
assert not owner.output(cs)[0]
def test_remapped_lkas_still_delivers_speed_limit_action(tmp_path):
from openpilot.common.params import Params
from openpilot.starpilot.controllers.wheel_actions import WheelPublisher
params = Params(str(tmp_path))
params.put("LKASButtonControl", 10, block=True)
cp = fixture.ev6_params()
owner = WheelPublisher()
now = 3_000_000_000
def state(pressed=None):
return structs.CarState(canValid=True, buttonEvents=[] if pressed is None else [
structs.CarState.ButtonEvent(type="lkas", pressed=pressed)])
owner.observe(params, cp, state(), now_ns=now, drive_id=1_000_000_000)
assert owner.observe(params, cp, state(True), now_ns=now + 10_000_000, drive_id=1_000_000_000) == (("LKASButtonControl", 10),)
assert not owner.observe(params, cp, state(False), now_ns=now + 20_000_000, drive_id=1_000_000_000)
@@ -102,9 +102,12 @@ class Ev6CardIntent(AolCardIntent):
self.physical.previous_cruise = cruise
self._raw_neutral_seen = not (main or lkas) and cruise == Buttons.NONE
continue
self.physical.observe(main, lkas, cruise, main_available=CS.cruiseState.available)
self.physical.observe(main, lkas, cruise, main_available=CS.cruiseState.available,
lkas_toggle=not self.settings.lkas_wheel_action)
main_press = bool(main and not previous_main)
lkas_press = bool(lkas and not previous_lkas)
# A remapped LKAS press belongs to WheelPublisher, not the AOL owner.
# Keep raw level history but neither grant nor revoke physical authority.
lkas_press = bool(lkas and not previous_lkas and not self.settings.lkas_wheel_action)
self._engagement_manual_withdrawal |= main_press or lkas_press
engagement_release = (self.physical.lkas_on_engage and cruise != previous_cruise
and previous_cruise in (Buttons.SET_DECEL, Buttons.RES_ACCEL))
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "5eb641c37149bd248bb84d908adcbe28da34a4d17f5e81377d9a10c21a0d8648", "schema_version": 1}
{"protected_inventory_sha256": "caeadba8e9b6df70b2b88db18b22f3c99c78841b0df86e1dee4c7511bee263d0", "schema_version": 1}