Honor LKAS wheel action assignments across vehicles

This commit is contained in:
firestar5683
2026-11-27 22:55:28 -06:00
parent 3831031635
commit 64fdc72c1e
11 changed files with 126 additions and 35 deletions
+3 -2
View File
@@ -35,7 +35,7 @@ from openpilot.selfdrive.pandad import can_capnp_to_list, can_list_to_can_capnp
from openpilot.selfdrive.car.can_callbacks import can_comm_callbacks, obd_callback
from openpilot.selfdrive.car.cruise import LOW_SPEED_CRUISE_ON_SET, SlcWheelContext, VCruiseHelper, slc_target_kph
from openpilot.starpilot.speed_limits import physical_actions as slc_physical, tesla_set_speed_card
from openpilot.starpilot.aol.intent import AolProcessFaultContext, independent_axis_requested, read_settings
from openpilot.starpilot.aol.intent import AolProcessFaultContext, claim_remapped_lkas, independent_axis_requested, read_settings
from openpilot.starpilot.aol.transport_pause import TransportPauseFeedback, cp_identity
from opendbc.car.honda.stock_aol import qualified as qualified_honda_stock_aol, native_observation as honda_native_observation
from opendbc.car.volkswagen.stock_aol import safety_config as volkswagen_aol_safety_config
@@ -715,7 +715,8 @@ class Car:
now_ns=now_ns, producer=self.slc_producer_session)
if hasattr(self.aol_card_intent, 'observe_vehicle_state'):
self.aol_card_intent.observe_vehicle_state(self.CI.CS)
self.aol_card_intent.update(CS, fault_active=fault_active, now_ns=now_ns, native_rejection_ns=rejection_ns,
consumed_buttons = claim_remapped_lkas(self.params, self.aol_settings, CS)
self.aol_card_intent.update(CS, consumed_buttons=consumed_buttons, fault_active=fault_active, now_ns=now_ns, native_rejection_ns=rejection_ns,
standard_enabled=(host_enabled if getattr(self.aol_card_intent, 'observe_stock_engagement', False)
else host_control_enabled))
# Observe ordinary state directly: independent AOL actuator activity is
+29 -10
View File
@@ -9,6 +9,7 @@ from openpilot.cereal import log
from openpilot.selfdrive.car.cruise import CRUISE_LONG_PRESS
from openpilot.system.manager.process_health import driving_process_failures
from openpilot.starpilot.conditional_mode.manual import Button, ButtonTracker, Press
from openpilot.starpilot.saved_source import read_saved
ButtonType = car.CarState.ButtonEvent.Type
GearShifter = car.CarState.GearShifter
@@ -32,6 +33,21 @@ class AolSettings:
default_physical_buttons: bool = True
main_wheel_action: bool = False
lkas_wheel_action: bool = False
lkas_unassigned: bool = True
@property
def default_lkas_toggle(self) -> bool:
return self.lkas_unassigned and self.lkas_action == 0 and not self.lkas_wheel_action
_LKAS_CONSUMED = frozenset((int(ButtonType.lkas),))
def claim_remapped_lkas(params, settings: AolSettings | None, CS) -> frozenset[int]:
if not CS.buttonEvents or settings is None or not settings.default_lkas_toggle or not any(
event.type == ButtonType.lkas and event.pressed for event in CS.buttonEvents):
return frozenset()
return frozenset() if read_saved(params, 'LKASButtonControl', 8) in ((None, True), (b'9', True)) else _LKAS_CONSUMED
def _button_value(params, key: str) -> int | None:
@@ -62,14 +78,19 @@ def read_settings(params) -> AolSettings:
pause_mps = float('nan')
break
valid_pause = 0.0 <= pause_mps <= 100.0
lkas = _button_value(params, 'LKASButtonControl')
saved_lkas = params.get('LKASButtonControl')
try:
lkas = 0 if saved_lkas is None else int(saved_lkas)
except (TypeError, ValueError):
lkas = None
main = _button_value(params, 'MainCruiseButtonControl')
return AolSettings(
enabled=params.get_bool('AlwaysOnLateral') and valid_pause, pause_brake_mps=pause_mps if valid_pause else 0.0,
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),
lkas_wheel_action=lkas in (1, 2, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15),
lkas_unassigned=saved_lkas is None,
distance_actions=(_button_action(params, 'DistanceButtonControl'),
_button_action(params, 'LongDistanceButtonControl'),
_button_action(params, 'VeryLongDistanceButtonControl')),
@@ -148,13 +169,12 @@ def disarming_fault(events, CS, *, temporary_ui_process_failure: bool = False,
class AolCardIntent:
def __init__(self, settings: AolSettings, *, explicit_latch: bool = False, lkas_button_supported: bool = True,
independent_cruise_buttons: bool = False, preserve_unassigned_cancel: bool = False,
confirm_main_available: bool = False, respect_lkas_wheel_action: bool = False):
confirm_main_available: bool = False):
self.settings = settings
self.explicit_latch = explicit_latch
self.independent_cruise_buttons = independent_cruise_buttons
self.preserve_unassigned_cancel = preserve_unassigned_cancel
self.confirm_main_available = confirm_main_available
self.respect_lkas_wheel_action = respect_lkas_wheel_action
self._pending_main_arm_ns = 0
self.lkas_button_supported = lkas_button_supported
self.allowed_latch = False
@@ -338,9 +358,8 @@ class AolCardIntent:
# owners keep their current event and native contracts.
main_toggle = (not independent_buttons or main_managed) and not (
self.independent_cruise_buttons and self.settings.main_wheel_action)
lkas_toggle = (not independent_buttons or lkas_managed) and not (
getattr(self, 'allow_manumatic', False) or
((self.independent_cruise_buttons or self.respect_lkas_wheel_action) and self.settings.lkas_wheel_action))
lkas_toggle = (lkas_managed or not independent_buttons and self.settings.default_lkas_toggle) and not getattr(
self, 'allow_manumatic', False)
previously_held = (self._main_held and main_toggle) or (self._lkas_held and lkas_toggle)
cancel_pressed = False
for event in CS.buttonEvents:
@@ -351,16 +370,16 @@ class AolCardIntent:
self._perform(self.main_action if not main_managed else 0)
self._main_held = bool(event.pressed)
elif button == int(ButtonType.lkas):
if (independent_buttons and event.pressed and not self._lkas_held and
if (event.pressed and not self._lkas_held and self.lkas_action in (PAUSE_LATERAL, PAUSE_LONGITUDINAL) and
button not in consumed_buttons and self.settings.enabled and not CS.accFaulted and not self._fault_inhibit):
self._perform(self.lkas_action if not lkas_managed else 0)
self._perform(self.lkas_action)
self._lkas_held = bool(event.pressed)
elif button == int(ButtonType.cancel) and event.pressed:
cancel_pressed = True
gesture_held = ((self._main_held and main_toggle and
(not independent_buttons or int(ButtonType.mainCruise) not in consumed_buttons)) or
(self._lkas_held and lkas_toggle and
(not independent_buttons or int(ButtonType.lkas) not in consumed_buttons)))
int(ButtonType.lkas) not in consumed_buttons))
if not previously_held and gesture_held and (not (independent_buttons or self.preserve_unassigned_cancel) or not cancel_pressed):
self._last_latch_edge_ns = now_ns
if cancel_pressed:
@@ -7,7 +7,7 @@ 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))
@pytest.mark.parametrize("action", (0, 1, 2, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15))
def test_remapped_lkas_keeps_established_lateral_after_brake(action, tmp_path):
from openpilot.common.params import Params
params = Params(str(tmp_path))
@@ -55,7 +55,7 @@ def test_remapped_lkas_never_creates_authority(tmp_path):
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):
for action in range(16):
params.put("LKASButtonControl", action, block=True)
assert read_settings(params).lkas_wheel_action == (action in DELIVERED_ACTIONS)
@@ -73,7 +73,7 @@ def test_only_main_adopt_is_marked_as_a_main_wheel_action(lkas, main, main_wheel
assert settings.main_wheel_action == main_wheel
@pytest.mark.parametrize('action,keeps_lateral', [(8, True), (9, False), (0, False)])
@pytest.mark.parametrize('action,keeps_lateral', [(8, True), (9, False), (0, True)])
def test_tucson_lkas_bookmark_does_not_double_as_lateral_toggle(action, keeps_lateral):
from opendbc.car import gen_empty_fingerprint
from opendbc.car.hyundai.interface import CarInterface
@@ -126,7 +126,7 @@ def test_mixed_palisade_lkas_bookmark_owns_only_the_wheel_action(tmp_path, topol
publisher = WheelPublisher()
owner.update(cs, now_ns=now, fault_active=False)
assert publisher.observe(saved, cp, cs, now_ns=now, drive_id=1_000_000_000) == (('', 0),)
if action == 8:
if action != 9:
press(owner, cs, 'lkas', now + 1)
assert not owner.allowed_latch and owner.physical_arm_ns == 0
cs.buttonEvents = []
@@ -140,8 +140,67 @@ def test_mixed_palisade_lkas_bookmark_owns_only_the_wheel_action(tmp_path, topol
owner.update(cs, now_ns=now + 10_000_000, fault_active=False, standard_enabled=True)
actions = publisher.observe(saved, cp, cs, now_ns=now + 10_000_000, drive_id=1_000_000_000)
assert actions == ((('LKASButtonControl', 8),) if action == 8 else ())
assert lateral(owner) == (action == 8)
if action == 8:
assert lateral(owner) == (action != 9)
if action != 9:
assert not owner.pause_lateral and owner._last_latch_edge_ns == edge
owner.update(cs, now_ns=now + 20_000_000, fault_active=True, standard_enabled=True)
assert not lateral(owner)
@pytest.mark.parametrize('action,toggles', [(None, True), (b'0', False), (b'8', False), (b'9', True),
(b'15', False), (b'invalid', False)])
@pytest.mark.parametrize('owner_type', ['shared', 'ford', 'tesla'])
def test_saved_lkas_assignment_beats_physical_aol_fallback(owner_type, action, toggles):
from openpilot.starpilot.car.ford.aol import FordCardIntent
from openpilot.starpilot.car.tesla.screen_intent import TeslaScreenCardIntent
settings = read_settings(SavedParams({'AlwaysOnLateral': b'1', 'LKASButtonControl': action}))
cp = structs.CarParams(safetyConfigs=[{'safetyParam': 512}])
if owner_type == 'shared':
owner = AolCardIntent(settings, explicit_latch=True)
elif owner_type == 'ford':
owner = FordCardIntent(cp, settings)
else:
owner = TeslaScreenCardIntent(cp, settings)
cs = structs.CarState(canValid=True, gearShifter='drive', cruiseState={'available': True, 'enabled': True})
owner.update(cs, now_ns=1, fault_active=False)
owner.observe_full_engagement(cs, enabled=False, active=False, source_ns=2, observation_valid=True, now_ns=2, fault_active=False)
owner.observe_full_engagement(cs, enabled=True, active=True, source_ns=3, observation_valid=True, now_ns=3, fault_active=False)
assert lateral(owner)
press(owner, cs, 'lkas', 10, engaged=True)
assert lateral(owner) is not toggles
assert owner.pause_lateral is toggles
@pytest.mark.parametrize('action', [3, 4])
def test_lkas_pause_mapping_only_pauses_the_selected_axis(action):
saved = SavedParams({'AlwaysOnLateral': b'1', 'LKASButtonControl': str(action).encode()})
owner = AolCardIntent(read_settings(saved), explicit_latch=True)
cs = structs.CarState(canValid=True, gearShifter='drive', cruiseState={'available': True})
owner.update(cs, now_ns=1, fault_active=False)
owner.observe_full_engagement(cs, enabled=False, active=False, source_ns=2, observation_valid=True, now_ns=2, fault_active=False)
owner.observe_full_engagement(cs, enabled=True, active=True, source_ns=3, observation_valid=True, now_ns=3, fault_active=False)
assert lateral(owner)
press(owner, cs, 'lkas', 10, engaged=True)
assert owner.allowed_latch and owner.pause_lateral == (action == 3) and owner.pause_longitudinal == (action == 4)
@pytest.mark.parametrize('saved_action', [b'0', b'8', b'15'])
def test_live_lkas_remap_does_not_also_toggle_default_aol(tmp_path, saved_action):
from openpilot.starpilot.aol.intent import claim_remapped_lkas
saved = SavedParams({'AlwaysOnLateral': b'1'})
saved.get_param_path = lambda key: str(tmp_path/key)
settings = read_settings(saved)
owner = AolCardIntent(settings, explicit_latch=True)
cs = armed(owner)
(tmp_path/'LKASButtonControl').write_bytes(saved_action)
cs.buttonEvents = [structs.CarState.ButtonEvent(type='lkas', pressed=True)]
claimed = claim_remapped_lkas(saved, settings, cs)
assert claimed == frozenset((int(structs.CarState.ButtonEvent.Type.lkas),))
owner.update(cs, now_ns=10, consumed_buttons=claimed, fault_active=False, standard_enabled=True)
assert lateral(owner)
cs.buttonEvents = []
assert not claim_remapped_lkas(saved, settings, cs)
owner.update(cs, now_ns=11, fault_active=False, standard_enabled=True)
assert lateral(owner)
+1 -2
View File
@@ -324,8 +324,7 @@ def create_intent(CP, settings):
mixed_hda2_stock = _mixed_hda2_stock(CP)
return AolCardIntent(settings, explicit_latch=policy_for(CP).explicit_latch,
independent_cruise_buttons=independent_cruise_buttons,
preserve_unassigned_cancel=mixed_hda2_stock, confirm_main_available=mixed_hda2_stock,
respect_lkas_wheel_action=qualified_blended_stock(CP))
preserve_unassigned_cancel=mixed_hda2_stock, confirm_main_available=mixed_hda2_stock)
def ordinary_axis_request_allowed(CP, CS) -> bool:
@@ -7,10 +7,9 @@ class ClassicLongCardIntent(AolCardIntent):
defer_full_engagement_on_gas = True
def __init__(self, cp, settings):
blended_alpha = qualified_alpha(cp)
super().__init__(settings, explicit_latch=True, independent_cruise_buttons=(
independent_buttons_qualified(cp, marked_only=False)),
preserve_unassigned_cancel=blended_alpha, respect_lkas_wheel_action=blended_alpha)
preserve_unassigned_cancel=qualified_alpha(cp))
self.requires_fault_observation = True
self.observe_stock_engagement = True
@@ -1,7 +1,7 @@
"""EV6 configured AOL desire gated by actual physical authorization."""
from opendbc.car.hyundai.values import Buttons
from opendbc.car.hyundai.ev6_aol import Ev6PhysicalAuthorization
from openpilot.starpilot.aol.intent import AolCardIntent, AOL_TOGGLE, ButtonType
from openpilot.starpilot.aol.intent import AolCardIntent, AOL_TOGGLE, ButtonType, PAUSE_LATERAL, PAUSE_LONGITUDINAL
class StockEv6CardIntent(AolCardIntent):
@@ -90,6 +90,9 @@ class Ev6CardIntent(AolCardIntent):
self._full_engagement_release_ns = 0
lkas_managed = self.settings.enabled and self.settings.lkas_action == AOL_TOGGLE
main_managed = self.settings.main_action == AOL_TOGGLE
lkas_consumed = int(ButtonType.lkas) in consumed_buttons
lkas_toggle = not lkas_consumed and (lkas_managed or self.settings.default_lkas_toggle)
lkas_axis_action = not lkas_consumed and (lkas_toggle or self.settings.lkas_action in (PAUSE_LATERAL, PAUSE_LONGITUDINAL))
auto_main = self.settings.enabled and not lkas_managed and not main_managed
if healthy and not rejected:
for main, lkas, cruise in self._samples:
@@ -103,11 +106,11 @@ class Ev6CardIntent(AolCardIntent):
self._raw_neutral_seen = not (main or lkas) and cruise == Buttons.NONE
continue
self.physical.observe(main, lkas, cruise, main_available=CS.cruiseState.available,
lkas_toggle=not self.settings.lkas_wheel_action)
lkas_toggle=lkas_toggle)
main_press = bool(main and not previous_main)
# 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)
lkas_press = bool(lkas and not previous_lkas and lkas_axis_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,7 +1,7 @@
"""Modern screen gesture override layered over ordinary cruise availability."""
from dataclasses import replace
from opendbc.car import structs
from openpilot.starpilot.aol.intent import AolCardIntent, ButtonType
from openpilot.starpilot.aol.intent import AolCardIntent, AOL_TOGGLE, ButtonType
class TeslaScreenCardIntent(AolCardIntent):
@@ -45,7 +45,8 @@ class TeslaScreenCardIntent(AolCardIntent):
continue
fresh_press = bool(event.pressed and not self.screen_held)
self.screen_held = bool(event.pressed)
if (fresh_press and CS.gearShifter == structs.CarState.GearShifter.drive and not CS.steerFaultTemporary and
if (fresh_press and self.screen_toggle_mapped and int(ButtonType.lkas) not in kwargs.get('consumed_buttons', ()) and
CS.gearShifter == structs.CarState.GearShifter.drive and not CS.steerFaultTemporary and
not fault and not cancel and self.settings.enabled and
not (self.brake_disengage and CS.brakePressed)):
current = (available if self.screen_override is None else self.screen_override)
@@ -70,4 +71,5 @@ class TeslaScreenCardIntent(AolCardIntent):
@settings.setter
def settings(self, value):
self.screen_toggle_mapped = value.lkas_action == AOL_TOGGLE or value.default_lkas_toggle
self._settings = replace(value, lkas_action=0)
@@ -65,7 +65,13 @@ def test_mach_e_fixed_lkas_role_matches_actual_intent_and_cannot_claim_off(tmp_p
rows = {row.key: row for row in wheel.rows()}
lkas = rows['wheel:LKASButtonControl']
assert lkas.value == 'Toggle AOL' and 'Toggle AOL' in lkas.choices
assert lkas.available and 'also toggles AOL' in lkas.reason
assert lkas.available
for code, label in ((8, 'Bookmark'), (0, 'Off')):
params.put('LKASButtonControl', code, block=True)
current = next(row for row in wheel.rows() if row.key == 'wheel:LKASButtonControl')
assert current.value == label
assert 'also toggles AOL' not in current.reason
params.remove('LKASButtonControl')
main = rows['wheel:MainCruiseButtonControl']
assert main.value == 'Factory cruise / AOL'
assert not main.available and not main.choices
+9 -6
View File
@@ -126,16 +126,19 @@ class WheelFeature:
ordinary_actions = (None, *(str(code).encode() for code in ACTIONS.values() if code != 9))
implicit_toggle = independent_cruise_buttons_supported(cp) and all(ok and value in ordinary_actions
for value, ok in sources)
ford_role = cp.brand == 'ford' and policy.explicit_latch and policy.runtime_supported and key == KEYS[0]
if (ford_role or (implicit_toggle and raw is None)) and selected == "Off":
lkas_default = key == KEYS[0] and policy.explicit_latch and policy.runtime_supported and cp.brand in ('ford', 'tesla')
if raw is None and key == KEYS[0] and cp.brand == 'hyundai' and policy.explicit_latch:
from opendbc.car.hyundai.blended_stock_aol import qualified, qualified_alpha
lkas_default |= qualified(cp) or qualified_alpha(cp)
if raw is None and (lkas_default or implicit_toggle) and selected == "Off":
selected = "Toggle AOL"
rows.append(FeatureRow(PREFIX + key, label, selected or "Invalid saved action", raw, choices,
available=readable and self.owner.authority("preferences"),
reason=("LKAS also toggles AOL independently of its saved extra action." if ford_role else
("When AOL is enabled, this button can still toggle it by default. Using only the other button " +
"requires assigning Toggle AOL to it and restarting.") if implicit_toggle and raw == b"0" else
reason=(("When AOL is enabled, this button can still toggle it by default. Using only the other button " +
"requires assigning Toggle AOL to it and restarting.") if key == KEYS[1] and implicit_toggle and raw == b"0" else
"Bookmark on release. Available while Left Paddle Longitudinal Pause is Off." if key == PADDLE_KEY else
"Off adds no action to the vehicle's existing button behavior. " +
("Off clears the LKAS assignment. " if key == KEYS[0] else
"Off adds no action to the vehicle's existing button behavior. ") +
"Axis pause and AOL assignments apply after restarting. Other actions can apply this drive. " +
"Long actions fire while held."),
capability=capability, repair_value="Off" if selected is None else ""))
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "e1d53755b43aed655f662df1c562b51c564e95fbad3b7d1379c4a8be9a045e18", "schema_version": 1}
{"protected_inventory_sha256": "cc28b9c87eed57d9b46be9bd153c722af246566db63d39215bac4b9b6c0f88e7", "schema_version": 1}