From e30016c008f84c0be9b81e4ac3ff17730beb5086 Mon Sep 17 00:00:00 2001 From: Dom <168790843+firestar5683@users.noreply.github.com> Date: Wed, 4 Nov 2026 17:25:53 -0600 Subject: [PATCH] Restore familiar torque arc colors and label --- .../starpilot/ui/onroad_customization.py | 2 +- openpilot/starpilot/ui/onroad_torque.py | 3 +- openpilot/starpilot/ui/onroad_torque_draw.py | 4 +-- .../ui/tests/test_onroad_customization.py | 5 +++ .../ui/tests/test_onroad_torque_draw.py | 32 ++++++++++++------- 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/openpilot/starpilot/ui/onroad_customization.py b/openpilot/starpilot/ui/onroad_customization.py index d1a7f66e98..8c39604fb7 100644 --- a/openpilot/starpilot/ui/onroad_customization.py +++ b/openpilot/starpilot/ui/onroad_customization.py @@ -135,7 +135,7 @@ for _profile, _data in PROFILES.items(): _bounds = _data["bounds"] _x, _y, _width, _height = maximum_footprint(_bounds["x"], _bounds["y"], _bounds["width"], _bounds["height"], _data["width"]) _data["widgets"]["torque_bar"] = { - **_widget("Steering demand", "torque_bar", _width, _height, _x, _y), "layer": "underlay", + **_widget("Torque bar", "torque_bar", _width, _height, _x, _y), "layer": "underlay", "note": "Torque command or lateral-acceleration demand. Full width reflects the configured display scale."} ACTIONLESS_WIDGETS = {profile: set(data["widgets"]) - {"speed_limit_actions"} for profile, data in PROFILES.items()} diff --git a/openpilot/starpilot/ui/onroad_torque.py b/openpilot/starpilot/ui/onroad_torque.py index 2bf261ca15..522d0ac74f 100644 --- a/openpilot/starpilot/ui/onroad_torque.py +++ b/openpilot/starpilot/ui/onroad_torque.py @@ -39,8 +39,7 @@ class TorqueBarWidget: if not enabled: return cap_radius = LARGE_CAP_RADIUS if screen_width == 2160 else CAP_RADIUS - self._painter.render(rect, torque, alpha, screen_width, cap_radius, widget_offset(state.customization, profile, 'torque_bar'), - demand_only=state.torque_is_demand) + self._painter.render(rect, torque, alpha, screen_width, cap_radius, widget_offset(state.customization, profile, 'torque_bar')) def close(self) -> None: self._painter.close() diff --git a/openpilot/starpilot/ui/onroad_torque_draw.py b/openpilot/starpilot/ui/onroad_torque_draw.py index 6c6fe6ecb4..8a27f45da3 100644 --- a/openpilot/starpilot/ui/onroad_torque_draw.py +++ b/openpilot/starpilot/ui/onroad_torque_draw.py @@ -82,7 +82,7 @@ class TorqueBarPainter: self._shader = shader def render(self, rect: rl.Rectangle, torque: float, alpha: float, screen_width: float, cap_radius: float, - offset: tuple[float, float] = (0, 0), *, demand_only: bool = False) -> None: + offset: tuple[float, float] = (0, 0)) -> None: if alpha <= 0: return self.prepare() @@ -101,7 +101,7 @@ class TorqueBarPainter: start, end = ((end_sine, -end_cosine), (0, -1)) if torque < 0 else ((0, -1), (end_sine, -end_cosine)) dot_y = rect.y + rect.height - torque_offset - thickness / 2 + offset[1] indicator_alpha = int(255 * 0.9 * alpha) / 255 - warmth = 0.0 if demand_only else max(0.0, min(1.0, (abs(torque) - 0.75) * 4)) + warmth = max(0.0, min(1.0, (abs(torque) - 0.75) * 4)) extent = (middle_radius + thickness / 2 - cap) * sine + cap reach = max(0.65 * extent, 0.0001) values = { diff --git a/openpilot/starpilot/ui/tests/test_onroad_customization.py b/openpilot/starpilot/ui/tests/test_onroad_customization.py index 64f69759d6..27473c8ca3 100644 --- a/openpilot/starpilot/ui/tests/test_onroad_customization.py +++ b/openpilot/starpilot/ui/tests/test_onroad_customization.py @@ -38,6 +38,11 @@ def road(document=None, **changes): customization=document or default_document(), **changes) +def test_torque_bar_keeps_its_familiar_customization_label(): + for profile in customization_metadata()['profiles'].values(): + assert profile['widgets']['torque_bar']['label'] == 'Torque bar' + + def test_defaults_and_metadata_are_independent_and_valid(): document = default_document() assert validate_document(document) == document diff --git a/openpilot/starpilot/ui/tests/test_onroad_torque_draw.py b/openpilot/starpilot/ui/tests/test_onroad_torque_draw.py index 31edff7c40..006240dfe0 100644 --- a/openpilot/starpilot/ui/tests/test_onroad_torque_draw.py +++ b/openpilot/starpilot/ui/tests/test_onroad_torque_draw.py @@ -1,6 +1,7 @@ import numpy as np from contextlib import contextmanager from types import SimpleNamespace as NS +from dataclasses import replace from unittest.mock import patch from openpilot.starpilot.ui.raylib import rl @@ -8,6 +9,8 @@ import pytest from openpilot.starpilot.ui import onroad_torque_draw from openpilot.starpilot.ui.onroad_torque_draw import TorqueBarPainter +from openpilot.starpilot.ui.onroad_torque import TorqueBarWidget +from openpilot.starpilot.ui.onroad_state import OnroadState, SpeedLimitObservation @contextmanager @@ -135,19 +138,24 @@ def test_shader_failure_never_paints_the_bounding_rectangle(default_shader_id): assert gpu.unloads == ([1] if default_shader_id == 0 else []) -@pytest.mark.parametrize('width,rect,cap', [ - (536, (0, 0, 476, 240), 7), (2160, (30, 30, 1800, 1020), 21), (1860, (30, 30, 1800, 1800), 7), +@pytest.mark.parametrize('width,rect', [ + (536, (0, 0, 476, 240)), (2160, (30, 30, 1800, 1020)), (1860, (30, 30, 1800, 1800)), ]) -@pytest.mark.parametrize('utilization', [-1, -.9, -.3, .3, .9, 1]) -def test_demand_has_direction_without_claiming_physical_torque_saturation(width, rect, cap, utilization): - with record_gpu() as gpu: - painter = TorqueBarPainter() - painter.render(rl.Rectangle(*rect), utilization, 1, width, cap, demand_only=True) - painter.render(rl.Rectangle(*rect), utilization, 1, width, cap) - demand, torque = gpu.frames - assert demand.uniforms['gradient'][1:] == pytest.approx((1, 0, 1)) +@pytest.mark.parametrize('utilization', [-1, -.875, -.75, -.3, .3, .75, .875, 1]) +def test_demand_preserves_original_colors_geometry_and_direction(width, rect, utilization): + state = OnroadState(True, True, 15.0, 80.0, SpeedLimitObservation(), lateral_active=True, torque_source_available=True, + torque_utilization=utilization, torque_is_demand=True) + frames = [] + for demand_only in (True, False): + widget = TorqueBarWidget() + with record_gpu() as gpu: + for _ in range(120): + widget.render(rl.Rectangle(*rect), replace(state, torque_is_demand=demand_only), width) + frames.append(gpu.frames[-1]) + demand, torque = frames + warmth = max(0.0, min(1.0, (abs(widget._torque_filter.x) - .75) * 4)) + assert demand.uniforms['gradient'][1:] == pytest.approx((1 - warmth * 140 / 255, warmth * 85 / 255, 1 - warmth)) + assert demand.uniforms == torque.uniforms assert demand.uniforms['indicatorNormals'][0 if utilization < 0 else 2] * utilization > 0 assert demand.uniforms['indicatorNormals'] == torque.uniforms['indicatorNormals'] assert demand.vertices == torque.vertices - if abs(utilization) > .75: - assert torque.uniforms['gradient'][1:] != pytest.approx((1, 0, 1))