diff --git a/openpilot/selfdrive/controls/controlsd.py b/openpilot/selfdrive/controls/controlsd.py index b86c14d049..2450471d86 100755 --- a/openpilot/selfdrive/controls/controlsd.py +++ b/openpilot/selfdrive/controls/controlsd.py @@ -198,17 +198,10 @@ class Controls: from openpilot.starpilot.lateral.learning_preferences import read_preference preference = read_preference(self.params, self.CP) - from openpilot.starpilot.lateral.torque_supported import GM_VEHICLES - - custom_fixed_gain = self.lateral_gain_owner is not None and str(self.CP.carFingerprint) not in GM_VEHICLES - if custom_fixed_gain: - # Saved route effects and live trials require the original controller gains. - self.route_flm_status = 'context_changed' - else: - _, self.route_flm_status = self._configure_route_tune(manual_status) + _, self.route_flm_status = self._configure_route_tune(manual_status) self.global_learning = ( GlobalRuntime(self.CP, self.CI, self.LaC, confirmed_live_history=load_confirmed_history(self.params)) - if preference.valid and preference.enabled and not custom_fixed_gain else None + if preference.valid and preference.enabled else None ) # Load optional capture and live-trial code before the first control command. # Engagement must not compile/import replay and feedback modules in the loop. diff --git a/openpilot/starpilot/flm/controller_replay.py b/openpilot/starpilot/flm/controller_replay.py index 8679617445..1a9b50051f 100644 --- a/openpilot/starpilot/flm/controller_replay.py +++ b/openpilot/starpilot/flm/controller_replay.py @@ -366,7 +366,7 @@ class _FrictionRecorder: class SelectedControllerFactory: """Frozen registered CP and selected mode; construct only in learner process.""" - def __init__(self, cp, mode, *, turn_assist=False, manual_baseline=(), manual_source_epoch=""): + def __init__(self, cp, mode, *, turn_assist=False, manual_baseline=(), manual_source_epoch="", manual_kp=None): from opendbc.car.car_helpers import interfaces from openpilot.starpilot.lateral.controller_selection import ControllerMode, policy_for @@ -379,6 +379,7 @@ class SelectedControllerFactory: self.turn_assist = bool(turn_assist) self.interface_class = interfaces[cp.carFingerprint] self.manual_baseline, self.manual_source_epoch = tuple(manual_baseline), manual_source_epoch + self.manual_kp = manual_kp if self.manual_baseline: from openpilot.starpilot.lateral.torque_settings import bounds @@ -397,7 +398,8 @@ class SelectedControllerFactory: or any(c not in '0123456789abcdef' for c in manual_source_epoch) ): raise ValueError('independent fixed manual constructor source') - elif manual_source_epoch: + elif bool(manual_source_epoch) != (manual_kp is not None) or manual_source_epoch and ( + type(manual_source_epoch) is not str or len(manual_source_epoch) != 64 or any(c not in '0123456789abcdef' for c in manual_source_epoch)): raise ValueError('manual source epoch without selected manual configuration') def create(self): @@ -412,6 +414,9 @@ class SelectedControllerFactory: controller = create_lateral_controller(self.cp, ci, 0.01, mode=self.mode, turn_assist=self.turn_assist) if controller.controller_policy != self.policy: raise ValueError('selected policy mismatch') + if self.manual_kp is not None: + from openpilot.starpilot.lateral.gain_runtime import install_fixed_kp + install_fixed_kp(self.cp, controller, self.manual_kp) if self.manual_baseline: controller.update_torque_parameters(*self.manual_baseline) return controller, VehicleModel(self.cp) @@ -1501,6 +1506,7 @@ class ControllerReplay: 'mode': str(self.factory.mode), 'turn_assist': self.factory.turn_assist, 'manual_baseline': self.factory.manual_baseline, + **({'manual_kp': self.factory.manual_kp} if self.factory.manual_kp is not None else {}), 'manual_source_epoch': self.factory.manual_source_epoch, 'objective': asdict(self.objective), 'identity': self.identity, @@ -1565,6 +1571,7 @@ class ControllerReplay: or values.get('mode') != str(factory.mode) or values.get('turn_assist') != factory.turn_assist or tuple(values.get('manual_baseline', ())) != factory.manual_baseline + or values.get('manual_kp') != factory.manual_kp or values.get('manual_source_epoch', '') != factory.manual_source_epoch or values.get('cp_bytes') != factory.cp.as_builder().to_bytes() ): @@ -1708,8 +1715,9 @@ def factory_from_snapshot(data): turn_assist=values['turn_assist'], manual_baseline=tuple(values.get('manual_baseline', ())), manual_source_epoch=values.get('manual_source_epoch', ''), + manual_kp=values.get('manual_kp'), ) - if factory.manual_baseline: + if factory.manual_baseline or factory.manual_kp is not None: from openpilot.starpilot.flm.runtime_adapter_registry import baseline_values, baseline_revision, selected_descriptor, selected_identity controller, _ = factory.create() diff --git a/openpilot/starpilot/flm/learner_factory.py b/openpilot/starpilot/flm/learner_factory.py index e906ad7123..ddb8ee129f 100644 --- a/openpilot/starpilot/flm/learner_factory.py +++ b/openpilot/starpilot/flm/learner_factory.py @@ -137,18 +137,21 @@ class TorqueCollectionAdapter: if evidence.stage_schema_revision != self.raw_stage_revision: raise ValueError('actual raw stage trace') manual_baseline = () + manual_kp = None if source is not None: from openpilot.starpilot.flm.runtime_adapter_registry import car_params_digest if not source.enabled or source.manual or source.source_epoch != evidence.source_epoch or source.cp_sha256 != car_params_digest(cp): raise ValueError('independent current manual configuration source') manual_baseline = source.manual_baseline + manual_kp = source.manual_kp factory = self.factory_type( cp, evidence.controller_mode, turn_assist=evidence.turn_assist, manual_baseline=manual_baseline, - manual_source_epoch=evidence.source_epoch if manual_baseline else '', + manual_source_epoch=evidence.source_epoch if manual_baseline or manual_kp is not None else '', + manual_kp=manual_kp, ) controller, vm = factory.create() from openpilot.starpilot.flm.native_baseline import static_values diff --git a/openpilot/starpilot/flm/live_tracking_probe.py b/openpilot/starpilot/flm/live_tracking_probe.py index bfa74b40f6..5dc6d8f1d0 100644 --- a/openpilot/starpilot/flm/live_tracking_probe.py +++ b/openpilot/starpilot/flm/live_tracking_probe.py @@ -819,6 +819,7 @@ def probe_endpoint( or current_vehicle_model_anchor != getattr(control, 'vehicle_model_anchor', None) or digest(vm_regime(dict(control.replay_inputs), current_vehicle_model_anchor)) != binding.vehicle_model_generation or tuple(factory.manual_baseline) != tuple(source.manual_baseline) + or factory.manual_kp != source.manual_kp or car_params_digest(factory.cp) != binding.cp_sha256 or (control.identity, control.source_epoch, control.baseline_revision, control.controller_revision, control.native_identity) != (binding.identity, binding.source_epoch, binding.baseline_revision, binding.controller_revision, binding.native_identity) diff --git a/openpilot/starpilot/flm/live_tracking_probe_process.py b/openpilot/starpilot/flm/live_tracking_probe_process.py index a6b776fe85..351b47f850 100644 --- a/openpilot/starpilot/flm/live_tracking_probe_process.py +++ b/openpilot/starpilot/flm/live_tracking_probe_process.py @@ -184,6 +184,7 @@ def probe_replay_snapshot(replay, prefix_controls, *, endpoint_output=None): 'mode': mode, 'turn_assist': factory.turn_assist, 'manual_baseline': factory.manual_baseline, + **({'manual_kp': factory.manual_kp} if factory.manual_kp is not None else {}), 'manual_source_epoch': factory.manual_source_epoch, 'objective': _plain(replay.objective, Objective), 'identity': replay.identity, diff --git a/openpilot/starpilot/flm/offroad_runtime.py b/openpilot/starpilot/flm/offroad_runtime.py index 1e4e896067..a51991a17a 100644 --- a/openpilot/starpilot/flm/offroad_runtime.py +++ b/openpilot/starpilot/flm/offroad_runtime.py @@ -331,6 +331,10 @@ def _current_controller(cp, params): mode = 'native' if cp.lateralTuning.which() == 'pid' else str(read_selection(params, cp).mode) factory = PidControllerFactory(cp, mode) if cp.lateralTuning.which() == 'pid' else SelectedControllerFactory(cp, mode, turn_assist=startup.turn_assist) controller, _ = factory.create() + from openpilot.starpilot.lateral.gain_runtime import create_gain_owner + from openpilot.starpilot.lateral.torque_supported import GM_VEHICLES + if str(cp.carFingerprint) not in GM_VEHICLES: + create_gain_owner(params, cp, controller) ci = interfaces[str(cp.carFingerprint)](cp) return ci, controller diff --git a/openpilot/starpilot/flm/original_context_receipts.py b/openpilot/starpilot/flm/original_context_receipts.py index 925dbb2da8..d10bdbb266 100644 --- a/openpilot/starpilot/flm/original_context_receipts.py +++ b/openpilot/starpilot/flm/original_context_receipts.py @@ -340,6 +340,7 @@ def verify_original_replay(packet, template_engine, replay_bytes): data['identity'] != engine.identity or data['baseline_revision'] != engine.baseline_revision or data['mode'] != str(engine.factory.mode) or data['turn_assist'] != engine.factory.turn_assist or tuple(data.get('manual_baseline',())) != engine.factory.manual_baseline or + data.get('manual_kp') != engine.factory.manual_kp or data.get('manual_source_epoch','') != engine.factory.manual_source_epoch or data['objective'] != asdict(engine.engine.objective)): raise ValueError('original context actual selected replay factory') diff --git a/openpilot/starpilot/flm/original_source_capture.py b/openpilot/starpilot/flm/original_source_capture.py index 7ffa558fc1..71aa8d5026 100644 --- a/openpilot/starpilot/flm/original_source_capture.py +++ b/openpilot/starpilot/flm/original_source_capture.py @@ -375,7 +375,8 @@ def export_packet(adapter, collector, windows, now_ns): 'controller_revision': adapter.controller_revision, 'model_revision': engine.model_revision, 'raw_mode': engine.raw_mode, 'mode': str(engine.factory.mode), 'turn_assist': engine.factory.turn_assist, 'manual_baseline': engine.factory.manual_baseline, - 'manual_source_epoch': engine.factory.manual_source_epoch, 'checkpoints': checkpoints}, + 'manual_source_epoch': engine.factory.manual_source_epoch, 'checkpoints': checkpoints, + **({'manual_kp': engine.factory.manual_kp} if engine.factory.manual_kp is not None else {})}, 'counts': {'source_poses': len(rows), 'frames': len(frames), 'emissions': len(tape['events']), 'carriers': len(tape['carriers']), 'windows': len(windows), 'span_ns': windows[-1][1] - windows[0][0]}, 'retained_raw_counts': {'legacy': retained_legacy, 'pending': retained_pending, 'original': len(capture.rows)}, diff --git a/openpilot/starpilot/flm/pid_controller_replay.py b/openpilot/starpilot/flm/pid_controller_replay.py index bb943c8b08..938b5dc6f5 100644 --- a/openpilot/starpilot/flm/pid_controller_replay.py +++ b/openpilot/starpilot/flm/pid_controller_replay.py @@ -66,16 +66,19 @@ def restore_pid_snapshot(controller, vm, snapshot): class PidControllerFactory: - def __init__(self, cp, mode, *, turn_assist=False, manual_baseline=(), manual_source_epoch=''): + def __init__(self, cp, mode, *, turn_assist=False, manual_baseline=(), manual_source_epoch='', manual_kp=None): from opendbc.car import structs from opendbc.car.car_helpers import interfaces if (cp.notCar or cp.passive or cp.dashcamOnly or str(cp.carFingerprint) not in interfaces or cp.lateralTuning.which() != 'pid' or - str(cp.steerControlType) != 'torque' or mode != 'native' or turn_assist or manual_baseline or manual_source_epoch): + str(cp.steerControlType) != 'torque' or mode != 'native' or turn_assist or manual_baseline): raise ValueError('registered stock torque PID configuration') self.cp = structs.CarParams.new_message(**cp.to_dict()).as_reader() self.mode, self.turn_assist = 'native', False self.interface_class = interfaces[str(cp.carFingerprint)] - self.manual_baseline, self.manual_source_epoch = (), '' + if bool(manual_source_epoch) != (manual_kp is not None) or manual_source_epoch and ( + type(manual_source_epoch) is not str or len(manual_source_epoch) != 64 or any(c not in '0123456789abcdef' for c in manual_source_epoch)): + raise ValueError('fixed PID gain source requires its settings epoch') + self.manual_baseline, self.manual_source_epoch, self.manual_kp = (), manual_source_epoch, manual_kp def create(self): from opendbc.car.vehicle_model import VehicleModel @@ -85,6 +88,9 @@ class PidControllerFactory: controller = create_lateral_controller(self.cp, ci, .01, mode='native', turn_assist=False) if type(controller) is not LatControlPID: raise ValueError('actual stock PID constructor mismatch') + if self.manual_kp is not None: + from openpilot.starpilot.lateral.gain_runtime import install_fixed_kp + install_fixed_kp(self.cp, controller, self.manual_kp) return controller, VehicleModel(self.cp) diff --git a/openpilot/starpilot/flm/runtime_adapter_registry.py b/openpilot/starpilot/flm/runtime_adapter_registry.py index 5f65345255..d8a550baea 100644 --- a/openpilot/starpilot/flm/runtime_adapter_registry.py +++ b/openpilot/starpilot/flm/runtime_adapter_registry.py @@ -235,6 +235,7 @@ class SourceState: manual_baseline: tuple[float, ...] = field(default=(), compare=False, repr=False) # Internal only: absent current configuration proof is not an explicit OFF. configuration_known: bool = True + manual_kp: float | None = field(default=None, compare=False, repr=False) def read_source(cp, params, *, now_ns, cp_sha256=None, calibration=(), vehicle_session="", calibration_generation=''): @@ -273,7 +274,8 @@ def read_source(cp, params, *, now_ns, cp_sha256=None, calibration=(), vehicle_s raise ValueError('invalid actual startup turn-assist choice') from openpilot.starpilot.lateral.controller_selection import selection_from_bytes - if selection_from_bytes(cp, raw_by_key['LateralControllerSelection']).source == 'invalid': + selection = selection_from_bytes(cp, raw_by_key['LateralControllerSelection']) + if selection.source == 'invalid': raise ValueError('invalid saved controller configuration') reset_raw = raw_by_key['AutoSteeringLearningReset'] reset = '0' if reset_raw is None else reset_raw.decode('ascii') @@ -282,9 +284,12 @@ def read_source(cp, params, *, now_ns, cp_sha256=None, calibration=(), vehicle_s document = raw_by_key[DOCUMENT_KEY] manual = False fixed_manual = () + manual_kp = None if document is not None: profile = parse_document(document).get(str(cp.carFingerprint)) if profile is not None: + from openpilot.starpilot.lateral.gain_runtime import fixed_kp_from_profile + manual_kp = fixed_kp_from_profile(cp, selection, profile) if cp.lateralTuning.which() == 'torque': tune = cp.lateralTuning.torque if profile.basis != (float(tune.latAccelFactor), float(tune.latAccelOffset), float(tune.friction)): @@ -369,6 +374,7 @@ def read_source(cp, params, *, now_ns, cp_sha256=None, calibration=(), vehicle_s calibration_generation=calibration_generation, persistent_source_epoch=persistent_epoch, manual_baseline=fixed_manual, + manual_kp=manual_kp, ) except (AttributeError, UnicodeError, TypeError, ValueError, OSError, OverflowError): return SourceState(False, False, '', '', now_ns, now_ns + SOURCE_LEASE_NS, cp_sha256, configuration_known=False) diff --git a/openpilot/starpilot/flm/source_plant_pipeline.py b/openpilot/starpilot/flm/source_plant_pipeline.py index 7eaf811325..af9931886d 100644 --- a/openpilot/starpilot/flm/source_plant_pipeline.py +++ b/openpilot/starpilot/flm/source_plant_pipeline.py @@ -46,7 +46,8 @@ def replay_data(packet, *, objective, identity, baseline_revision): data = {'version':2 if normalized else 1,'raw_mode':True, 'cp_bytes':bytes.fromhex(original['cp_bytes_hex']), 'mode':original['mode'], 'turn_assist':original['turn_assist'], 'manual_baseline':tuple(original['manual_baseline']), - 'manual_source_epoch':original['manual_source_epoch'], 'objective':asdict(objective), + 'manual_source_epoch':original['manual_source_epoch'], + **({'manual_kp': original['manual_kp']} if 'manual_kp' in original else {}), 'objective':asdict(objective), 'identity':identity, 'baseline_revision':baseline_revision,'model_revision':original['model_revision'], 'windows':((first,last),),'checkpoints':tuple((stamp,revision,tuple(tuple(pair) for pair in values)) for stamp,revision,values in original['checkpoints']), 'frames':frames,'emissions':packet['actual_command_tape']} @@ -111,6 +112,7 @@ def _stage_engine(original, cutoff, *, context_packet=None): data = {'version':1,'raw_mode':True,'cp_bytes':original.factory.cp.as_builder().to_bytes(), 'mode':str(original.factory.mode),'turn_assist':original.factory.turn_assist, 'manual_baseline':original.factory.manual_baseline,'manual_source_epoch':original.factory.manual_source_epoch, + **({'manual_kp': original.factory.manual_kp} if original.factory.manual_kp is not None else {}), 'objective':asdict(original.engine.objective),'identity':original.identity, 'baseline_revision':original.baseline_revision,'model_revision':original.engine.model_revision, 'windows':tuple(chosen),'checkpoints':tuple((stamp,cp.revision,cp.values) for stamp,cp in original.checkpoints diff --git a/openpilot/starpilot/flm/steerlearnerd.py b/openpilot/starpilot/flm/steerlearnerd.py index 8e2824d66b..90456528ae 100644 --- a/openpilot/starpilot/flm/steerlearnerd.py +++ b/openpilot/starpilot/flm/steerlearnerd.py @@ -154,7 +154,7 @@ def _collect_applied_output(collector, applied, sm, cp, now_ns): def _source_config_binding(source): return (source.cp_sha256, source.source_epoch, source.reset, source.calibration_generation, - source.enabled, source.manual, source.persistent_source_epoch, tuple(source.manual_baseline)) + source.enabled, source.manual, source.persistent_source_epoch, tuple(source.manual_baseline), source.manual_kp) def _source_config_known(source, now_ns): @@ -173,7 +173,8 @@ def _source_config_known(source, now_ns): type(source.persistent_source_epoch) is str and (not source.persistent_source_epoch or len(source.persistent_source_epoch) == 64 and not source.persistent_source_epoch.strip('0123456789abcdef')) and type(source.manual_baseline) is tuple and len(source.manual_baseline) in (0, 3) and - all(type(value) in (int, float) and math.isfinite(value) for value in source.manual_baseline)) + all(type(value) in (int, float) and math.isfinite(value) for value in source.manual_baseline) and + (source.manual_kp is None or type(source.manual_kp) in (int, float) and math.isfinite(source.manual_kp))) def _pause_historical_collector(collector, reason): diff --git a/openpilot/starpilot/lateral/gain_runtime.py b/openpilot/starpilot/lateral/gain_runtime.py index fd7c80fe3f..f4346eee96 100644 --- a/openpilot/starpilot/lateral/gain_runtime.py +++ b/openpilot/starpilot/lateral/gain_runtime.py @@ -2,6 +2,7 @@ from __future__ import annotations +import math import time from opendbc.car.interfaces import get_torque_params @@ -9,7 +10,7 @@ from openpilot.starpilot.car.volkswagen.model_smoothing import supported as fact from openpilot.starpilot.lateral.torque_runtime import gm_manual_supported_cp, production_supported_cp from openpilot.starpilot.lateral.torque_supported import BOLT_VEHICLES, GM_VEHICLES -from openpilot.starpilot.lateral.torque_settings import DOCUMENT_KEY, MAX_DOCUMENT_BYTES, GainBasis, parse_document +from openpilot.starpilot.lateral.torque_settings import DOCUMENT_KEY, MAX_DOCUMENT_BYTES, GainBasis, gain_bounds, parse_document from openpilot.starpilot.saved_source import read_saved REFRESH_NS = 1_000_000_000 @@ -45,6 +46,33 @@ def gain_basis(cp, controller) -> GainBasis: (tune.latAccelFactor, tune.latAccelOffset, tune.friction)) +def fixed_kp_from_profile(cp, selection, profile) -> float | None: + if profile is None or profile.proportional_gain.mode != 'custom' or str(cp.carFingerprint) in GM_VEHICLES or not gain_supported(cp): + return None + if cp.lateralTuning.which() == 'pid': + basis = pid_gain_basis(cp) + else: + from openpilot.selfdrive.controls.lib.latcontrol_torque import INTERP_SPEEDS, KP_INTERP, STARPILOT_KP + tune = cp.lateralTuning.torque + table = ((0.,), (STARPILOT_KP,)) if selection.mode.value == 'starpilot' else (tuple(INTERP_SPEEDS), tuple(KP_INTERP)) + basis = GainBasis(selection.mode.value, table, (tune.latAccelFactor, tune.latAccelOffset, tune.friction)) + return profile.proportional_gain.custom_value if profile.gain_basis == basis else None + + +def install_fixed_kp(cp, controller, value) -> None: + if not gain_supported(cp) or str(cp.carFingerprint) in GM_VEHICLES or type(value) not in (int, float) or not math.isfinite(value): + raise ValueError('Invalid fixed proportional gain') + basis = gain_basis(cp, controller) + low, high = gain_bounds(str(cp.carFingerprint), basis) + if not low <= value <= high: + raise ValueError('Out-of-range fixed proportional gain') + speeds, gains = basis.source_table + controller.pid._k_p = [list(speeds), [gain * value / gains[-1] for gain in gains]] + if hasattr(controller, 'native_learning_baseline'): + from openpilot.starpilot.flm.runtime_adapter_registry import baseline_values + controller.native_learning_baseline = baseline_values(controller) + + def _selected(params, cp, basis: GainBasis) -> float | None: try: if str(cp.carFingerprint) in BOLT_VEHICLES: @@ -70,16 +98,13 @@ class GenericGainOwner: self.basis = basis self.last_refresh_ns: int | None = None self.current_table = basis.source_table - self._apply(value) + if str(cp.carFingerprint) in GM_VEHICLES: + self._apply(value) + else: + install_fixed_kp(cp, controller, value) def _apply(self, value: float | None) -> None: - table = self.basis.source_table - if value is not None: - if str(self.cp.carFingerprint) in GM_VEHICLES: - table = ((0.0,), (value,)) - else: - speeds, gains = table - table = (speeds, tuple(gain * value / gains[-1] for gain in gains)) + table = self.basis.source_table if value is None else ((0.0,), (value,)) if table != self.current_table: self.pid._k_p = [list(row) for row in table] self.current_table = table diff --git a/openpilot/starpilot/lateral/tests/test_lateral_kp.py b/openpilot/starpilot/lateral/tests/test_lateral_kp.py index 1e1bba3adc..bb5f55ad0a 100644 --- a/openpilot/starpilot/lateral/tests/test_lateral_kp.py +++ b/openpilot/starpilot/lateral/tests/test_lateral_kp.py @@ -13,12 +13,49 @@ from openpilot.starpilot.ui.feature_settings_owner import FeatureSettingsOwner from openpilot.starpilot.ui.feature_settings_state import FeaturePage, row_change +def assert_flm_fixed_gain(cp, params, controls, expected): + from openpilot.starpilot.flm.controller_replay import SelectedControllerFactory, factory_from_snapshot, pack_primitive_snapshot + from openpilot.starpilot.flm.offroad_runtime import current_configuration + from openpilot.starpilot.flm.pid_controller_replay import PidControllerFactory + from openpilot.starpilot.flm.runtime_adapter_registry import baseline_values, read_source, selected_identity + + assert controls.global_learning is not None and controls.global_learning.descriptor is not None + assert controls.LaC.route_flm_scope is not None + scope, descriptor, numeric = current_configuration(cp, params) + assert scope == controls.LaC.route_flm_scope + assert numeric == baseline_values(controls.LaC) + source = read_source(cp, params, now_ns=1_000_000_000, calibration=(0., 0., 0.)) + assert source.enabled and not source.manual and source.manual_kp == expected + assert not source.manual_baseline + factory_type = PidControllerFactory if cp.lateralTuning.which() == 'pid' else SelectedControllerFactory + factory = factory_type(cp, descriptor.controller_mode, turn_assist=descriptor.turn_assist, + manual_source_epoch=source.source_epoch, manual_kp=source.manual_kp) + replay, _ = factory.create() + assert baseline_values(replay) == numeric + snapshot = { + 'cp_bytes': cp.as_reader().as_builder().to_bytes(), + 'mode': descriptor.controller_mode, + 'turn_assist': descriptor.turn_assist, + 'manual_source_epoch': source.source_epoch, + 'manual_kp': expected, + 'baseline_revision': scope.baseline_revision, + 'identity': selected_identity(descriptor, source.source_epoch, scope.baseline_revision), + 'objective': {'stage': 'feedforward', 'speed_band': 'high', 'phase': 'steady'}, + } + child, _ = factory_from_snapshot(pack_primitive_snapshot(snapshot)) + assert baseline_values(child.create()[0]) == numeric + with pytest.raises(ValueError, match='fixed manual child configuration identity'): + factory_from_snapshot(pack_primitive_snapshot(dict(snapshot, manual_kp=expected + 0.01))) + + def test_golf_parked_gain_setting_reaches_controls_at_restart(monkeypatch): monkeypatch.setenv("SIMULATION", "1") monkeypatch.setenv("REPLAY", "1") cp = CarInterface.get_params(CAR.VOLKSWAGEN_GOLF_MK7, {i: {0xFD: 8} if i == 1 else {} for i in range(8)}, [], True, False, False) + cp.carVin = "WVWZZZAUZGW123456" with OpenpilotPrefix(): params = Params() + params.put_bool("OpenpilotEnabledToggle", True, block=True) params.put("CarParams", cp.to_bytes(), block=True) parked = True owner = FeatureSettingsOwner(params, lambda group: parked or group != "parked_preferences", @@ -47,6 +84,7 @@ def test_golf_parked_gain_setting_reaches_controls_at_restart(monkeypatch): assert tuple(selected.LaC.pid._k_p[1]) == pytest.approx((0.5,)) assert tuple(selected.LaC.pid._k_i[1]) == tuple(baseline.LaC.pid._k_i[1]) assert selected.LaC.ff_factor == baseline.LaC.ff_factor + assert_flm_fixed_gain(cp, params, selected, 0.5) reset = row_change(row("torque:gain:mode"), -1) assert reset is not None and owner.apply(reset) assert Controls().lateral_gain_owner is None @@ -63,8 +101,10 @@ def test_standard_torque_gain_preserves_the_speed_schedule(monkeypatch): monkeypatch.setenv("SIMULATION", "1") monkeypatch.setenv("REPLAY", "1") cp = CarInterface.get_params(CAR.VOLKSWAGEN_SHARAN_MK2, {i: {0x1A0: 8} if i == 1 else {} for i in range(8)}, [], False, False, False) + cp.carVin = "WVWZZZAUZGW123456" with OpenpilotPrefix(): params = Params() + params.put_bool("OpenpilotEnabledToggle", True, block=True) params.put("CarParams", cp.to_bytes(), block=True) baseline = Controls() assert gain_supported(cp) @@ -77,3 +117,4 @@ def test_standard_torque_gain_preserves_the_speed_schedule(monkeypatch): assert tuple(selected.LaC.pid._k_p[0]) == speeds assert tuple(selected.LaC.pid._k_p[1]) == pytest.approx(tuple(gain * requested / gains[-1] for gain in gains)) assert selected.LaC.pid._k_i == baseline.LaC.pid._k_i + assert_flm_fixed_gain(cp, params, selected, requested) diff --git a/openpilot/starpilot/ui/gain_feature.py b/openpilot/starpilot/ui/gain_feature.py index cfa400a5e3..19cfebb995 100644 --- a/openpilot/starpilot/ui/gain_feature.py +++ b/openpilot/starpilot/ui/gain_feature.py @@ -47,7 +47,7 @@ class GainFeature: choices=("Selected controller",), available=allowed, capability=capability, dependencies=dependencies, default_value="Selected controller")) apply_note = ("First manual activation requires a driving-process restart." - if capability[0] in GM_VEHICLES else "Applies at restart. Learned steering adjustments pause while custom Kp is active.") + if capability[0] in GM_VEHICLES else "Applies at restart. Only the proportional gain is fixed.") rows = [FeatureRow("", "Manual steering response", "Higher values respond more strongly. " + apply_note)] rows.append(FeatureRow("torque:gain:mode", "Steering response source", "Custom" if choice.mode == "custom" else "Selected controller", raw, diff --git a/prebuilt.json b/prebuilt.json index 7914a6eca3..30f19a8c46 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "90767f419df836f5618a4859f800650b449bd325dbfe101845d84d61199b2dca", "schema_version": 1} +{"protected_inventory_sha256": "eefeb7e83aa507e9ecbf77674e0d31c773291f4ce49f7872cba4a1da8cf168dc", "schema_version": 1}