mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-12-02 05:23:43 +08:00
mici: steady status colors (#39336)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import numpy as np
|
||||
import raylib_nb as rl
|
||||
from openpilot.selfdrive.ui.ui_state import ui_state, UIStatus
|
||||
from openpilot.selfdrive.ui.mici.onroad.status import status_fade
|
||||
from openpilot.system.ui.widgets import Widget
|
||||
from openpilot.system.ui.lib.application import gui_app
|
||||
from openpilot.system.ui.lib.polygon import Gradient, draw_polygon
|
||||
@@ -57,25 +58,17 @@ class ConfidenceBall(Widget):
|
||||
dot_height = (1 - self._confidence_filter.x) * (self._rect.height - 2 * (status_dot_radius + margin)) + status_dot_radius + margin
|
||||
dot_height = self._rect.y + dot_height
|
||||
|
||||
# confidence zones
|
||||
if ui_state.status == UIStatus.ENGAGED:
|
||||
if self._confidence_filter.x > 0.5:
|
||||
top_dot_color = rl.Color(0, 255, 187, 255)
|
||||
bottom_dot_color = rl.Color(0, 255, 64, 255)
|
||||
elif self._confidence_filter.x > 0.2:
|
||||
top_dot_color = rl.Color(255, 200, 0, 255)
|
||||
bottom_dot_color = rl.Color(255, 115, 0, 255)
|
||||
else:
|
||||
top_dot_color = rl.Color(255, 0, 21, 255)
|
||||
bottom_dot_color = rl.Color(255, 0, 89, 255)
|
||||
|
||||
elif ui_state.status == UIStatus.OVERRIDE:
|
||||
top_dot_color = rl.Color(255, 255, 255, 255)
|
||||
bottom_dot_color = rl.Color(82, 82, 82, 255)
|
||||
|
||||
# confidence zones while engaged, top and bottom gradient colors
|
||||
if self._confidence_filter.x > 0.5:
|
||||
engaged = (rl.Color(0, 255, 187, 255), rl.Color(0, 255, 64, 255))
|
||||
elif self._confidence_filter.x > 0.2:
|
||||
engaged = (rl.Color(255, 200, 0, 255), rl.Color(255, 115, 0, 255))
|
||||
else:
|
||||
top_dot_color = rl.Color(102, 102, 102, 255)
|
||||
bottom_dot_color = rl.Color(26, 26, 26, 255)
|
||||
engaged = (rl.Color(255, 0, 21, 255), rl.Color(255, 0, 89, 255))
|
||||
override = (rl.Color(255, 255, 255, 255), rl.Color(82, 82, 82, 255))
|
||||
disengaged = (rl.Color(102, 102, 102, 255), rl.Color(26, 26, 26, 255))
|
||||
top_dot_color, bottom_dot_color = (status_fade.color({UIStatus.ENGAGED: e, UIStatus.OVERRIDE: o, UIStatus.DISENGAGED: d})
|
||||
for e, o, d in zip(engaged, override, disengaged, strict=True))
|
||||
|
||||
draw_circle_gradient(dot_x, dot_height, status_dot_radius,
|
||||
top_dot_color, bottom_dot_color, alpha)
|
||||
|
||||
@@ -4,6 +4,7 @@ import raylib_nb as rl
|
||||
from dataclasses import dataclass
|
||||
from openpilot.common.constants import CV
|
||||
from openpilot.selfdrive.ui.mici.onroad import DIMMED_ICON_ALPHA
|
||||
from openpilot.selfdrive.ui.mici.onroad.status import STATUS_FADE_RC, lerp_color, status_fade
|
||||
from openpilot.selfdrive.ui.mici.onroad.torque_bar import TorqueBar
|
||||
from openpilot.selfdrive.ui.ui_state import ui_state, UIStatus, ChestnutState
|
||||
from openpilot.system.ui.lib.application import gui_app, FontWeight, ASSETS_DIR
|
||||
@@ -20,9 +21,9 @@ CRUISE_DISABLED_CHAR = '–'
|
||||
|
||||
SET_SPEED_PERSISTENCE = 2.5 # seconds
|
||||
WHEEL_SIZE = 52
|
||||
WHEEL_WHITE = (255, 255, 255)
|
||||
WHEEL_GREEN = (0, 255, 64)
|
||||
WHEEL_ORANGE = (255, 115, 0)
|
||||
WHEEL_WHITE = rl.Color(255, 255, 255, 255)
|
||||
WHEEL_GREEN = rl.Color(0, 255, 64, 255)
|
||||
WHEEL_ORANGE = rl.Color(255, 115, 0, 255)
|
||||
|
||||
|
||||
def _texture(rgba: np.ndarray, px: float) -> rl.Texture:
|
||||
@@ -109,8 +110,7 @@ class HudRenderer(Widget):
|
||||
self._txt_chestnut_orange: rl.Texture = gui_app.texture('icons_mici/chestnut_orange.png', 61, 36)
|
||||
self._chestnut_icon: rl.Texture | None = None
|
||||
self._wheel_alpha_filter = FirstOrderFilter(0, 0.05, 1 / gui_app.target_fps)
|
||||
self._wheel_color_filters = [FirstOrderFilter(c, 0.05, 1 / gui_app.target_fps) for c in WHEEL_WHITE]
|
||||
self._wheel_glow_filter = FirstOrderFilter(0, 0.05, 1 / gui_app.target_fps)
|
||||
self._wheel_critical_filter = FirstOrderFilter(0, STATUS_FADE_RC, 1 / gui_app.target_fps)
|
||||
|
||||
self._set_speed_alpha_filter = FirstOrderFilter(0.0, 0.1, 1 / gui_app.target_fps)
|
||||
self._chestnut_alpha_filter = FirstOrderFilter(0.0, 0.1, 1 / gui_app.target_fps)
|
||||
@@ -200,21 +200,17 @@ class HudRenderer(Widget):
|
||||
def _draw_steering_wheel(self, rect: rl.Rectangle) -> None:
|
||||
# The wheel is the source of truth for engagement: green if and only if openpilot is engaged.
|
||||
# When disengaged it's grayed out, except for steerRequired alerts which show it orange.
|
||||
engaged = ui_state.status == UIStatus.ENGAGED
|
||||
if engaged:
|
||||
target_color = WHEEL_GREEN
|
||||
elif self._show_wheel_critical:
|
||||
target_color = WHEEL_ORANGE
|
||||
else:
|
||||
target_color = WHEEL_WHITE
|
||||
critical = self._wheel_critical_filter.update(self._show_wheel_critical)
|
||||
idle_color = lerp_color(WHEEL_WHITE, WHEEL_ORANGE, critical)
|
||||
wheel_color = status_fade.color({UIStatus.ENGAGED: WHEEL_GREEN, UIStatus.OVERRIDE: idle_color, UIStatus.DISENGAGED: idle_color})
|
||||
engaged = status_fade.weight(UIStatus.ENGAGED)
|
||||
glow = engaged + (1 - engaged) * critical
|
||||
wheel_txt = self._txt_wheel
|
||||
|
||||
if self._show_wheel_critical or ui_state.status != UIStatus.DISENGAGED:
|
||||
self._wheel_alpha_filter.update(255)
|
||||
else:
|
||||
self._wheel_alpha_filter.update(255 * DIMMED_ICON_ALPHA)
|
||||
wheel_color = [int(f.update(c)) for f, c in zip(self._wheel_color_filters, target_color, strict=True)]
|
||||
glow = self._wheel_glow_filter.update(target_color != WHEEL_WHITE)
|
||||
|
||||
# pos
|
||||
pos_x = int(rect.x + rect.width / 2)
|
||||
@@ -225,10 +221,10 @@ class HudRenderer(Widget):
|
||||
origin = rl.Vector2(self._txt_wheel_glow.width / 2, self._txt_wheel_glow.height / 2)
|
||||
rl.draw_texture_pro(self._txt_wheel_glow, rl.Rectangle(0, 0, self._txt_wheel_glow.width, self._txt_wheel_glow.height),
|
||||
rl.Rectangle(pos_x, pos_y, self._txt_wheel_glow.width, self._txt_wheel_glow.height), origin, rotation,
|
||||
rl.Color(*wheel_color, int(alpha * glow)))
|
||||
rl.Color(wheel_color.r, wheel_color.g, wheel_color.b, int(alpha * glow)))
|
||||
rl.draw_texture_pro(wheel_txt, rl.Rectangle(0, 0, wheel_txt.width, wheel_txt.height),
|
||||
rl.Rectangle(pos_x, pos_y, wheel_txt.width, wheel_txt.height),
|
||||
rl.Vector2(wheel_txt.width / 2, wheel_txt.height / 2), rotation, rl.Color(*wheel_color, int(alpha)))
|
||||
rl.Vector2(wheel_txt.width / 2, wheel_txt.height / 2), rotation, rl.Color(wheel_color.r, wheel_color.g, wheel_color.b, int(alpha)))
|
||||
rl.draw_texture_pro(self._txt_wheel_highlight, rl.Rectangle(0, 0, wheel_txt.width, wheel_txt.height),
|
||||
rl.Rectangle(pos_x, pos_y, wheel_txt.width, wheel_txt.height),
|
||||
rl.Vector2(wheel_txt.width / 2, wheel_txt.height / 2), rotation, rl.Color(255, 255, 255, int(alpha * glow)))
|
||||
|
||||
@@ -6,6 +6,7 @@ from openpilot.selfdrive.controls.radard import RADAR_TO_CAMERA
|
||||
from openpilot.selfdrive.locationd.calibrationd import HEIGHT_INIT
|
||||
from openpilot.selfdrive.ui.ui_state import ui_state, UIStatus
|
||||
from openpilot.selfdrive.ui.mici.onroad import blend_colors
|
||||
from openpilot.selfdrive.ui.mici.onroad.status import status_fade
|
||||
from openpilot.selfdrive.ui.onroad.model_renderer import ModelRenderer as BaseModelRenderer, CLIP_MARGIN, MAX_DRAW_DISTANCE, STOCK_PATH_GRADIENT
|
||||
from openpilot.system.ui.lib.application import gui_app
|
||||
from openpilot.system.ui.lib.polygon import draw_polygon
|
||||
@@ -135,7 +136,7 @@ class ModelRenderer(BaseModelRenderer):
|
||||
def _get_ll_color(self, prob: float, adjacent: bool, left: bool):
|
||||
alpha = np.clip(prob, 0.0, 0.7)
|
||||
if adjacent:
|
||||
_base_color = LANE_LINE_COLORS.get(ui_state.status, LANE_LINE_COLORS[UIStatus.DISENGAGED])
|
||||
_base_color = status_fade.color(LANE_LINE_COLORS)
|
||||
color = rl.Color(_base_color.r, _base_color.g, _base_color.b, int(alpha * 255))
|
||||
|
||||
# turn adjacent lls orange if torque is high
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
"""
|
||||
Engaged and override can flap every frame (gas taps, steer override on driver torque near the threshold),
|
||||
so anything that looks different between them must go through status_fade instead of switching on
|
||||
ui_state.status. Override shows instantly and holds until engaged for OVERRIDE_HOLD, so flapping shows
|
||||
a steady override. Everything else fades.
|
||||
"""
|
||||
import numpy as np
|
||||
import raylib_nb as rl
|
||||
from openpilot.common.filter_simple import FirstOrderFilter
|
||||
from openpilot.selfdrive.ui.ui_state import ui_state, UIStatus
|
||||
from openpilot.system.ui.lib.application import gui_app
|
||||
|
||||
STATUS_FADE_RC = 0.25
|
||||
OVERRIDE_HOLD = 0.3
|
||||
STATUSES = tuple(UIStatus)
|
||||
|
||||
|
||||
def lerp_color(a: rl.Color, b: rl.Color, t: float) -> rl.Color:
|
||||
return rl.Color(*(round(x + (y - x) * t) for x, y in zip((a.r, a.g, a.b, a.a), (b.r, b.g, b.b, b.a), strict=True)))
|
||||
|
||||
|
||||
class StatusFade:
|
||||
"""ui_state.status as weights, stepped once per frame"""
|
||||
def __init__(self):
|
||||
self._weights: FirstOrderFilter | None = None
|
||||
self._frame = -1
|
||||
self._override_time = float('-inf')
|
||||
|
||||
def _update(self) -> np.ndarray:
|
||||
if self._weights is None or ui_state.sm.frame != self._frame:
|
||||
self._frame = ui_state.sm.frame
|
||||
now = rl.get_time()
|
||||
if ui_state.status == UIStatus.OVERRIDE:
|
||||
self._override_time = now
|
||||
held = ui_state.status == UIStatus.ENGAGED and now - self._override_time < OVERRIDE_HOLD
|
||||
status = UIStatus.OVERRIDE if held else ui_state.status
|
||||
target = np.array([status == s for s in STATUSES], dtype=float)
|
||||
if self._weights is None:
|
||||
self._weights = FirstOrderFilter(target, STATUS_FADE_RC, 1 / gui_app.target_fps)
|
||||
elif status == UIStatus.OVERRIDE:
|
||||
self._weights.x = target
|
||||
else:
|
||||
self._weights.update(target)
|
||||
return self._weights.x
|
||||
|
||||
def weight(self, status: UIStatus) -> float:
|
||||
return float(self._update()[STATUSES.index(status)])
|
||||
|
||||
def color(self, colors: dict[UIStatus, rl.Color]) -> rl.Color:
|
||||
rgba = sum(w * np.array([c.r, c.g, c.b, c.a], dtype=float) for w, c in zip(self._update(), (colors[s] for s in STATUSES), strict=True))
|
||||
return rl.Color(*np.round(rgba).astype(int).tolist())
|
||||
|
||||
|
||||
status_fade = StatusFade()
|
||||
@@ -7,6 +7,7 @@ import numpy as np
|
||||
import raylib_nb as rl
|
||||
from opendbc.car import ACCELERATION_DUE_TO_GRAVITY
|
||||
from openpilot.selfdrive.ui.mici.onroad import blend_colors
|
||||
from openpilot.selfdrive.ui.mici.onroad.status import status_fade
|
||||
from openpilot.selfdrive.ui.ui_state import ui_state, UIStatus
|
||||
from openpilot.system.ui.lib.application import gui_app
|
||||
from openpilot.system.ui.lib.polygon import draw_polygon, Gradient
|
||||
@@ -188,11 +189,11 @@ class TorqueBar(Widget):
|
||||
|
||||
# animate alpha and angle span
|
||||
self._torque_line_alpha_filter.update(ui_state.status != UIStatus.DISENGAGED and not self._hidden)
|
||||
engaged = status_fade.weight(UIStatus.ENGAGED)
|
||||
|
||||
torque_line_bg_alpha = np.interp(abs(self._torque_filter.x), [0.5, 1.0], [0.25, 0.5])
|
||||
# dimmer while not engaged
|
||||
torque_line_bg_alpha = 0.15 + (np.interp(abs(self._torque_filter.x), [0.5, 1.0], [0.25, 0.5]) - 0.15) * engaged
|
||||
torque_line_bg_color = rl.Color(255, 255, 255, int(255 * torque_line_bg_alpha * self._torque_line_alpha_filter.x))
|
||||
if ui_state.status != UIStatus.ENGAGED:
|
||||
torque_line_bg_color = rl.Color(255, 255, 255, int(255 * 0.15 * self._torque_line_alpha_filter.x))
|
||||
|
||||
# draw curved line polygon torque bar
|
||||
torque_line_radius = 1200
|
||||
@@ -235,8 +236,8 @@ class TorqueBar(Widget):
|
||||
max(0, abs(self._torque_filter.x) - 0.75) * 4,
|
||||
)
|
||||
|
||||
if ui_state.status != UIStatus.ENGAGED:
|
||||
start_color = end_color = rl.Color(255, 255, 255, int(255 * 0.35 * self._torque_line_alpha_filter.x))
|
||||
dimmed = rl.Color(255, 255, 255, int(255 * 0.35 * self._torque_line_alpha_filter.x))
|
||||
start_color, end_color = blend_colors(dimmed, start_color, engaged), blend_colors(dimmed, end_color, engaged)
|
||||
|
||||
gradient = Gradient(
|
||||
start=(start_grad_pt, 0),
|
||||
|
||||
Reference in New Issue
Block a user