From ddb90394935653ac5be2e0b75c248d5f8c3a6e57 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Tue, 28 Apr 2026 07:26:05 -0400 Subject: [PATCH] torque: show static override values in Dev UI & gate `useParams` on custom torque tune (#1821) torque: show static override values in Dev UI --- .../onroad/developer_ui/__init__.py | 3 ++- .../onroad/developer_ui/elements.py | 23 +++++++++---------- selfdrive/ui/sunnypilot/ui_state.py | 5 ++++ sunnypilot/selfdrive/locationd/torqued_ext.py | 6 ++--- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/selfdrive/ui/sunnypilot/onroad/developer_ui/__init__.py b/selfdrive/ui/sunnypilot/onroad/developer_ui/__init__.py index 8204253d32..889e1737ee 100644 --- a/selfdrive/ui/sunnypilot/onroad/developer_ui/__init__.py +++ b/selfdrive/ui/sunnypilot/onroad/developer_ui/__init__.py @@ -141,7 +141,8 @@ class DeveloperUiRenderer(Widget): # Add torque-specific elements if using torque control if sm['controlsState'].lateralControlState.which() == 'torqueState': - if sm.valid['liveTorqueParameters']: + override_active = ui_state.enforce_torque_control and ui_state.custom_torque_params and ui_state.torque_override_enabled + if sm.valid['liveTorqueParameters'] or override_active: elements.extend([ self.friction_elem.update(sm, ui_state.is_metric), self.lat_accel_factor_elem.update(sm, ui_state.is_metric), diff --git a/selfdrive/ui/sunnypilot/onroad/developer_ui/elements.py b/selfdrive/ui/sunnypilot/onroad/developer_ui/elements.py index 94e3af42eb..389692d30b 100644 --- a/selfdrive/ui/sunnypilot/onroad/developer_ui/elements.py +++ b/selfdrive/ui/sunnypilot/onroad/developer_ui/elements.py @@ -8,8 +8,7 @@ import pyray as rl from dataclasses import dataclass from openpilot.common.constants import CV - - +from openpilot.selfdrive.ui.ui_state import ui_state from openpilot.system.ui.lib.text_measure import measure_text_cached @@ -248,12 +247,12 @@ class FrictionCoefficientElement: self.unit = "" def update(self, sm, is_metric: bool) -> UiElement: - ltp = sm['liveTorqueParameters'] - friction_coef = ltp.frictionCoefficientFiltered - live_valid = ltp.liveValid + if ui_state.enforce_torque_control and ui_state.custom_torque_params and ui_state.torque_override_enabled: + return UiElement(f"{ui_state.torque_override_friction:.3f}", "FRIC.", self.unit, rl.WHITE) - value = f"{friction_coef:.3f}" - color = rl.Color(0, 255, 0, 255) if live_valid else rl.WHITE + ltp = sm['liveTorqueParameters'] + value = f"{ltp.frictionCoefficientFiltered:.3f}" + color = rl.Color(0, 255, 0, 255) if ltp.liveValid else rl.WHITE return UiElement(value, "FRIC.", self.unit, color) @@ -262,12 +261,12 @@ class LatAccelFactorElement: self.unit = "" def update(self, sm, is_metric: bool) -> UiElement: - ltp = sm['liveTorqueParameters'] - lat_accel_factor = ltp.latAccelFactorFiltered - live_valid = ltp.liveValid + if ui_state.enforce_torque_control and ui_state.custom_torque_params and ui_state.torque_override_enabled: + return UiElement(f"{ui_state.torque_override_lat_accel_factor:.3f}", "L.A.F.", self.unit, rl.WHITE) - value = f"{lat_accel_factor:.3f}" - color = rl.Color(0, 255, 0, 255) if live_valid else rl.WHITE + ltp = sm['liveTorqueParameters'] + value = f"{ltp.latAccelFactorFiltered:.3f}" + color = rl.Color(0, 255, 0, 255) if ltp.liveValid else rl.WHITE return UiElement(value, "L.A.F.", self.unit, color) diff --git a/selfdrive/ui/sunnypilot/ui_state.py b/selfdrive/ui/sunnypilot/ui_state.py index 2a48e9eeef..f4f87b6030 100644 --- a/selfdrive/ui/sunnypilot/ui_state.py +++ b/selfdrive/ui/sunnypilot/ui_state.py @@ -143,6 +143,11 @@ class UIStateSP: self.standstill_timer = self.params.get_bool("StandstillTimer") self.sunnylink_enabled = self.params.get_bool("SunnylinkEnabled") self.torque_bar = self.params.get_bool("TorqueBar") + self.enforce_torque_control = self.params.get_bool("EnforceTorqueControl") + self.custom_torque_params = self.params.get_bool("CustomTorqueParams") + self.torque_override_enabled = self.params.get_bool("TorqueParamsOverrideEnabled") + self.torque_override_lat_accel_factor = float(self.params.get("TorqueParamsOverrideLatAccelFactor", return_default=True)) + self.torque_override_friction = float(self.params.get("TorqueParamsOverrideFriction", return_default=True)) self.true_v_ego_ui = self.params.get_bool("TrueVEgoUI") self.turn_signals = self.params.get_bool("ShowTurnSignals") self.boot_offroad_mode = self.params.get("DeviceBootMode", return_default=True) diff --git a/sunnypilot/selfdrive/locationd/torqued_ext.py b/sunnypilot/selfdrive/locationd/torqued_ext.py index 58a23da00e..1e62b7666a 100644 --- a/sunnypilot/selfdrive/locationd/torqued_ext.py +++ b/sunnypilot/selfdrive/locationd/torqued_ext.py @@ -4,7 +4,6 @@ Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. This file is part of sunnypilot and is licensed under the MIT License. See the LICENSE.md file in the root directory for more details. """ - import numpy as np from cereal import car @@ -18,7 +17,6 @@ RELAXED_MIN_BUCKET_POINTS = np.array([1, 200, 300, 500, 500, 300, 200, 1]) ALLOWED_CARS = ['toyota', 'hyundai', 'rivian', 'honda'] - class TorqueEstimatorExt: def __init__(self, CP: car.CarParams): self.CP = CP @@ -28,6 +26,7 @@ class TorqueEstimatorExt: self.enforce_torque_control_toggle = self._params.get_bool("EnforceTorqueControl") # only during init self.use_params = self.CP.brand in ALLOWED_CARS and self.CP.lateralTuning.which() == 'torque' self.use_live_torque_params = self._params.get_bool("LiveTorqueParamsToggle") + self.custom_torque_params = self._params.get_bool("CustomTorqueParams") self.torque_override_enabled = self._params.get_bool("TorqueParamsOverrideEnabled") self.min_bucket_points = RELAXED_MIN_BUCKET_POINTS self.factor_sanity = 0.0 @@ -51,13 +50,14 @@ class TorqueEstimatorExt: def _update_params(self): if self.frame % int(PARAMS_UPDATE_PERIOD / DT_MDL) == 0: self.use_live_torque_params = self._params.get_bool("LiveTorqueParamsToggle") + self.custom_torque_params = self._params.get_bool("CustomTorqueParams") self.torque_override_enabled = self._params.get_bool("TorqueParamsOverrideEnabled") def update_use_params(self): self._update_params() if self.enforce_torque_control_toggle: - if self.torque_override_enabled: + if self.custom_torque_params and self.torque_override_enabled: self.use_params = False else: self.use_params = self.use_live_torque_params