|
|
|
@ -3,6 +3,7 @@ import numpy as np |
|
|
|
|
import pyray as rl |
|
|
|
|
from cereal import messaging, car |
|
|
|
|
from dataclasses import dataclass, field |
|
|
|
|
from openpilot.common.filter_simple import FirstOrderFilter |
|
|
|
|
from openpilot.common.params import Params |
|
|
|
|
from openpilot.selfdrive.locationd.calibrationd import HEIGHT_INIT |
|
|
|
|
from openpilot.selfdrive.ui.ui_state import ui_state |
|
|
|
@ -49,7 +50,7 @@ class ModelRenderer(Widget): |
|
|
|
|
super().__init__() |
|
|
|
|
self._longitudinal_control = 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._lane_line_probs = np.zeros(4, 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: |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
allow_throttle = sm['longitudinalPlan'].allowThrottle or not self._longitudinal_control |
|
|
|
|
self._blend_filter.update(int(allow_throttle)) |
|
|
|
|
|
|
|
|
|
if self._experimental_mode: |
|
|
|
|
# Draw with acceleration coloring |
|
|
|
|
if len(self._exp_gradient['colors']) > 1: |
|
|
|
@ -284,23 +288,9 @@ class ModelRenderer(Widget): |
|
|
|
|
else: |
|
|
|
|
draw_polygon(self._rect, self._path.projected_points, rl.Color(255, 255, 255, 30)) |
|
|
|
|
else: |
|
|
|
|
# Draw with throttle/no throttle gradient |
|
|
|
|
allow_throttle = sm['longitudinalPlan'].allowThrottle or not self._longitudinal_control |
|
|
|
|
|
|
|
|
|
# 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) |
|
|
|
|
# Blend throttle/no throttle colors based on transition |
|
|
|
|
blend_factor = round(self._blend_filter.x * 100) / 100 |
|
|
|
|
blended_colors = self._blend_colors(NO_THROTTLE_COLORS, THROTTLE_COLORS, blend_factor) |
|
|
|
|
gradient = { |
|
|
|
|
'start': (0.0, 1.0), # Bottom of path |
|
|
|
|
'end': (0.0, 0.0), # Top of path |
|
|
|
|