mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-04-06 18:04:00 +08:00
better
This commit is contained in:
@@ -185,7 +185,9 @@ def modeld_lagging_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubM
|
||||
def joystick_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int, personality) -> Alert:
|
||||
gb = sm['carControl'].actuators.accel / 4.
|
||||
steer = sm['carControl'].actuators.torque
|
||||
vals = f"Gas: {round(gb * 100.)}%, Steer: {round(steer * 100.)}%"
|
||||
damp = sm['carControl'].actuators.dampFactor
|
||||
damp_pct = round((damp - 3) / (200 - 3) * 100.) if damp > 0 else 50
|
||||
vals = f"Gas: {round(gb * 100.)}%, Steer: {round(steer * 100.)}%\nDamp: {damp_pct}%"
|
||||
return NormalPermanentAlert("Joystick Mode", vals)
|
||||
|
||||
|
||||
|
||||
@@ -6,56 +6,14 @@ See the LICENSE.md file in the root directory for more details.
|
||||
"""
|
||||
import pyray as rl
|
||||
|
||||
from openpilot.common.params import Params
|
||||
from openpilot.selfdrive.ui.mici.onroad.hud_renderer import HudRenderer
|
||||
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.application import gui_app, FontWeight
|
||||
|
||||
|
||||
class JoystickDebugOverlay:
|
||||
def __init__(self):
|
||||
self._params = Params()
|
||||
self._font = None
|
||||
|
||||
def _ensure_font(self):
|
||||
if self._font is None:
|
||||
self._font = gui_app.font(FontWeight.BOLD)
|
||||
|
||||
def render(self, rect: rl.Rectangle) -> None:
|
||||
if not self._params.get_bool("JoystickDebugMode"):
|
||||
return
|
||||
if not ui_state.started:
|
||||
return
|
||||
|
||||
self._ensure_font()
|
||||
|
||||
actuators = ui_state.sm['carControl'].actuators
|
||||
accel = actuators.accel
|
||||
lateral = actuators.torque
|
||||
damp = actuators.dampFactor if actuators.dampFactor > 0 else 100.0
|
||||
|
||||
font_size = 48
|
||||
line_height = 60
|
||||
x = rect.x + rect.width - 300
|
||||
y = rect.y + 120
|
||||
|
||||
labels = [
|
||||
("ACCEL", f"{accel:+.2f}"),
|
||||
("LATERAL", f"{lateral:+.2f}"),
|
||||
("DAMP", f"{damp:.0f}"),
|
||||
]
|
||||
|
||||
for label, value in labels:
|
||||
rl.draw_text_ex(self._font, f"{label}: {value}", rl.Vector2(x, y), font_size, 0, rl.WHITE)
|
||||
y += line_height
|
||||
|
||||
|
||||
class HudRendererSP(HudRenderer):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.blind_spot_indicators = BlindSpotIndicators()
|
||||
self._joystick_overlay = JoystickDebugOverlay()
|
||||
|
||||
def _update_state(self) -> None:
|
||||
super()._update_state()
|
||||
@@ -64,7 +22,6 @@ class HudRendererSP(HudRenderer):
|
||||
def _render(self, rect: rl.Rectangle) -> None:
|
||||
super()._render(rect)
|
||||
self.blind_spot_indicators.render(rect)
|
||||
self._joystick_overlay.render(rect)
|
||||
|
||||
def _has_blind_spot_detected(self) -> bool:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user