From b094bcb4f7009070387d60f9a9ec64c13cbfea5f Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Tue, 24 Nov 2026 19:19:31 -0600 Subject: [PATCH] Make the Lead Indicator editable in Galaxy --- .../ui/mici/onroad/model_renderer.py | 14 +++++--- .../selfdrive/ui/onroad/model_renderer.py | 9 +++-- .../galaxy/tests/test_onroad_layout.mjs | 24 ++++++++++++-- .../galaxy/web/js/onroad-layout-document.js | 3 +- .../galaxy/web/js/onroad-layout-template.js | 30 ++++++++++++++++- .../starpilot/galaxy/web/js/onroad-layout.js | 33 +++++++++++++++---- .../system/starport/projection_layout.py | 3 +- .../starpilot/ui/appearance_preferences.py | 19 +++++++---- .../starpilot/ui/onroad_customization.py | 2 +- openpilot/starpilot/ui/road_colors.py | 8 +++++ openpilot/starpilot/ui/runtime_app.py | 4 +-- .../starpilot/ui/tests/test_covered_camera.py | 6 ++-- openpilot/starpilot/ui/tests/test_lead_bar.py | 16 +++++++-- .../starpilot/ui/tests/test_lead_info.py | 12 ++++++- .../ui/tests/test_onroad_customization.py | 15 +++++++++ prebuilt.json | 2 +- 16 files changed, 166 insertions(+), 34 deletions(-) diff --git a/openpilot/selfdrive/ui/mici/onroad/model_renderer.py b/openpilot/selfdrive/ui/mici/onroad/model_renderer.py index 48a03239c4..95456c8f1e 100644 --- a/openpilot/selfdrive/ui/mici/onroad/model_renderer.py +++ b/openpilot/selfdrive/ui/mici/onroad/model_renderer.py @@ -7,7 +7,7 @@ from types import SimpleNamespace from openpilot.common.params import Params from openpilot.starpilot.ui.appearance_preferences import format_lead_info from openpilot.starpilot.ui.rainbow_path import RainbowPath -from openpilot.starpilot.ui.road_colors import lane_color, path_mode, solid_gradient +from openpilot.starpilot.ui.road_colors import lane_color, lead_marker_color, path_mode, solid_gradient from openpilot.starpilot.ui.onroad_customization import ROAD_COLORS from openpilot.starpilot.lateral.lane_feedback import BLUE, direction as lane_centering_direction from openpilot.common.filter_simple import FirstOrderFilter @@ -216,7 +216,8 @@ class ModelRenderer(ModelGeometry, Widget): @staticmethod def _valid_lead_numbers(lead) -> bool: try: - distance, lateral, relative_speed = float(lead.dRel), float(lead.yRel), float(lead.vRel) + distance, lateral = float(lead.dRel), float(lead.yRel) + relative_speed = float(lead.vRel) if lead.vRel is not None else 0.0 return distance > 0 and all(math.isfinite(value) for value in (distance, lateral, relative_speed)) except (AttributeError, TypeError, ValueError, OverflowError): return False @@ -227,6 +228,9 @@ class ModelRenderer(ModelGeometry, Widget): model = sm['modelV2'] e2e = (sm.valid['longitudinalPlan'] and sm.valid['modelV2'] and plan.longitudinalPlanSource == log.LongitudinalPlan.LongitudinalPlanSource.e2e and len(model.leadsV3) > 1) + ego_speed = sm['carState'].vEgo if e2e and sm.all_checks(['carState']) else None + if ego_speed is not None and not math.isfinite(ego_speed): + ego_speed = None leads = [] for index in range(2): info = None @@ -234,7 +238,8 @@ class ModelRenderer(ModelGeometry, Widget): candidate = model.leadsV3[index] if candidate.x and candidate.y and candidate.v: info = SimpleNamespace(present=candidate.prob > 0.5, dRel=candidate.x[0] - RADAR_TO_CAMERA, - yRel=-candidate.y[0], vRel=0.0, vLead=candidate.v[0]) + yRel=-candidate.y[0], vRel=candidate.v[0] - ego_speed if ego_speed is not None else None, + vLead=candidate.v[0]) elif sm.valid['radarState']: info = (sm['radarState'].leadOne, sm['radarState'].leadTwo)[index] valid = info is not None and info.present and self._valid_lead_numbers(info) @@ -488,7 +493,8 @@ class ModelRenderer(ModelGeometry, Widget): for lead in self._lead_vehicles: if not lead.bar.size or lead.fade_filter.x <= 0: continue - draw_polygon(self._rect, lead.bar + offset, rl.Color(255, 255, 255, int(255 * lead.fade_filter.x))) + color = lead_marker_color(self.road_style, lead.fade_filter.x) + draw_polygon(self._rect, lead.bar + offset, color if color is not None else rl.Color(255, 255, 255, int(255 * lead.fade_filter.x))) diff --git a/openpilot/selfdrive/ui/onroad/model_renderer.py b/openpilot/selfdrive/ui/onroad/model_renderer.py index 3ffadbe980..ea6f1650e1 100644 --- a/openpilot/selfdrive/ui/onroad/model_renderer.py +++ b/openpilot/selfdrive/ui/onroad/model_renderer.py @@ -8,7 +8,7 @@ from openpilot.common.filter_simple import FirstOrderFilter from openpilot.common.params import Params from openpilot.starpilot.ui.appearance_preferences import format_lead_info from openpilot.starpilot.ui.rainbow_path import RainbowPath -from openpilot.starpilot.ui.road_colors import edge_gradient, lane_color, path_mode, solid_gradient +from openpilot.starpilot.ui.road_colors import edge_gradient, lane_color, lead_marker_color, path_mode, solid_gradient from openpilot.starpilot.ui.onroad_customization import ROAD_COLORS from openpilot.starpilot.lateral.lane_feedback import BLUE, direction as lane_centering_direction from openpilot.selfdrive.locationd.calibrationd import HEIGHT_INIT @@ -413,8 +413,11 @@ class ModelRenderer(ModelGeometry, Widget): if not lead.glow or not lead.chevron: continue - rl.draw_triangle_fan(lead.glow, len(lead.glow), rl.Color(218, 202, 37, 255)) - rl.draw_triangle_fan(lead.chevron, len(lead.chevron), rl.Color(201, 34, 49, lead.fill_alpha)) + style = self.road_style + glow = lead_marker_color(style, 1.0) + fill = lead_marker_color(style, lead.fill_alpha / 255) + rl.draw_triangle_fan(lead.glow, len(lead.glow), glow if glow is not None else rl.Color(218, 202, 37, 255)) + rl.draw_triangle_fan(lead.chevron, len(lead.chevron), fill if fill is not None else rl.Color(201, 34, 49, lead.fill_alpha)) def _draw_lead_info(self, lead: LeadVehicle, text: str) -> None: # Centered just above the chevron's glow, kept on screen. diff --git a/openpilot/starpilot/galaxy/tests/test_onroad_layout.mjs b/openpilot/starpilot/galaxy/tests/test_onroad_layout.mjs index 4b6f6dc102..63438fd995 100644 --- a/openpilot/starpilot/galaxy/tests/test_onroad_layout.mjs +++ b/openpilot/starpilot/galaxy/tests/test_onroad_layout.mjs @@ -1161,7 +1161,7 @@ const displayRows = [ { key: "DeveloperSidebar", label: "Developer Sidebar", group: "Big layout", choices: ["Off", "On"], available: true, reason: "", requires: "" }, { key: "ShowBrakeStatus", label: "Wheel brake and acceleration colors", group: "widget", choices: ["Off", "On"], available: true, reason: "", requires: "" }, { key: "HideLeadMarker", label: "Lead Indicator", group: "Lead car", choices: ["Off", "On"], available: true, reason: "", requires: "" }, - { key: "LeadInfo", label: "Lead Info", group: "Lead car", choices: ["Off", "Distance", "Speed"], available: true, reason: "", requires: "HideLeadMarker" }, + { key: "LeadInfo", label: "Lead Info", group: "Lead car", choices: ["Off", "Distance", "Speed", "Relative speed"], available: true, reason: "", requires: "HideLeadMarker" }, { key: "SignalMetrics", label: "C4 amber signal border", group: "Alerts and borders", choices: ["Off", "On"], available: true, reason: "", requires: "" }, ] const withDisplayData = () => ({ ...snapshot(), display: { rows: copy(displayRows), @@ -1179,7 +1179,7 @@ assert.equal(validDocument({ ...merged.document, showMaxSpeed: "no" }, merged.me const display = editor() display.vm.state.data = merged; display.vm.state.draft = copy(merged.document) assert.deepEqual(display.vm.displayGroups.map(group => [group.name, group.rows.map(row => row.key)]), - [["Big layout", ["DeveloperSidebar"]], ["Lead car", ["HideLeadMarker", "LeadInfo"]], ["Alerts and borders", ["SignalMetrics"]]]) + [["Big layout", ["DeveloperSidebar"]], ["Alerts and borders", ["SignalMetrics"]]]) display.vm.setDisplay("DeveloperSidebar", "Off") assert.equal(display.vm.displaySettingRow(display.vm.displayRow("DeveloperSidebar")).value, "Off") assert.equal(display.vm.dirty, true) @@ -1263,6 +1263,26 @@ assert.equal(display.vm.displayValue("LeadInfo"), "Distance") assert.equal(display.vm.dirty, true) display.vm.undo(); display.vm.undo() assert.equal(display.vm.dirty, false) +display.vm.openLeadEditor() +assert.equal(display.vm.state.inspectorPanel, "lead") +assert.equal(display.vm.leadRows.length, 2) +display.vm.setDisplay("HideLeadMarker", "On") +display.vm.setDisplay("LeadInfo", "Relative speed") +assert.equal(display.vm.leadPreviewLabel, "+4 mph") +display.vm.roadColor("leadMarker", "#22CCFFFF") +assert.equal(display.vm.leadColor, "#22CCFFFF") +assert.equal(validDocument(display.vm.state.draft, display.vm.state.data.metadata), true) +display.vm.resetRoad() +assert.equal(display.vm.leadColor, "#22CCFFFF") +display.vm.state.data.supportedProfiles = ["large", "compact"] +display.vm.selectProfile("compact") +assert.equal(display.vm.leadColor, "#FFFFFFFF") +display.vm.selectProfile("large") +display.vm.resetLeadColor() +assert.equal(display.vm.leadColor, "#C92231FF") +display.vm.undo() +assert.equal(display.vm.leadColor, "#22CCFFFF") +display.vm.resetToStock() display.vm.state.selected = "cruise_limits" display.vm.setShowMaxSpeed({ target: { checked: false } }) assert.equal(display.vm.state.draft.showMaxSpeed, false) diff --git a/openpilot/starpilot/galaxy/web/js/onroad-layout-document.js b/openpilot/starpilot/galaxy/web/js/onroad-layout-document.js index b51e0a92f0..523046fb32 100644 --- a/openpilot/starpilot/galaxy/web/js/onroad-layout-document.js +++ b/openpilot/starpilot/galaxy/web/js/onroad-layout-document.js @@ -168,7 +168,8 @@ export function validDocument(document, metadata) { const profile = metadata.profiles[name], layout = document.layouts[name] const road = document.roadColors[name] if (!object(road) || !Object.entries(road).every(([key, value]) => key === "pathMode" ? PATH_MODES.includes(value) : - ROAD_COLORS.includes(key) && typeof value === "string" && HEX.test(value))) return false + (ROAD_COLORS.includes(key) || key === "leadMarker") && + typeof value === "string" && HEX.test(value))) return false const colors = document.widgetColors[name] if (!object(colors) || !Object.entries(colors).every(([id, overrides]) => { const fields = profile.widgets[id]?.colors diff --git a/openpilot/starpilot/galaxy/web/js/onroad-layout-template.js b/openpilot/starpilot/galaxy/web/js/onroad-layout-template.js index abf27a7a08..b91f49b552 100644 --- a/openpilot/starpilot/galaxy/web/js/onroad-layout-template.js +++ b/openpilot/starpilot/galaxy/web/js/onroad-layout-template.js @@ -132,6 +132,20 @@ export const ONROAD_LAYOUT_TEMPLATE = ` {{ zone.label }} + + + + + {{ leadPreviewLabel }} + + Loading Widgets @@ -196,6 +210,9 @@ export const ONROAD_LAYOUT_TEMPLATE = `

Tap a widget to edit it.

Drag ⠿ to reorder. The top row is in front, and alerts stay above all widgets. Each side camera can be locked to the front; unlock it to move widgets above.

The eyes follow the chosen scene. Choose General edit to arrange every enabled widget. Hiding a widget with the eye affects only this scene's preview.

+
+ +
+
+

Lead Indicator

+ +
+ + + +
+

Path & Lane Colors