This commit is contained in:
firestar5683
2026-05-03 11:46:15 -05:00
parent 997c1be7b6
commit b8a84d6196
6 changed files with 65 additions and 9 deletions
+22 -1
View File
@@ -16,6 +16,8 @@ QT_STEER_KP_PLACEHOLDER = 1.0
LAUNCH_PARAM_MIGRATION_MARKER = ".starpilot_launch_param_migrations_v2"
BRANCH_DEFAULTS_MIGRATION_MARKER = ".starpilot_branch_defaults_migrations_v1"
ACCELERATION_PROFILE_MIGRATION_MARKER = ".starpilot_acceleration_profile_default_v1"
STANDARD_ACCELERATION_PROFILE = 0
BRANCH_BOOL_DEFAULTS = {
"ConditionalExperimental": True,
@@ -53,8 +55,10 @@ BRANCH_FLOAT_DEFAULTS = {
class ParamsLike(Protocol):
def get_param_path(self, key: str = "") -> str: ...
def get_bool(self, key: str) -> bool: ...
def get_int(self, key: str) -> int: ...
def get_float(self, key: str) -> float: ...
def put_bool(self, key: str, value: bool) -> None: ...
def put_int(self, key: str, value: int) -> None: ...
def put_float(self, key: str, value: float) -> None: ...
@@ -70,6 +74,10 @@ def _branch_defaults_marker_path(params: ParamsLike) -> Path:
return Path(params.get_param_path()) / BRANCH_DEFAULTS_MIGRATION_MARKER
def _acceleration_profile_marker_path(params: ParamsLike) -> Path:
return Path(params.get_param_path()) / ACCELERATION_PROFILE_MIGRATION_MARKER
def _apply_legacy_launch_param_migrations(params: ParamsLike, marker: Path) -> None:
if marker.exists():
return
@@ -112,12 +120,25 @@ def _apply_branch_default_migration(params: ParamsLike, marker: Path) -> None:
marker.touch()
def _apply_acceleration_profile_default_migration(params: ParamsLike, marker: Path) -> None:
if marker.exists():
return
marker.parent.mkdir(parents=True, exist_ok=True)
params.put_int("AccelerationProfile", STANDARD_ACCELERATION_PROFILE)
marker.touch()
def apply_launch_param_migrations(params: ParamsLike, marker_path: Path | None = None,
branch_defaults_marker_path: Path | None = None) -> None:
branch_defaults_marker_path: Path | None = None,
acceleration_profile_marker_path: Path | None = None) -> None:
_apply_legacy_launch_param_migrations(params, marker_path or _default_marker_path(params))
# Keep branch-default rollout on its own marker so older installs that already
# have the legacy marker still receive this one-time param reset.
_apply_branch_default_migration(params, branch_defaults_marker_path or _branch_defaults_marker_path(params))
_apply_acceleration_profile_default_migration(
params, acceleration_profile_marker_path or _acceleration_profile_marker_path(params)
)
def main() -> int:
@@ -1,9 +1,11 @@
from pathlib import Path
from openpilot.system.manager.launch_param_migrations import (
ACCELERATION_PROFILE_MIGRATION_MARKER,
BRANCH_DEFAULTS_MIGRATION_MARKER,
DEFAULT_STEER_KP,
LAUNCH_PARAM_MIGRATION_MARKER,
STANDARD_ACCELERATION_PROFILE,
apply_launch_param_migrations,
)
@@ -32,9 +34,16 @@ class FileBackedFakeParams:
value = self.get(key)
return float(value) if value is not None else 0.0
def get_int(self, key):
value = self.get(key)
return int(float(value)) if value is not None else 0
def put_bool(self, key, value):
Path(self.get_param_path(key)).write_text("1" if value else "0", encoding="utf-8")
def put_int(self, key, value):
Path(self.get_param_path(key)).write_text(str(int(value)), encoding="utf-8")
def put_float(self, key, value):
Path(self.get_param_path(key)).write_text(str(float(value)), encoding="utf-8")
@@ -141,3 +150,28 @@ def test_apply_launch_param_migrations_does_not_reapply_branch_defaults_after_ma
assert params.get_float("AggressiveFollowHigh") == 2.0
assert params.get_float("StandardJerkAcceleration") == 25.0
assert params.get_float("RelaxedFollow") == 2.0
def test_apply_launch_param_migrations_updates_acceleration_profile_for_existing_installs(tmp_path):
params = FileBackedFakeParams(tmp_path / "params")
params.put_int("AccelerationProfile", 2)
(tmp_path / "params" / LAUNCH_PARAM_MIGRATION_MARKER).touch()
(tmp_path / "params" / BRANCH_DEFAULTS_MIGRATION_MARKER).touch()
apply_launch_param_migrations(params)
assert params.get_int("AccelerationProfile") == STANDARD_ACCELERATION_PROFILE
assert (tmp_path / "params" / ACCELERATION_PROFILE_MIGRATION_MARKER).is_file()
def test_apply_launch_param_migrations_does_not_reapply_acceleration_profile_after_marker(tmp_path):
params = FileBackedFakeParams(tmp_path / "params")
acceleration_profile_marker = tmp_path / "params" / ACCELERATION_PROFILE_MIGRATION_MARKER
params.put_int("AccelerationProfile", 3)
acceleration_profile_marker.touch()
apply_launch_param_migrations(params)
assert params.get_int("AccelerationProfile") == 3