Restore familiar torque arc colors and label

This commit is contained in:
Dom
2026-11-04 17:25:53 -06:00
parent c8296b3bd8
commit e30016c008
5 changed files with 29 additions and 17 deletions
@@ -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()}
+1 -2
View File
@@ -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()
+2 -2
View File
@@ -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 = {
@@ -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
@@ -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))