From f0dba2446a9d16a70451c019d2bdced7e651e34d Mon Sep 17 00:00:00 2001 From: royjr Date: Wed, 11 Feb 2026 01:14:41 -0500 Subject: [PATCH] ConfidenceVisual --- common/params_keys.h | 2 +- selfdrive/ui/onroad/augmented_road_view.py | 25 ++++++++++++++++--- .../ui/sunnypilot/layouts/settings/visuals.py | 15 +++++++---- selfdrive/ui/sunnypilot/ui_state.py | 2 +- sunnypilot/sunnylink/params_metadata.json | 4 +-- 5 files changed, 36 insertions(+), 12 deletions(-) diff --git a/common/params_keys.h b/common/params_keys.h index 211631b6c0..f4a005e72e 100644 --- a/common/params_keys.h +++ b/common/params_keys.h @@ -25,7 +25,7 @@ inline static std::unordered_map keys = { {"CarParamsPersistent", {PERSISTENT, BYTES}}, {"CarParamsPrevRoute", {PERSISTENT, BYTES}}, {"CompletedTrainingVersion", {PERSISTENT, STRING, "0"}}, - {"ConfidenceBall", {PERSISTENT | BACKUP, BOOL, "0"}}, + {"ConfidenceVisual", {PERSISTENT | BACKUP, INT, "0"}}, {"ControlsReady", {CLEAR_ON_MANAGER_START | CLEAR_ON_ONROAD_TRANSITION, BOOL}}, {"CurrentBootlog", {PERSISTENT, STRING}}, {"CurrentRoute", {CLEAR_ON_MANAGER_START | CLEAR_ON_ONROAD_TRANSITION, STRING}}, diff --git a/selfdrive/ui/onroad/augmented_road_view.py b/selfdrive/ui/onroad/augmented_road_view.py index 8546fa8e2e..b28a40c2d6 100644 --- a/selfdrive/ui/onroad/augmented_road_view.py +++ b/selfdrive/ui/onroad/augmented_road_view.py @@ -57,7 +57,9 @@ class AugmentedRoadView(CameraView, AugmentedRoadViewSP): self._hud_renderer = HudRenderer() self.alert_renderer = AlertRenderer() self.driver_state_renderer = DriverStateRenderer() - self._confidence_ball = ConfidenceBall(scale = 1.0, bar = True) + + self._confidence_visual: ConfidenceBall | None = None + self._confidence_visual_mode: int = 0 # debug self._pm = messaging.PubMaster(['uiDebug']) @@ -106,8 +108,9 @@ class AugmentedRoadView(CameraView, AugmentedRoadViewSP): # End clipping region rl.end_scissor_mode() - if ui_state.confidence_ball: - self._confidence_ball.render(self._content_rect) + self._update_confidence_visual() + if self._confidence_visual is not None: + self._confidence_visual.render(self._content_rect) # Draw colored border based on driving state self._draw_border(rect) @@ -239,6 +242,22 @@ class AugmentedRoadView(CameraView, AugmentedRoadViewSP): if gui_app.sunnypilot_ui(): ui_state.reset_onroad_sleep_timer(OnroadTimerStatus.PAUSE) + def _update_confidence_visual(self): + mode = int(getattr(ui_state, "confidence_visual", 0) or 0) + + # Only rebuild when the mode changes + if mode == self._confidence_visual_mode: + return + + self._confidence_visual_mode = mode + + if mode == 1: + self._confidence_visual = ConfidenceBall(scale=1.0, bar=False) + elif mode == 2: + self._confidence_visual = ConfidenceBall(scale=1.0, bar=True) + else: + self._confidence_visual = None + if __name__ == "__main__": gui_app.init_window("OnRoad Camera View") diff --git a/selfdrive/ui/sunnypilot/layouts/settings/visuals.py b/selfdrive/ui/sunnypilot/layouts/settings/visuals.py index f6c4831811..3d5b7e01e2 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/visuals.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/visuals.py @@ -39,11 +39,6 @@ class VisualsLayout(Widget): tr("Display steering arc on the driving screen when lateral control is enabled."), None, ), - "ConfidenceBall": ( - lambda: tr("Confidence Ball"), - tr("Display confidence ball on the driving screen."), - True, - ), "RainbowMode": ( lambda: tr("Enable Tesla Rainbow Mode"), tr("A beautiful rainbow effect on the path the model wants to take. " + @@ -125,10 +120,18 @@ class VisualsLayout(Widget): button_width=350, inline=False ) + self._confidence_visual = multiple_button_item_sp( + title=lambda: tr("Confidence Visual"), + description=lambda: tr("Display confidence ball or bar on the driving screen."), + buttons=[lambda: tr("Off"), lambda: tr("Ball"), lambda: tr("Bar")], + param="ConfidenceVisual", + inline=False + ) items = list(self._toggles.values()) + [ self._chevron_info, self._dev_ui_info, + self._confidence_visual, ] return items @@ -140,6 +143,8 @@ class VisualsLayout(Widget): self._dev_ui_info.action_item.set_selected_button(ui_state.params.get("DevUIInfo", return_default=True)) + self._confidence_visual.action_item.set_selected_button(ui_state.params.get("ConfidenceVisual", return_default=True)) + if ui_state.has_longitudinal_control: self._chevron_info.set_description(tr(CHEVRON_INFO_DESCRIPTION["enabled"])) self._chevron_info.action_item.set_selected_button(ui_state.params.get("ChevronInfo", return_default=True)) diff --git a/selfdrive/ui/sunnypilot/ui_state.py b/selfdrive/ui/sunnypilot/ui_state.py index 6e06eac906..42b55fc00b 100644 --- a/selfdrive/ui/sunnypilot/ui_state.py +++ b/selfdrive/ui/sunnypilot/ui_state.py @@ -138,7 +138,7 @@ class UIStateSP: self.torque_bar = self.params.get_bool("TorqueBar") self.true_v_ego_ui = self.params.get_bool("TrueVEgoUI") self.turn_signals = self.params.get_bool("ShowTurnSignals") - self.confidence_ball = self.params.get_bool("ConfidenceBall") + self.confidence_visual = self.params.get("ConfidenceVisual") class DeviceSP: diff --git a/sunnypilot/sunnylink/params_metadata.json b/sunnypilot/sunnylink/params_metadata.json index 82a845efc3..9f537d1791 100644 --- a/sunnypilot/sunnylink/params_metadata.json +++ b/sunnypilot/sunnylink/params_metadata.json @@ -182,8 +182,8 @@ "title": "Completed Training Version", "description": "" }, - "ConfidenceBall": { - "title": "Confidence Ball", + "ConfidenceVisual": { + "title": "Confidence Visual", "description": "" }, "ControlsReady": {