mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-02 06:13:40 +08:00
Expose calibrated steering controller choices in developer parameters
This commit is contained in:
@@ -93,6 +93,39 @@ class ControllerSelection:
|
||||
mode: ControllerMode
|
||||
policy: str | None
|
||||
source: str
|
||||
force_torque: bool = False
|
||||
|
||||
|
||||
def torque_choice_cp(cp):
|
||||
"""Preview only calibrated torque-actuated cars; never change the caller's CP."""
|
||||
if generic_torque_supported(cp):
|
||||
return cp
|
||||
try:
|
||||
platform = PLATFORMS.get(str(cp.carFingerprint))
|
||||
unsafe = (structs.CarParams.SafetyModel.noOutput, structs.CarParams.SafetyModel.silent,
|
||||
structs.CarParams.SafetyModel.allOutput)
|
||||
if (platform is None or platform.__class__.__module__.split('.')[-2] != str(cp.brand) or
|
||||
cp.notCar or cp.passive or cp.dashcamOnly or
|
||||
cp.steerControlType != structs.CarParams.SteerControlType.torque or cp.lateralTuning.which() != 'pid' or
|
||||
not cp.safetyConfigs or any(config.safetyModel in unsafe for config in cp.safetyConfigs)):
|
||||
return None
|
||||
from opendbc.car.interfaces import CarInterfaceBase
|
||||
prepared = cp.as_reader().as_builder()
|
||||
CarInterfaceBase.configure_torque_tune(prepared.carFingerprint, prepared.lateralTuning)
|
||||
return prepared if generic_torque_supported(prepared) else None
|
||||
except (AttributeError, TypeError, ValueError, OverflowError, KeyError, NotImplementedError, OSError):
|
||||
return None
|
||||
|
||||
|
||||
def prepare_controller(cp, raw):
|
||||
"""Apply an explicit saved type before the interface and published CP exist."""
|
||||
selected = selection_from_bytes(cp, raw)
|
||||
if selected.source != 'invalid' and selected.force_torque and cp.lateralTuning.which() == 'pid':
|
||||
prepared = torque_choice_cp(cp)
|
||||
if prepared is not None:
|
||||
cp.lateralTuning.init('torque')
|
||||
cp.lateralTuning.torque = prepared.lateralTuning.torque.to_dict()
|
||||
return cp
|
||||
|
||||
|
||||
def policy_for(CP) -> str | None:
|
||||
@@ -198,21 +231,27 @@ def parse_document(raw: bytes) -> dict:
|
||||
if not isinstance(vehicles, dict) or len(vehicles) > len(KNOWN_POLICIES):
|
||||
raise ValueError('Invalid controller selection vehicles')
|
||||
for fingerprint, choice in vehicles.items():
|
||||
if (fingerprint not in KNOWN_POLICIES or not isinstance(choice, dict) or set(choice) != {'brand', 'mode'} or
|
||||
if (fingerprint not in KNOWN_POLICIES or not isinstance(choice, dict) or set(choice) not in ({'brand', 'mode'}, {'brand', 'mode', 'forceTorque'}) or
|
||||
('forceTorque' in choice and type(choice['forceTorque']) is not bool) or
|
||||
choice['brand'] != KNOWN_POLICIES[fingerprint] or type(choice['mode']) is not str or
|
||||
choice['mode'] not in (ControllerMode.STANDARD, ControllerMode.STARPILOT)):
|
||||
raise ValueError('Invalid controller selection choice')
|
||||
return document
|
||||
|
||||
|
||||
def replace_mode(raw: bytes | None, CP, mode: ControllerMode) -> bytes:
|
||||
def replace_mode(raw: bytes | None, CP, mode: ControllerMode, *, force_torque: bool = False) -> bytes:
|
||||
"""Change only one exact platform's saved choice, preserving other entries."""
|
||||
if policy_for(CP) is None:
|
||||
raise ValueError('No exact torque policy for CarParams')
|
||||
choice_cp = torque_choice_cp(CP)
|
||||
if type(force_torque) is not bool or choice_cp is None or policy_for(choice_cp) is None:
|
||||
raise ValueError('No calibrated torque controller for CarParams')
|
||||
mode = ControllerMode(mode)
|
||||
if CP.lateralTuning.which() == 'pid' and mode == ControllerMode.STARPILOT and not force_torque:
|
||||
raise ValueError('PID cars require an explicit torque controller choice')
|
||||
document = {'version': DOCUMENT_VERSION, 'vehicles': {}} if raw is None else parse_document(raw)
|
||||
vehicles = dict(document['vehicles'])
|
||||
vehicles[str(CP.carFingerprint)] = {'brand': str(CP.brand), 'mode': mode.value}
|
||||
if force_torque:
|
||||
vehicles[str(CP.carFingerprint)]['forceTorque'] = True
|
||||
encoded = json.dumps({'version': DOCUMENT_VERSION, 'vehicles': vehicles},
|
||||
sort_keys=True, separators=(',', ':'), allow_nan=False).encode()
|
||||
if len(encoded) > MAX_DOCUMENT_BYTES:
|
||||
@@ -222,20 +261,25 @@ def replace_mode(raw: bytes | None, CP, mode: ControllerMode) -> bytes:
|
||||
|
||||
def selection_from_bytes(CP, raw: bytes | None) -> ControllerSelection:
|
||||
default = default_selection(CP)
|
||||
if raw is None or default.policy is None:
|
||||
if raw is None:
|
||||
return default
|
||||
try:
|
||||
choice = parse_document(raw)['vehicles'].get(str(CP.carFingerprint))
|
||||
if choice is None or choice['brand'] != str(CP.brand):
|
||||
return default
|
||||
return ControllerSelection(ControllerMode(choice['mode']), default.policy, 'saved')
|
||||
force_torque = choice.get('forceTorque', False)
|
||||
choice_cp = torque_choice_cp(CP) if force_torque else CP
|
||||
policy = policy_for(choice_cp) if choice_cp is not None else None
|
||||
if policy is None and not (not force_torque and choice['mode'] == ControllerMode.STANDARD and torque_choice_cp(CP) is not None):
|
||||
return ControllerSelection(default.mode, default.policy, 'invalid')
|
||||
return ControllerSelection(ControllerMode(choice['mode']), policy, 'saved', force_torque)
|
||||
except (UnicodeError, ValueError, TypeError, OverflowError):
|
||||
return ControllerSelection(default.mode, default.policy, 'invalid')
|
||||
|
||||
|
||||
def read_selection(params, CP) -> ControllerSelection:
|
||||
"""Read once at controls startup; a later settings write cannot change this controller."""
|
||||
if policy_for(CP) is None:
|
||||
if torque_choice_cp(CP) is None:
|
||||
return default_selection(CP)
|
||||
try:
|
||||
with Path(params.get_param_path(DOCUMENT_KEY)).open('rb') as source:
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
"""Explicit controller choices reach startup without changing vehicle authority."""
|
||||
import json
|
||||
from dataclasses import replace
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from opendbc.car import DT_CTRL
|
||||
from opendbc.car.car_helpers import interfaces
|
||||
from openpilot.common.params import Params
|
||||
from openpilot.selfdrive.controls.lib.lateral_controller_factory import create_lateral_controller
|
||||
from openpilot.starpilot.lateral.controller_selection import (
|
||||
DOCUMENT_KEY, ControllerMode, parse_document, prepare_controller, replace_mode,
|
||||
selection_from_bytes, torque_choice_cp,
|
||||
)
|
||||
from openpilot.starpilot.ui.feature_settings_owner import FeatureSettingsOwner
|
||||
from openpilot.starpilot.ui.feature_settings_state import FeatureSettingsRequest
|
||||
from openpilot.starpilot.vehicle_preferences import VehicleStartupPreferences
|
||||
|
||||
PID_CARS = ('CHRYSLER_PACIFICA_2018_HYBRID', 'CHRYSLER_PACIFICA_2019_HYBRID',
|
||||
'HONDA_CIVIC', 'VOLKSWAGEN_GOLF_MK7')
|
||||
|
||||
|
||||
def factory(identity):
|
||||
return interfaces[identity].get_non_essential_params(identity)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('identity', PID_CARS)
|
||||
@pytest.mark.parametrize('mode', list(ControllerMode))
|
||||
def test_explicit_choice_selects_real_controller_and_preserves_authority(identity, mode):
|
||||
cp = factory(identity)
|
||||
assert cp.lateralTuning.which() == 'pid'
|
||||
baseline = cp.to_dict()
|
||||
assert torque_choice_cp(cp) is not None
|
||||
assert cp.to_dict() == baseline
|
||||
assert prepare_controller(cp, None).to_dict() == baseline
|
||||
raw = replace_mode(None, cp, mode, force_torque=True)
|
||||
prepared = VehicleStartupPreferences(controller_selection=raw).prepare(cp)
|
||||
actual = prepared.to_dict()
|
||||
actual.pop('lateralTuning')
|
||||
expected = baseline.copy()
|
||||
expected.pop('lateralTuning')
|
||||
assert actual == expected
|
||||
assert prepared.lateralTuning.which() == 'torque'
|
||||
selection = selection_from_bytes(prepared, raw)
|
||||
ci = interfaces[identity](prepared)
|
||||
controller = create_lateral_controller(prepared.as_reader(), ci, DT_CTRL, mode=selection.mode)
|
||||
assert type(controller).__name__ == 'LatControlTorque'
|
||||
assert (controller.starpilot_extension is not None) == (mode == ControllerMode.STARPILOT)
|
||||
assert controller.torque_params.to_dict() == prepared.lateralTuning.torque.to_dict()
|
||||
restored_raw = replace_mode(raw, prepared, ControllerMode.STANDARD)
|
||||
stock = prepare_controller(factory(identity), restored_raw)
|
||||
assert stock.to_dict() == baseline
|
||||
stock_controller = create_lateral_controller(stock.as_reader(), interfaces[identity](stock), DT_CTRL, mode=ControllerMode.STANDARD)
|
||||
assert type(stock_controller).__name__ == 'LatControlPID'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('identity', PID_CARS)
|
||||
def test_developer_choice_saved_and_startup_snapshot_is_frozen(tmp_path, identity):
|
||||
cp = factory(identity)
|
||||
params = Params(str(tmp_path))
|
||||
owner = FeatureSettingsOwner(params, lambda _: True, vehicle_fingerprint=lambda: identity, vehicle_params=lambda: cp)
|
||||
state = owner.snapshot('torque/developer', parked=True, system_long=False, lateral_context=True, metric=False)
|
||||
current = next(r for r in state.rows if r.key == DOCUMENT_KEY)
|
||||
assert current.available and current.value == 'Stock Controller'
|
||||
assert current.choices == ('Stock Controller', 'Torque Controller', 'StarPilot Controller')
|
||||
frozen = VehicleStartupPreferences.read(params, enabled=True)
|
||||
request = FeatureSettingsRequest(current.key, current.source, 'Torque Controller', vehicle_fingerprint=identity,
|
||||
capability=current.capability, dependencies=current.dependencies)
|
||||
assert owner.apply(request)
|
||||
assert not owner.apply(request)
|
||||
assert frozen.prepare(factory(identity)).lateralTuning.which() == 'pid'
|
||||
saved = VehicleStartupPreferences.read(params, enabled=True)
|
||||
params.remove(DOCUMENT_KEY)
|
||||
assert saved.prepare(factory(identity)).lateralTuning.which() == 'torque'
|
||||
assert VehicleStartupPreferences.read(params, enabled=False).prepare(factory(identity)).lateralTuning.which() == 'pid'
|
||||
assert cp.lateralTuning.which() == 'pid'
|
||||
assert not owner.apply(replace(request, value='Invented Controller'))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('field,value', [('steerControlType', 'angle'), ('steerControlType', 'curvature'),
|
||||
('brand', 'toyota'), ('notCar', True), ('passive', True), ('dashcamOnly', True), ('carFingerprint', 'UNKNOWN')])
|
||||
def test_forced_choice_refuses_unsupported_configuration(field, value):
|
||||
cp = factory(PID_CARS[0])
|
||||
raw = replace_mode(None, cp, ControllerMode.STARPILOT, force_torque=True)
|
||||
setattr(cp, field, value)
|
||||
before = cp.to_dict()
|
||||
assert torque_choice_cp(cp) is None
|
||||
assert prepare_controller(cp, raw).to_dict() == before
|
||||
with pytest.raises(ValueError):
|
||||
replace_mode(None, cp, ControllerMode.STANDARD, force_torque=True)
|
||||
|
||||
|
||||
def test_missing_calibration_unsafe_profile_and_malformed_choice_do_not_convert():
|
||||
cp = factory(PID_CARS[0])
|
||||
original = cp.to_dict()
|
||||
raw = replace_mode(None, cp, ControllerMode.STARPILOT, force_torque=True)
|
||||
with patch('opendbc.car.interfaces.CarInterfaceBase.configure_torque_tune', side_effect=KeyError('missing')):
|
||||
assert torque_choice_cp(cp) is None
|
||||
assert prepare_controller(cp, raw).to_dict() == original
|
||||
cp.safetyConfigs[0].safetyModel = 'noOutput'
|
||||
assert torque_choice_cp(cp) is None
|
||||
cp = factory(PID_CARS[0])
|
||||
for bad in (b'{}', b'x' * 4097, raw.replace(b'true', b'1'), raw.replace(b'true', b'"true"')):
|
||||
assert selection_from_bytes(cp, bad).source == 'invalid'
|
||||
assert prepare_controller(cp, bad).to_dict() == original
|
||||
document = json.loads(raw)
|
||||
del document['vehicles'][PID_CARS[0]]['forceTorque']
|
||||
legacy = json.dumps(document).encode()
|
||||
assert prepare_controller(cp, legacy).to_dict() == original
|
||||
assert prepare_controller(factory(PID_CARS[1]), raw).lateralTuning.which() == 'pid'
|
||||
assert parse_document(raw)['vehicles'][PID_CARS[0]]['forceTorque'] is True
|
||||
|
||||
|
||||
@pytest.mark.parametrize('identity', PID_CARS[:2])
|
||||
@pytest.mark.parametrize('mode', list(ControllerMode))
|
||||
def test_pacifica_choice_reaches_actual_controls(identity, mode):
|
||||
import os
|
||||
from openpilot.common.prefix import OpenpilotPrefix
|
||||
from openpilot.selfdrive.controls.controlsd import Controls
|
||||
with OpenpilotPrefix(), patch.dict(os.environ, {'SIMULATION': '1', 'REPLAY': '1'}):
|
||||
params = Params()
|
||||
cp = factory(identity)
|
||||
raw = replace_mode(None, cp, mode, force_torque=True)
|
||||
params.put(DOCUMENT_KEY, json.loads(raw), block=True)
|
||||
preferences = VehicleStartupPreferences.read(params, enabled=True)
|
||||
preferences.prepare(cp)
|
||||
ci = interfaces[identity](cp)
|
||||
preferences.finalize(cp)
|
||||
preferences.configure_controller(ci)
|
||||
params.put('CarParams', cp.to_bytes(), block=True)
|
||||
controls = Controls()
|
||||
assert type(controls.LaC).__name__ == 'LatControlTorque'
|
||||
assert (controls.LaC.starpilot_extension is not None) == (mode == ControllerMode.STARPILOT)
|
||||
assert controls.CP.to_dict()['safetyConfigs'] == cp.to_dict()['safetyConfigs']
|
||||
|
||||
|
||||
def test_every_eligible_factory_pid_can_select_and_restore():
|
||||
supported = []
|
||||
for identity in interfaces:
|
||||
cp = factory(identity)
|
||||
if cp.lateralTuning.which() != 'pid' or torque_choice_cp(cp) is None:
|
||||
continue
|
||||
before = cp.to_dict()
|
||||
raw = replace_mode(None, cp, ControllerMode.STANDARD, force_torque=True)
|
||||
prepare_controller(cp, raw)
|
||||
assert cp.lateralTuning.which() == 'torque', identity
|
||||
original = factory(identity)
|
||||
prepare_controller(original, replace_mode(raw, cp, ControllerMode.STANDARD))
|
||||
assert original.to_dict() == before, identity
|
||||
supported.append(identity)
|
||||
assert set(PID_CARS).issubset(supported)
|
||||
@@ -7,7 +7,7 @@ import math
|
||||
import json
|
||||
|
||||
from openpilot.starpilot.lateral.controller_selection import (
|
||||
DOCUMENT_KEY, LEARNING_OFF_KEY, MAX_DOCUMENT_BYTES, ControllerMode, policy_for, replace_mode, selection_from_bytes,
|
||||
DOCUMENT_KEY, LEARNING_OFF_KEY, MAX_DOCUMENT_BYTES, ControllerMode, policy_for, replace_mode, selection_from_bytes, torque_choice_cp,
|
||||
)
|
||||
from openpilot.starpilot.lateral.learning_preferences import (
|
||||
KEY as LEARNING_PREFERENCES_KEY, MAX_BYTES as LEARNING_PREFERENCES_LIMIT, read_preference, replace_preference,
|
||||
@@ -21,7 +21,9 @@ from openpilot.starpilot.ui.feature_settings_state import FeatureRow, FeatureSet
|
||||
|
||||
|
||||
CHOICES = ('Stock Controller', 'StarPilot Controller')
|
||||
TORQUE_CHOICE = 'Torque Controller'
|
||||
MODES = dict(zip(CHOICES, (ControllerMode.STANDARD, ControllerMode.STARPILOT), strict=True))
|
||||
MODES[TORQUE_CHOICE] = ControllerMode.STANDARD
|
||||
TUNING_GUIDANCE = ("StarPilot's torque controller can provide higher low-speed steering accuracy, but may require additional tuning. " +
|
||||
"Join the StarPilot Discord and open a tuning request: https://firestar.link/discord")
|
||||
SETUP_ACTION = 'torque_prepare_firestar'
|
||||
@@ -61,16 +63,18 @@ class ControllerFeature:
|
||||
if CP is None or CP.notCar:
|
||||
return None
|
||||
try:
|
||||
policy = policy_for(CP)
|
||||
prepared = torque_choice_cp(CP)
|
||||
policy = policy_for(prepared) if prepared is not None else None
|
||||
if policy is None:
|
||||
return None
|
||||
tune = CP.lateralTuning.torque
|
||||
tune = prepared.lateralTuning.torque
|
||||
firmware = tuple((str(fw.ecu), bytes(fw.fwVersion)) for fw in CP.carFw)
|
||||
return (str(CP.brand), str(CP.carFingerprint), policy, str(CP.steerControlType),
|
||||
str(CP.lateralTuning.which()), bool(CP.passive), bool(CP.dashcamOnly), bool(CP.notCar),
|
||||
int(CP.flags), int(CP.alternativeExperience), float(tune.latAccelFactor),
|
||||
float(tune.latAccelOffset), float(tune.friction), float(tune.steeringAngleDeadzoneDeg),
|
||||
float(CP.steerActuatorDelay), float(CP.steerLimitTimer), str(CP.carVin), firmware)
|
||||
float(CP.steerActuatorDelay), float(CP.steerLimitTimer), str(CP.carVin), firmware,
|
||||
json.dumps(CP.lateralTuning.to_dict(), sort_keys=True, separators=(',', ':')))
|
||||
except (AttributeError, TypeError, ValueError, OverflowError):
|
||||
return None
|
||||
|
||||
@@ -117,7 +121,9 @@ class ControllerFeature:
|
||||
learning = ({LEARNING_PREFERENCES_KEY: replace_preference(sources[LEARNING_PREFERENCES_KEY], CP, False)}
|
||||
if LEARNING_PREFERENCES_KEY in sources else {})
|
||||
return {**SETUP_DEFAULTS, **learning, LANE_CHANGE_KEY: json.dumps(to_value(lane), sort_keys=True, separators=(',', ':')).encode(),
|
||||
DOCUMENT_KEY: replace_mode(sources[DOCUMENT_KEY], CP, ControllerMode.STARPILOT)}
|
||||
DOCUMENT_KEY: replace_mode(sources[DOCUMENT_KEY], CP, ControllerMode.STARPILOT,
|
||||
force_torque=steering_controller(CP) == 'pid' or
|
||||
selection_from_bytes(CP, sources[DOCUMENT_KEY]).force_torque)}
|
||||
|
||||
def setup_row(self) -> FeatureRow | None:
|
||||
CP = self.vehicle_params()
|
||||
@@ -176,15 +182,16 @@ class ControllerFeature:
|
||||
raw, readable = read_saved(self.params, DOCUMENT_KEY, MAX_DOCUMENT_BYTES)
|
||||
selected = selection_from_bytes(CP, raw) if readable else None
|
||||
valid = readable and selected is not None and selected.source != 'invalid'
|
||||
value = CHOICES[0] if valid and selected.mode == ControllerMode.STANDARD else \
|
||||
CHOICES[1] if valid else 'Invalid saved controller choice'
|
||||
value = (TORQUE_CHOICE if selected.force_torque and selected.mode == ControllerMode.STANDARD else
|
||||
CHOICES[0] if selected.mode == ControllerMode.STANDARD else CHOICES[1]) if valid else 'Invalid saved controller choice'
|
||||
choices = (CHOICES[0], TORQUE_CHOICE, CHOICES[1]) if steering_controller(CP) == 'pid' or valid and selected.force_torque else CHOICES
|
||||
learning, learning_readable = read_saved(self.params, LEARNING_OFF_KEY, 1)
|
||||
preference = read_preference(self.params, CP, legacy_snapshot=(learning, learning_readable))
|
||||
learning_valid = learning_readable and preference.valid
|
||||
allowed = valid and learning_valid and self.authority('preferences')
|
||||
reason = ('Choose the steering controller for your next drive. ' + TUNING_GUIDANCE if valid and learning_valid else
|
||||
'Saved steering preferences are unreadable or invalid; no change was made.')
|
||||
return FeatureRow(DOCUMENT_KEY, 'Steering Controller', value, raw, CHOICES if valid else (),
|
||||
return FeatureRow(DOCUMENT_KEY, 'Steering Controller', value, raw, choices if valid else (),
|
||||
available=allowed, reason=reason, capability=capability,
|
||||
dependencies=((LEARNING_OFF_KEY, learning), (LEARNING_PREFERENCES_KEY, preference.raw)),
|
||||
default_value=CHOICES[0] if selection_from_bytes(CP, None).mode == ControllerMode.STANDARD else CHOICES[1])
|
||||
@@ -238,7 +245,8 @@ class ControllerFeature:
|
||||
not request.vehicle_fingerprint or request.vehicle_fingerprint != self.vehicle_fingerprint()):
|
||||
return False
|
||||
CP = self.vehicle_params()
|
||||
if CP is None or request.capability != self.capability(CP):
|
||||
row = self.row()
|
||||
if CP is None or row is None or request.value not in row.choices or request.capability != self.capability(CP):
|
||||
return False
|
||||
raw, readable = read_saved(self.params, DOCUMENT_KEY, MAX_DOCUMENT_BYTES)
|
||||
learning, learning_readable = read_saved(self.params, LEARNING_OFF_KEY, 1)
|
||||
@@ -251,7 +259,9 @@ class ControllerFeature:
|
||||
selected = selection_from_bytes(CP, raw)
|
||||
if selected.source == 'invalid':
|
||||
return False
|
||||
encoded = replace_mode(raw, CP, MODES[request.value])
|
||||
force_torque = request.value == TORQUE_CHOICE or request.value == CHOICES[1] and (
|
||||
steering_controller(CP) == 'pid' or selected.force_torque)
|
||||
encoded = replace_mode(raw, CP, MODES[request.value], force_torque=force_torque)
|
||||
except (UnicodeError, ValueError, TypeError, OverflowError):
|
||||
return False
|
||||
|
||||
|
||||
@@ -1128,6 +1128,9 @@ class FeatureSettingsOwner:
|
||||
rows.extend(longitudinal_developer_rows(self))
|
||||
elif page == FeaturePage.DEVELOPER_LATERAL:
|
||||
title = 'Developer Parameters'
|
||||
controller_row = self.controller.row()
|
||||
if controller_row is not None:
|
||||
rows.append(controller_row)
|
||||
capability = self._capability("torque") or self._capability("gain")
|
||||
allowed = configurable and self.authority("torque") and capability is not None
|
||||
_, numeric_rows = self.torque.rows(capability, allowed, repair_allowed=parked and allowed)
|
||||
|
||||
@@ -85,11 +85,12 @@ class TestControllerFeature(unittest.TestCase):
|
||||
self.assertIsNone(self.params.get('ForceAutoTuneOff'))
|
||||
self.assertIsNone(self.params.get(DOCUMENT_KEY))
|
||||
|
||||
def test_stock_pid_keeps_learning_preference_without_exposing_a_toggle(self):
|
||||
def test_stock_pid_exposes_controller_choice_without_mutating_cp(self):
|
||||
self.cp = interfaces[HONDA.HONDA_CIVIC].get_non_essential_params(HONDA.HONDA_CIVIC)
|
||||
self.assertEqual(self.cp.lateralTuning.which(), 'pid')
|
||||
original = self.cp.as_reader().as_builder().to_bytes()
|
||||
self.assertIsNone(self.row()) # No torque-only controller/manual editor.
|
||||
self.assertEqual(self.require_row().choices, ('Stock Controller', 'Torque Controller', 'StarPilot Controller'))
|
||||
self.assertEqual(self.require_row().value, 'Stock Controller')
|
||||
self.assertIsNone(self.row('ForceAutoTuneOff'))
|
||||
self.assertTrue(read_preference(self.params, self.cp).enabled)
|
||||
self.assertIsNone(self.params.get('ForceAutoTuneOff'))
|
||||
|
||||
@@ -19,6 +19,7 @@ def bolt_disable_supported(cp) -> bool:
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class VehicleStartupPreferences:
|
||||
controller_selection: bytes | None = field(default=None, kw_only=True)
|
||||
toyota_auto_hold: bool = False
|
||||
toyota_sng: bool = field(default=False, kw_only=True)
|
||||
jeep_brake_hold: bool = field(default=False, kw_only=True)
|
||||
@@ -58,6 +59,10 @@ class VehicleStartupPreferences:
|
||||
from openpilot.starpilot.car.tesla.radar_settings import read_radar_settings
|
||||
from openpilot.starpilot.car.tesla.pedal_preferences import read_pedal_settings
|
||||
from openpilot.starpilot.car.ford.bluepilot import startup_params as ford_bluepilot
|
||||
from openpilot.starpilot.lateral.controller_selection import DOCUMENT_KEY, MAX_DOCUMENT_BYTES
|
||||
controller_selection, readable_selection = read_saved(params, DOCUMENT_KEY, MAX_DOCUMENT_BYTES)
|
||||
if not enabled or not readable_selection:
|
||||
controller_selection = None
|
||||
smoothing = read_snapshot(params, enabled=enabled)
|
||||
radar = read_radar_settings(params)
|
||||
pedal = read_pedal_settings(params)
|
||||
@@ -87,7 +92,7 @@ class VehicleStartupPreferences:
|
||||
volt_one_pedal = bool(enabled and not disable_bolt and read_saved(params, "VoltOnePedalMode", 8) == (b"1", True) and
|
||||
readable and safe in (None, b"0"))
|
||||
except (OSError, TypeError, ValueError):
|
||||
return cls(vw_stock_long=vw_stock_long,
|
||||
return cls(controller_selection=controller_selection, vw_stock_long=vw_stock_long,
|
||||
subaru_smoothing=smoothing, disable_bolt_long=disable_bolt, honda_bosch_a_radar=honda_radar, tesla_preap_stock=preap_stock,
|
||||
tesla_preap_radar=radar, tesla_preap_pedal=pedal,
|
||||
gm_camera_pedal=False, toyota_filter=False)
|
||||
@@ -107,7 +112,7 @@ class VehicleStartupPreferences:
|
||||
cooperative = bool(enabled and readable and safe in (None, b"0") and
|
||||
read_saved(params, "TeslaCoopSteering", 8) == (b"1", True))
|
||||
screen_brake = read_saved(params, 'TeslaAOLDisengageOnBrake', 8) == (b'1', True)
|
||||
return cls(vw_stock_long=vw_stock_long,
|
||||
return cls(controller_selection=controller_selection, vw_stock_long=vw_stock_long,
|
||||
subaru_smoothing=smoothing, subaru_avh_startup=bool(enabled and readable and safe in (None, b"0") and
|
||||
read_saved(params, "IsReleaseBranch", 8) in ((None, True), (b"0", True)) and
|
||||
read_saved(params, "SubaruAvhStartup", 8) == (b"1", True)),
|
||||
@@ -233,7 +238,8 @@ class VehicleStartupPreferences:
|
||||
configure_radar(cp)
|
||||
from opendbc.bluepilot_lateral.hosts.starpilot.safety_param import init_ford_safety_param_starpilot
|
||||
init_ford_safety_param_starpilot(cp, dict(self.ford_bluepilot))
|
||||
return cp
|
||||
from openpilot.starpilot.lateral.controller_selection import prepare_controller
|
||||
return prepare_controller(cp, self.controller_selection)
|
||||
|
||||
def finalize(self, cp) -> None:
|
||||
from opendbc.car.volkswagen.meb_modes import prepare_stock as prepare_meb_stock
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "328211c2a53e3e3eb99d2bc768c11ada5c6bb384f8e99f5c8847bd80106568a0", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "32ee0c0c81775e54c7921d72605ef4452987c670af1356adccbd79ea4c0e37ca", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user