raylib: use filter for allow throttle (#36209)

* use time here

* use epic filter

* rm

* intermediary

* tune
pull/36208/head
Shane Smiskol 2 days ago committed by GitHub
parent 0711160b1c
commit 9297cd2f3e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      selfdrive/ui/onroad/alert_renderer.py
  2. 26
      selfdrive/ui/onroad/model_renderer.py
  3. 2
      selfdrive/ui/ui_state.py

@ -4,7 +4,7 @@ from dataclasses import dataclass
from cereal import messaging, log from cereal import messaging, log
from openpilot.selfdrive.ui.ui_state import ui_state from openpilot.selfdrive.ui.ui_state import ui_state
from openpilot.system.hardware import TICI from openpilot.system.hardware import TICI
from openpilot.system.ui.lib.application import gui_app, FontWeight, DEFAULT_FPS from openpilot.system.ui.lib.application import gui_app, FontWeight
from openpilot.system.ui.lib.text_measure import measure_text_cached from openpilot.system.ui.lib.text_measure import measure_text_cached
from openpilot.system.ui.widgets import Widget from openpilot.system.ui.widgets import Widget
from openpilot.system.ui.widgets.label import gui_text_box from openpilot.system.ui.widgets.label import gui_text_box
@ -76,7 +76,7 @@ class AlertRenderer(Widget):
# Check if selfdriveState messages have stopped arriving # Check if selfdriveState messages have stopped arriving
if not sm.updated['selfdriveState']: if not sm.updated['selfdriveState']:
recv_frame = sm.recv_frame['selfdriveState'] recv_frame = sm.recv_frame['selfdriveState']
time_since_onroad = (sm.frame - ui_state.started_frame) / DEFAULT_FPS time_since_onroad = time.monotonic() - ui_state.started_time
# 1. Never received selfdriveState since going onroad # 1. Never received selfdriveState since going onroad
waiting_for_startup = recv_frame < ui_state.started_frame waiting_for_startup = recv_frame < ui_state.started_frame

@ -3,6 +3,7 @@ import numpy as np
import pyray as rl import pyray as rl
from cereal import messaging, car from cereal import messaging, car
from dataclasses import dataclass, field from dataclasses import dataclass, field
from openpilot.common.filter_simple import FirstOrderFilter
from openpilot.common.params import Params from openpilot.common.params import Params
from openpilot.selfdrive.locationd.calibrationd import HEIGHT_INIT from openpilot.selfdrive.locationd.calibrationd import HEIGHT_INIT
from openpilot.selfdrive.ui.ui_state import ui_state from openpilot.selfdrive.ui.ui_state import ui_state
@ -49,7 +50,7 @@ class ModelRenderer(Widget):
super().__init__() super().__init__()
self._longitudinal_control = False self._longitudinal_control = False
self._experimental_mode = False self._experimental_mode = False
self._blend_factor = 1.0 self._blend_filter = FirstOrderFilter(1.0, 0.25, 1 / DEFAULT_FPS)
self._prev_allow_throttle = True self._prev_allow_throttle = True
self._lane_line_probs = np.zeros(4, dtype=np.float32) self._lane_line_probs = np.zeros(4, dtype=np.float32)
self._road_edge_stds = np.zeros(2, dtype=np.float32) self._road_edge_stds = np.zeros(2, dtype=np.float32)
@ -277,6 +278,9 @@ class ModelRenderer(Widget):
if not self._path.projected_points.size: if not self._path.projected_points.size:
return return
allow_throttle = sm['longitudinalPlan'].allowThrottle or not self._longitudinal_control
self._blend_filter.update(int(allow_throttle))
if self._experimental_mode: if self._experimental_mode:
# Draw with acceleration coloring # Draw with acceleration coloring
if len(self._exp_gradient['colors']) > 1: if len(self._exp_gradient['colors']) > 1:
@ -284,23 +288,9 @@ class ModelRenderer(Widget):
else: else:
draw_polygon(self._rect, self._path.projected_points, rl.Color(255, 255, 255, 30)) draw_polygon(self._rect, self._path.projected_points, rl.Color(255, 255, 255, 30))
else: else:
# Draw with throttle/no throttle gradient # Blend throttle/no throttle colors based on transition
allow_throttle = sm['longitudinalPlan'].allowThrottle or not self._longitudinal_control blend_factor = round(self._blend_filter.x * 100) / 100
blended_colors = self._blend_colors(NO_THROTTLE_COLORS, THROTTLE_COLORS, blend_factor)
# Start transition if throttle state changes
if allow_throttle != self._prev_allow_throttle:
self._prev_allow_throttle = allow_throttle
self._blend_factor = max(1.0 - self._blend_factor, 0.0)
# Update blend factor
if self._blend_factor < 1.0:
self._blend_factor = min(self._blend_factor + PATH_BLEND_INCREMENT, 1.0)
begin_colors = NO_THROTTLE_COLORS if allow_throttle else THROTTLE_COLORS
end_colors = THROTTLE_COLORS if allow_throttle else NO_THROTTLE_COLORS
# Blend colors based on transition
blended_colors = self._blend_colors(begin_colors, end_colors, self._blend_factor)
gradient = { gradient = {
'start': (0.0, 1.0), # Bottom of path 'start': (0.0, 1.0), # Bottom of path
'end': (0.0, 0.0), # Top of path 'end': (0.0, 0.0), # Top of path

@ -59,6 +59,7 @@ class UIState:
# UI Status tracking # UI Status tracking
self.status: UIStatus = UIStatus.DISENGAGED self.status: UIStatus = UIStatus.DISENGAGED
self.started_frame: int = 0 self.started_frame: int = 0
self.started_time: float = 0.0
self._engaged_prev: bool = False self._engaged_prev: bool = False
self._started_prev: bool = False self._started_prev: bool = False
@ -131,6 +132,7 @@ class UIState:
if self.started: if self.started:
self.status = UIStatus.DISENGAGED self.status = UIStatus.DISENGAGED
self.started_frame = self.sm.frame self.started_frame = self.sm.frame
self.started_time = time.monotonic()
self._started_prev = self.started self._started_prev = self.started

Loading…
Cancel
Save