From ec570f7ced18ce242fb860bbccd9a1f801153a10 Mon Sep 17 00:00:00 2001 From: Dom <168790843+firestar5683@users.noreply.github.com> Date: Tue, 17 Nov 2026 11:49:17 -0600 Subject: [PATCH] Make highway smoothing available across steering controllers --- openpilot/selfdrive/controls/controlsd.py | 5 ++-- .../tests/test_highway_correction_gain.py | 20 ++++++++++++++ .../galaxy/tests/test_settings_defaults.py | 27 +++++++++++++++++++ .../starpilot/lateral/tests/test_lane_host.py | 4 +-- .../tests/test_gm_volt_long_policy.py | 4 +-- .../starpilot/ui/feature_settings_owner.py | 4 +-- prebuilt.json | 2 +- 7 files changed, 57 insertions(+), 9 deletions(-) diff --git a/openpilot/selfdrive/controls/controlsd.py b/openpilot/selfdrive/controls/controlsd.py index d87c6300a4..8c639d9d4d 100755 --- a/openpilot/selfdrive/controls/controlsd.py +++ b/openpilot/selfdrive/controls/controlsd.py @@ -51,7 +51,8 @@ from openpilot.starpilot.lateral.lane_change_preferences import LiveLaneChangePo from openpilot.starpilot.lateral.lane_change_smoothing import LaneChangeSmoother, limit_rate from openpilot.starpilot.lateral.lane_runtime import LaneCenteringHost, runtime_supported as lane_runtime_supported from openpilot.starpilot.lateral.torque_runtime import TorqueHost, runtime_enabled as torque_runtime_enabled -from openpilot.starpilot.lateral.controller_selection import learning_allowed, read_selection, turn_assist_supported +from openpilot.starpilot.feature_capabilities import lateral_supported +from openpilot.starpilot.lateral.controller_selection import learning_allowed, read_selection from openpilot.starpilot.lateral.gain_runtime import create_gain_owner from openpilot.starpilot.flm.global_runtime import GlobalRuntime from openpilot.starpilot.flm.evidence_hooks import control_message @@ -126,7 +127,7 @@ class Controls: LaneCenteringController(body=interface_dimensions(self.CI, self.CP), body_required=True) if predict_lane_clearance else LaneCenteringController() ) self.highway_correction_gain = HighwayCorrectionGain() - self.highway_smoothing_supported = turn_assist_supported(self.CP) + self.highway_smoothing_supported = lateral_supported(self.CP) self.highway_gain = read_gain(self.params) if self.highway_smoothing_supported else 1.0 self.lateral_pause = LateralPause(read_lateral_pause(self.params), self.params) self.lane_change_preferences = LiveLaneChangePolicy(self.params, now_ns=0 if os.getenv('REPLAY') == '1' else time.monotonic_ns()) diff --git a/openpilot/selfdrive/controls/tests/test_highway_correction_gain.py b/openpilot/selfdrive/controls/tests/test_highway_correction_gain.py index 79af92cb4f..0fc872f171 100644 --- a/openpilot/selfdrive/controls/tests/test_highway_correction_gain.py +++ b/openpilot/selfdrive/controls/tests/test_highway_correction_gain.py @@ -205,3 +205,23 @@ def test_read_gain_maps_setting_and_treats_invalid_as_off(tmp_path): for raw, gain in ((b"10", 1.0), (b"3", 0.3), (b"1", 0.1), (b"0", 1.0), (b"0.5", 1.0), (b"11", 1.0), (b"nan", 1.0), (b"x", 1.0)): (tmp_path / KEY).write_bytes(raw) assert math.isclose(read_gain(params), gain), raw + + +def test_smoothing_capability_independent_of_controller_type(): + from opendbc.car import structs + from opendbc.car.car_helpers import interfaces + from opendbc.car.ford.values import CAR + from openpilot.starpilot.feature_capabilities import lateral_supported + cp = interfaces[CAR.FORD_MUSTANG_MACH_E_MK1].get_non_essential_params(CAR.FORD_MUSTANG_MACH_E_MK1) + raw = _weave() + for steer_type, tuning in ((structs.CarParams.SteerControlType.curvature, 'pid'), + (structs.CarParams.SteerControlType.angle, 'pid'), + (structs.CarParams.SteerControlType.torque, 'pid'), + (structs.CarParams.SteerControlType.torque, 'torque')): + cp.steerControlType = steer_type + cp.lateralTuning.init(tuning) + assert lateral_supported(cp) + # Zero percent remains exact pass-through; enabled smoothing acts on the same + # curvature command before any controller consumes it. + np.testing.assert_array_equal(_run(HighwayCorrectionGain(), raw, gain=1.), raw) + assert np.max(np.abs(_run(HighwayCorrectionGain(), raw, gain=.37)[-1000:])) < np.max(np.abs(raw[-1000:])) diff --git a/openpilot/starpilot/galaxy/tests/test_settings_defaults.py b/openpilot/starpilot/galaxy/tests/test_settings_defaults.py index 023060956e..6a75e4b96b 100644 --- a/openpilot/starpilot/galaxy/tests/test_settings_defaults.py +++ b/openpilot/starpilot/galaxy/tests/test_settings_defaults.py @@ -287,3 +287,30 @@ def test_enrollment_then_galaxy_custom_strength_persists_across_startups(gateway retire_settings(gateway.params) assert slider(gateway)[2]['value'] == '70' assert read_gain(gateway.params) == pytest.approx(.37) + + +@pytest.mark.parametrize('saved_mode', [b'1', b'2', b'3']) +def test_ford_all_controllers_expose_and_save_highway_smoothing(gateway, saved_mode): + from opendbc.car.car_helpers import interfaces + from opendbc.car.ford.values import CAR + from openpilot.starpilot.car.ford.controller_selection import KEY as FORD_MODE + from openpilot.starpilot.feature_capabilities import lateral_supported + from openpilot.starpilot.lateral.controller_selection import turn_assist_supported + cp = interfaces[CAR.FORD_MUSTANG_MACH_E_MK1].get_non_essential_params(CAR.FORD_MUSTANG_MACH_E_MK1) + gateway.context.value = AuthorityContext(True, cp, cp.as_reader().as_builder().to_bytes()) + gateway.params.put(FORD_MODE, int(saved_mode), block=True) + assert lateral_supported(cp) and not turn_assist_supported(cp) + page, index, row = slider(gateway) + assert row['available'] + intent = gateway.gateway.preview(page['view'], index, 0, gateway.session, gateway.generation, value=70) + assert gateway.gateway.confirm(intent['intent'], gateway.session, gateway.generation) + assert read_gain(gateway.params) == pytest.approx(.37) + assert read_saved(gateway.params, FORD_MODE, 16)[0] == saved_mode + + +@pytest.mark.parametrize('flag', ['passive', 'dashcamOnly', 'notCar']) +def test_smoothing_still_requires_real_controllable_vehicle(gateway, flag): + _, cp = ioniq_candidate() + setattr(cp, flag, True) + gateway.context.value = AuthorityContext(True, cp, cp.as_reader().as_builder().to_bytes()) + assert not any(row['label'] == 'Highway Smoothing' for row in gateway.page('torque')['rows']) diff --git a/openpilot/starpilot/lateral/tests/test_lane_host.py b/openpilot/starpilot/lateral/tests/test_lane_host.py index 354afd32b6..a2cc561d07 100644 --- a/openpilot/starpilot/lateral/tests/test_lane_host.py +++ b/openpilot/starpilot/lateral/tests/test_lane_host.py @@ -33,7 +33,7 @@ def probe(output, reference_method=None): from openpilot.selfdrive.controls.lib.latcontrol_torque import LatControlTorque from openpilot.selfdrive.controls.lib.longcontrol import LongControl from openpilot.selfdrive.controls.lib.highway_correction_gain import HighwayCorrectionGain, read_gain - from openpilot.starpilot.lateral.controller_selection import turn_assist_supported + from openpilot.starpilot.feature_capabilities import lateral_supported from openpilot.starpilot.longitudinal.ioniq6_start import eligible as ioniq6_start_eligible from openpilot.starpilot.longitudinal.tests.extension_helpers import attach_inputs from openpilot.starpilot.lateral.lane_centering import ControlMode, LaneCenteringController, LaneCenteringRequest, LaneCenteringSettings @@ -68,7 +68,7 @@ def probe(output, reference_method=None): control.lane_centering_controller = LaneCenteringController() control.params = Params() control.highway_correction_gain = HighwayCorrectionGain() - control.highway_smoothing_supported = turn_assist_supported(control.CP) + control.highway_smoothing_supported = lateral_supported(control.CP) control.highway_gain = read_gain(control.params) if control.highway_smoothing_supported else 1.0 control.lane_change_preferences = LiveLaneChangePolicy(control.params, now_ns=1_000_000_000) control.lane_change_policy = control.lane_change_preferences.applied diff --git a/openpilot/starpilot/longitudinal/tests/test_gm_volt_long_policy.py b/openpilot/starpilot/longitudinal/tests/test_gm_volt_long_policy.py index 25594036fe..cd868f5c4f 100644 --- a/openpilot/starpilot/longitudinal/tests/test_gm_volt_long_policy.py +++ b/openpilot/starpilot/longitudinal/tests/test_gm_volt_long_policy.py @@ -9,7 +9,7 @@ from unittest.mock import Mock, MagicMock from openpilot.cereal.messaging import SubMaster from openpilot.selfdrive.controls.lib.latcontrol import LatControl from openpilot.selfdrive.controls.lib.highway_correction_gain import HighwayCorrectionGain, read_gain -from openpilot.starpilot.lateral.controller_selection import turn_assist_supported +from openpilot.starpilot.feature_capabilities import lateral_supported from openpilot.starpilot.lateral.lane_centering import LaneCenteringController from openpilot.starpilot.longitudinal.extension import LongitudinalContext @@ -103,7 +103,7 @@ def controls_fixture(alpha=False): finalize(controls, saved.cleanup) controls.params = Params(saved.name) controls.highway_correction_gain = HighwayCorrectionGain() - controls.highway_smoothing_supported = turn_assist_supported(controls.CP) + controls.highway_smoothing_supported = lateral_supported(controls.CP) controls.highway_gain = read_gain(controls.params) if controls.highway_smoothing_supported else 1.0 controls.lane_change_preferences = LiveLaneChangePolicy(controls.params, now_ns=now) controls.lane_change_policy = controls.lane_change_preferences.applied diff --git a/openpilot/starpilot/ui/feature_settings_owner.py b/openpilot/starpilot/ui/feature_settings_owner.py index 7086f68df4..b5847df776 100644 --- a/openpilot/starpilot/ui/feature_settings_owner.py +++ b/openpilot/starpilot/ui/feature_settings_owner.py @@ -812,9 +812,9 @@ class FeatureSettingsOwner: return result.committed and result.verified def _highway_smoothing_capability(self) -> tuple | None: - from openpilot.starpilot.lateral.controller_selection import turn_assist_supported + from openpilot.starpilot.feature_capabilities import lateral_supported cp = self.vehicle_params() - if cp is None or not turn_assist_supported(cp): + if cp is None or not lateral_supported(cp): return None return (cp.carFingerprint, cp.lateralTuning.which(), str(cp.steerControlType), cp.passive, cp.dashcamOnly, cp.notCar, tuple((str(config.safetyModel), int(config.safetyParam)) for config in cp.safetyConfigs)) diff --git a/prebuilt.json b/prebuilt.json index cebe3bf42e..6a52271f8e 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "e80b455770749ce2f2bc062e412a31d7b516761564bc9528ded76fdab632a720", "schema_version": 1} +{"protected_inventory_sha256": "347561c4d9283ec7b3b41db073e05e59891fccc9e8f91e685c457e9f0c1b71b5", "schema_version": 1}