mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-09-03 08:13:42 +08:00
move to sp
This commit is contained in:
@@ -132,7 +132,6 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
|
||||
{"UptimeOnroad", {PERSISTENT, FLOAT, "0.0"}},
|
||||
{"UsbGpuActive", {CLEAR_ON_MANAGER_START | CLEAR_ON_OFFROAD_TRANSITION | CLEAR_ON_IGNITION_ON, BOOL}},
|
||||
{"UsbGpuLoading", {CLEAR_ON_MANAGER_START | CLEAR_ON_OFFROAD_TRANSITION | CLEAR_ON_IGNITION_ON, BOOL}},
|
||||
{"UsbGpuLoadProgress", {CLEAR_ON_MANAGER_START | CLEAR_ON_OFFROAD_TRANSITION | CLEAR_ON_IGNITION_ON, INT, "0"}},
|
||||
{"Version", {PERSISTENT, STRING}},
|
||||
|
||||
// --- sunnypilot params --- //
|
||||
@@ -286,4 +285,5 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
|
||||
{"TorqueParamsOverrideEnabled", {PERSISTENT | BACKUP, BOOL, "0"}},
|
||||
{"TorqueParamsOverrideFriction", {PERSISTENT | BACKUP, FLOAT, "0.1"}},
|
||||
{"TorqueParamsOverrideLatAccelFactor", {PERSISTENT | BACKUP, FLOAT, "2.5"}},
|
||||
{"UsbGpuLoadProgress", {CLEAR_ON_MANAGER_START | CLEAR_ON_OFFROAD_TRANSITION | CLEAR_ON_IGNITION_ON, INT, "0"}},
|
||||
};
|
||||
|
||||
@@ -29,11 +29,11 @@ from openpilot.selfdrive.modeld.parse_model_outputs import Parser
|
||||
from openpilot.selfdrive.modeld.compile_modeld import make_input_queues, WARP_INPUTS, POLICY_INPUTS
|
||||
from openpilot.selfdrive.modeld.fill_model_msg import fill_model_msg, fill_driving_model_data, fill_pose_msg, PublishState
|
||||
from openpilot.common.file_chunker import open_file_chunked
|
||||
from openpilot.selfdrive.modeld.load_progress import open_with_progress
|
||||
from openpilot.selfdrive.modeld.constants import ModelConstants, Plan
|
||||
from openpilot.selfdrive.modeld.helpers import usbgpu_present, usbgpu_compiled, modeld_pkl_path, get_tg_input_devices, load_oob
|
||||
|
||||
from openpilot.sunnypilot.livedelay.helpers import get_lat_delay
|
||||
from openpilot.sunnypilot.modeld_v2.load_progress import open_with_progress
|
||||
from openpilot.sunnypilot.modeld_v2.modeld_base import ModelStateBase
|
||||
from openpilot.sunnypilot.selfdrive.controls.lib.relc import RoadEdgeLaneChangeController
|
||||
|
||||
@@ -224,7 +224,6 @@ def main(demo=False):
|
||||
os.environ['HCQDEV_WAIT_TIMEOUT_MS'] = '3000'
|
||||
params = Params()
|
||||
params.put_bool("UsbGpuLoading", USBGPU)
|
||||
params.put("UsbGpuLoadProgress", 0)
|
||||
params.remove("UsbGpuActive")
|
||||
|
||||
config_realtime_process(7, 54)
|
||||
|
||||
@@ -223,7 +223,7 @@ class HudRenderer(Widget):
|
||||
if icon is not self._egpu_icon:
|
||||
self._egpu_fade_time = rl.get_time()
|
||||
self._egpu_icon = icon
|
||||
alpha = self._egpu_alpha_filter.update(True)
|
||||
alpha = self._egpu_alpha_filter.update(loading or 0 < rl.get_time() - self._egpu_fade_time < SET_SPEED_PERSISTENCE)
|
||||
if alpha < 1e-2:
|
||||
return
|
||||
|
||||
@@ -231,18 +231,6 @@ class HudRenderer(Widget):
|
||||
rect.y + rect.height - 14 - (self._txt_wheel.height + icon.height) / 2)
|
||||
rl.draw_texture_ex(icon, pos, 0.0, 1.0, rl.Color(255, 255, 255, int(255 * opacity * alpha)))
|
||||
|
||||
if loading:
|
||||
pct_text = f"{ui_state.usbgpu_load_progress}%"
|
||||
size = FONT_SIZES.max_speed
|
||||
cell = measure_text_cached(self._font_bold, "0", size)
|
||||
widths = [cell.x if c.isdigit() else measure_text_cached(self._font_bold, c, size).x for c in pct_text]
|
||||
x = pos.x - 8 - sum(widths)
|
||||
y = pos.y + (icon.height - cell.y) / 2
|
||||
for c, w in zip(pct_text, widths, strict=True):
|
||||
glyph = measure_text_cached(self._font_bold, c, size).x
|
||||
rl.draw_text_ex(self._font_bold, c, rl.Vector2(x + (w - glyph) / 2, y), size, 0, rl.WHITE)
|
||||
x += w
|
||||
|
||||
def _draw_steering_wheel(self, rect: rl.Rectangle) -> None:
|
||||
wheel_txt = self._txt_wheel_critical if self._show_wheel_critical else self._txt_wheel
|
||||
|
||||
|
||||
@@ -6,8 +6,10 @@ See the LICENSE.md file in the root directory for more details.
|
||||
"""
|
||||
import pyray as rl
|
||||
|
||||
from openpilot.selfdrive.ui.mici.onroad.hud_renderer import HudRenderer
|
||||
from openpilot.selfdrive.ui.mici.onroad.hud_renderer import HudRenderer, FONT_SIZES, SET_SPEED_PERSISTENCE
|
||||
from openpilot.selfdrive.ui.sunnypilot.onroad.blind_spot_indicators import BlindSpotIndicators
|
||||
from openpilot.selfdrive.ui.ui_state import ui_state
|
||||
from openpilot.system.ui.lib.text_measure import measure_text_cached
|
||||
|
||||
|
||||
class HudRendererSP(HudRenderer):
|
||||
@@ -23,6 +25,28 @@ class HudRendererSP(HudRenderer):
|
||||
super()._render(rect)
|
||||
self.blind_spot_indicators.render(rect)
|
||||
|
||||
def _draw_model_source(self, rect: rl.Rectangle) -> None:
|
||||
self._egpu_fade_time = rl.get_time() - SET_SPEED_PERSISTENCE / 2
|
||||
super()._draw_model_source(rect)
|
||||
|
||||
if not ui_state.usbgpu_loading or ui_state.sm.recv_frame['selfdriveState'] < ui_state.started_frame:
|
||||
return
|
||||
|
||||
icon = self._txt_egpu
|
||||
pos = rl.Vector2(rect.x + rect.width - 10 - icon.width,
|
||||
rect.y + rect.height - 14 - (self._txt_wheel.height + icon.height) / 2)
|
||||
|
||||
pct_text = f"{ui_state.usbgpu_load_progress}%"
|
||||
size = FONT_SIZES.max_speed
|
||||
cell = measure_text_cached(self._font_bold, "0", size)
|
||||
widths = [cell.x if c.isdigit() else measure_text_cached(self._font_bold, c, size).x for c in pct_text]
|
||||
x = pos.x - 8 - sum(widths)
|
||||
y = pos.y + (icon.height - cell.y) / 2
|
||||
for c, w in zip(pct_text, widths):
|
||||
glyph = measure_text_cached(self._font_bold, c, size).x
|
||||
rl.draw_text_ex(self._font_bold, c, rl.Vector2(x + (w - glyph) / 2, y), size, 0, rl.WHITE)
|
||||
x += w
|
||||
|
||||
def _has_blind_spot_detected(self) -> bool:
|
||||
|
||||
return self.blind_spot_indicators.detected
|
||||
|
||||
@@ -42,6 +42,8 @@ class UIStateSP:
|
||||
self.screensaver = ScreenSaverSP(params=self.params)
|
||||
self.screensaver_enabled: bool = False
|
||||
|
||||
self.usbgpu_load_progress: int = self.params.get("UsbGpuLoadProgress", return_default=True)
|
||||
|
||||
self.active_bundle = None
|
||||
self.blindspot: bool = False
|
||||
self.chevron_metrics = None
|
||||
@@ -175,6 +177,8 @@ class UIStateSP:
|
||||
self.boot_offroad_mode = self.params.get("DeviceBootMode", return_default=True)
|
||||
self.always_offroad = self.params.get_bool("OffroadMode")
|
||||
self.screensaver_enabled = self.params.get_bool("ScreenSaverEnabled")
|
||||
if self.usbgpu_loading:
|
||||
self.usbgpu_load_progress = self.params.get("UsbGpuLoadProgress", return_default=True)
|
||||
|
||||
if not self._sp_initialized:
|
||||
self._sp_initialized = True
|
||||
|
||||
@@ -86,7 +86,6 @@ class UIState(UIStateSP):
|
||||
self.usbgpu_compiled: bool = usbgpu_compiled()
|
||||
self.usbgpu_active: bool | None = self.params.get("UsbGpuActive")
|
||||
self.usbgpu_loading: bool = self.params.get_bool("UsbGpuLoading")
|
||||
self.usbgpu_load_progress: int = self.params.get("UsbGpuLoadProgress", return_default=True)
|
||||
self.started: bool = False
|
||||
self.ignition: bool = False
|
||||
self.recording_audio: bool = False
|
||||
@@ -165,9 +164,6 @@ class UIState(UIStateSP):
|
||||
# Update started state
|
||||
self.started = self.sm["deviceState"].started and self.ignition
|
||||
|
||||
if self.usbgpu_loading:
|
||||
self.usbgpu_load_progress = self.params.get("UsbGpuLoadProgress", return_default=True)
|
||||
|
||||
# Update body state
|
||||
if self.CP is not None and self.is_body != self.CP.notCar:
|
||||
self.is_body = self.CP.notCar
|
||||
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
import os
|
||||
from openpilot.common.file_chunker import open_file_chunked, get_existing_chunks
|
||||
from openpilot.common.file_chunker import open_file_chunked, get_existing_chunks, get_manifest_path
|
||||
from openpilot.common.params import Params
|
||||
|
||||
PARAM = "UsbGpuLoadProgress"
|
||||
@@ -40,5 +40,6 @@ class ProgressReader:
|
||||
|
||||
|
||||
def open_with_progress(pkl_path):
|
||||
total = sum(os.path.getsize(p) for p in get_existing_chunks(pkl_path))
|
||||
manifest = get_manifest_path(pkl_path)
|
||||
total = sum(os.path.getsize(p) for p in get_existing_chunks(pkl_path) if p != manifest)
|
||||
return ProgressReader(open_file_chunked(pkl_path), total)
|
||||
@@ -25,7 +25,7 @@ from opendbc.car.car_helpers import get_demo_car_params
|
||||
from tinygrad.tensor import Tensor
|
||||
|
||||
from openpilot.common.file_chunker import open_file_chunked
|
||||
from openpilot.selfdrive.modeld.load_progress import open_with_progress
|
||||
from openpilot.sunnypilot.modeld_v2.load_progress import open_with_progress
|
||||
from openpilot.common.swaglog import cloudlog
|
||||
from openpilot.common.params import Params
|
||||
from openpilot.common.filter_simple import FirstOrderFilter
|
||||
|
||||
Reference in New Issue
Block a user