mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-02 14:03:51 +08:00
Make highway smoothing available across steering controllers
This commit is contained in:
@@ -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())
|
||||
|
||||
@@ -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:]))
|
||||
|
||||
@@ -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'])
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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))
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "e80b455770749ce2f2bc062e412a31d7b516761564bc9528ded76fdab632a720", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "347561c4d9283ec7b3b41db073e05e59891fccc9e8f91e685c457e9f0c1b71b5", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user