From fb7c1582452a9a45a45ea3ab7f4e15a1bcbe80ce Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Wed, 18 Nov 2026 23:56:52 -0600 Subject: [PATCH] Keep Ford PCM cruise buttons separate from SLC confirmation --- openpilot/selfdrive/car/cruise.py | 2 + .../tests/test_physical_actions.py | 44 ++++++++++++++++++- openpilot/starpilot/ui/runtime_snapshot.py | 1 + .../ui/tests/test_runtime_snapshot.py | 3 +- prebuilt.json | 2 +- 5 files changed, 49 insertions(+), 3 deletions(-) diff --git a/openpilot/selfdrive/car/cruise.py b/openpilot/selfdrive/car/cruise.py index b6cf67184d..5a39d5f14b 100644 --- a/openpilot/selfdrive/car/cruise.py +++ b/openpilot/selfdrive/car/cruise.py @@ -177,6 +177,7 @@ class VCruiseHelper: self.pcm_slc_sample = (float(self.v_cruise_kph), now_ns) def _update_slc_button_latches(self, CS, enabled, slc_pending: SlcPendingConfirmation | None) -> None: + # Ford PCM buttons reach OEM cruise even when a host-side press is consumed. for b in CS.buttonEvents: button = b.type.raw if button not in self.button_timers: @@ -186,6 +187,7 @@ class VCruiseHelper: self.slc_released_suppressed = True self.button_timers[button] = 0 elif (b.pressed and enabled and CS.cruiseState.available and slc_pending is not None and + not (self.CP.brand == 'ford' and self.CP.pcmCruise) and not (self.CP.pcmCruise and button == ButtonType.accelCruise and (CS.standstill or CS.cruiseState.standstill or not CS.cruiseState.enabled)) and button not in self.slc_suppressed_buttons): diff --git a/openpilot/starpilot/speed_limits/tests/test_physical_actions.py b/openpilot/starpilot/speed_limits/tests/test_physical_actions.py index f9f71568a0..512c980307 100644 --- a/openpilot/starpilot/speed_limits/tests/test_physical_actions.py +++ b/openpilot/starpilot/speed_limits/tests/test_physical_actions.py @@ -3,10 +3,11 @@ import math import pytest +from opendbc.car import structs from opendbc.car.dashboard_speed_limit import Observation, Status from openpilot.cereal import messaging -from openpilot.selfdrive.car.cruise import SlcPendingConfirmation +from openpilot.selfdrive.car.cruise import SlcPendingConfirmation, VCruiseHelper from openpilot.starpilot.speed_limits import physical_actions from openpilot.starpilot.speed_limits.selection import Source from openpilot.starpilot.speed_limits.tests.test_runtime_replay import ReplaySM @@ -144,3 +145,44 @@ def test_dashboard_engagement_qualifies_both_samples(sm, state_changes, local_ch 'observed_ns': NOW - 5_000_000, 'valid_until_ns': NOW + 145_000_000} | local_changes)) assert (physical_actions.engagement_state(sm, local, 'card', NOW, after_ns=after_ns) is not None) == matches + + +@pytest.mark.parametrize('direction', ['accelCruise', 'decelCruise']) +@pytest.mark.parametrize('longitudinal', [False, True]) +def test_ford_pcm_wheel_changes_only_stock_set(direction, longitudinal): + cp = structs.CarParams(brand='ford', pcmCruise=True, openpilotLongitudinalControl=longitudinal) + helper = VCruiseHelper(cp) + cs = structs.CarState(canValid=True) + cs.cruiseState.available = cs.cruiseState.enabled = True + cs.cruiseState.speed = cs.cruiseState.speedCluster = 20. + prompt = SlcPendingConfirmation('planner', 1, 2) + for pressed, speed in [(True, 20.), (True, 21. if direction == 'accelCruise' else 19.), (False, 21. if direction == 'accelCruise' else 19.)]: + cs.cruiseState.speed = cs.cruiseState.speedCluster = speed + cs.buttonEvents = [{'type': direction, 'pressed': pressed}] + helper.update_v_cruise(cs, True, True, prompt, slc_enabled=True) + assert helper.slc_consumed_button is None + assert not helper.slc_suppressed_buttons + assert helper.v_cruise_kph == pytest.approx(speed * 3.6) + assert helper.v_cruise_cluster_kph == pytest.approx(speed * 3.6) + + +@pytest.mark.parametrize('direction', ['accelCruise', 'decelCruise']) +def test_ford_software_set_still_consumes_confirmation_without_a_speed_step(direction): + cp = structs.CarParams(brand='ford', pcmCruise=False, openpilotLongitudinalControl=True) + helper = VCruiseHelper(cp) + helper.v_cruise_kph = helper.v_cruise_cluster_kph = 72. + cs = structs.CarState(canValid=True) + cs.cruiseState.available = cs.cruiseState.enabled = True + prompt = SlcPendingConfirmation('planner', 1, 2) + cs.buttonEvents = [{'type': direction, 'pressed': True}] + helper.update_v_cruise(cs, True, True, prompt, slc_enabled=True) + assert helper.slc_consumed_button is not None + assert helper.slc_consumed_button.pending == prompt + for _ in range(60): + cs.buttonEvents = [] + helper.update_v_cruise(cs, True, True, None, slc_enabled=True) + assert helper.v_cruise_kph == 72. + cs.buttonEvents = [{'type': direction, 'pressed': False}] + helper.update_v_cruise(cs, True, True, None, slc_enabled=True) + assert helper.v_cruise_kph == 72. + assert not helper.slc_suppressed_buttons diff --git a/openpilot/starpilot/ui/runtime_snapshot.py b/openpilot/starpilot/ui/runtime_snapshot.py index 294c04cac1..fb131ae799 100644 --- a/openpilot/starpilot/ui/runtime_snapshot.py +++ b/openpilot/starpilot/ui/runtime_snapshot.py @@ -681,6 +681,7 @@ class RuntimeSnapshotAdapter: cruise_state = getattr(car, 'cruiseState', None) wheel_confirmation = bool( system_long and control is not None and getattr(control, 'enabled', False) and + not (cp is not None and cp.brand == 'ford' and cp.pcmCruise) and cruise_state is not None and getattr(cruise_state, 'available', False) and not (cp is not None and getattr(cp, 'brand', '') == 'toyota' and (car.standstill or cruise_state.standstill or not cruise_state.enabled))) diff --git a/openpilot/starpilot/ui/tests/test_runtime_snapshot.py b/openpilot/starpilot/ui/tests/test_runtime_snapshot.py index 3b75501995..4cae06742d 100644 --- a/openpilot/starpilot/ui/tests/test_runtime_snapshot.py +++ b/openpilot/starpilot/ui/tests/test_runtime_snapshot.py @@ -1096,13 +1096,14 @@ class TestRuntimeSnapshot(unittest.TestCase): @pytest.mark.parametrize('brand,standstill,cruise_standstill,cruise_enabled,expected', [ ('honda', False, False, True, True), + ('ford', False, False, True, False), ('toyota', False, False, True, True), ('toyota', True, False, True, False), ('toyota', False, True, True, False), ('toyota', False, False, False, False), ]) def test_wheel_confirmation_hint_preserves_toyota_resume(brand, standstill, cruise_standstill, cruise_enabled, expected, tmp_path): - ui = vehicle_ui(tmp_path, carFingerprint='', brand=brand, openpilotLongitudinalControl=True, pcmCruise=brand == 'toyota') + ui = vehicle_ui(tmp_path, carFingerprint='', brand=brand, openpilotLongitudinalControl=True, pcmCruise=brand in ('toyota', 'ford')) car = ui.sm['carState'] car.canTimeout, car.canValid, car.standstill = False, True, standstill car.cruiseState = NS(available=True, enabled=cruise_enabled, standstill=cruise_standstill) diff --git a/prebuilt.json b/prebuilt.json index 71a0728a56..9fc5b77b43 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "2a935797b3d7b6fa6a6e0563873e4c36e7c6832e7f6ed9b9045caec3de86c908", "schema_version": 1} +{"protected_inventory_sha256": "9e5f1f5598ab2d2bd5bafffbec449239f3d5bc18b73e6be0608845e64ed6c1e0", "schema_version": 1}