From 6534f536ebf1a12c8d8d1817bfd9e0e766d05ea1 Mon Sep 17 00:00:00 2001 From: FrogAi <91348155+FrogAi@users.noreply.github.com> Date: Wed, 12 Jun 2024 16:44:50 -0700 Subject: [PATCH] Visuals - Model UI - Path Edges Adjust the width of the path edges shown on your UI to represent different driving modes and statuses. Default is 20% of the total path. Blue = Navigation Light Blue = 'Always On Lateral' Green = Default Orange = 'Experimental Mode' Red = 'Traffic Mode' Yellow = 'Conditional Experimental Mode' Overriden --- selfdrive/ui/qt/onroad/annotated_camera.cc | 44 ++++++++++++++++++++++ selfdrive/ui/ui.cc | 6 ++- selfdrive/ui/ui.h | 2 + 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/selfdrive/ui/qt/onroad/annotated_camera.cc b/selfdrive/ui/qt/onroad/annotated_camera.cc index 941acd068..8218c0419 100644 --- a/selfdrive/ui/qt/onroad/annotated_camera.cc +++ b/selfdrive/ui/qt/onroad/annotated_camera.cc @@ -443,6 +443,50 @@ void AnnotatedCameraWidget::drawLaneLines(QPainter &painter, const UIState *s, c paintLane(scene.track_adjacent_vertices[5], laneWidthRight, blindSpotRight); } + // Paint path edges + QLinearGradient pe(0, height(), 0, 0); + auto setGradientColors = [&](const QColor &baseColor) { + pe.setColorAt(0.0, baseColor); + QColor color = baseColor; + color.setAlphaF(0.5); + pe.setColorAt(0.5, color); + color.setAlphaF(0.1); + pe.setColorAt(1.0, color); + }; + + if (alwaysOnLateralActive) { + setGradientColors(bg_colors[STATUS_ALWAYS_ON_LATERAL_ACTIVE]); + } else if (conditionalStatus == 1 || conditionalStatus == 3 || conditionalStatus == 5) { + setGradientColors(bg_colors[STATUS_CONDITIONAL_OVERRIDDEN]); + } else if (experimentalMode) { + setGradientColors(bg_colors[STATUS_EXPERIMENTAL_MODE_ACTIVE]); + } else if (trafficModeActive) { + setGradientColors(bg_colors[STATUS_TRAFFIC_MODE_ACTIVE]); + } else if (scene.navigate_on_openpilot) { + setGradientColors(bg_colors[STATUS_NAVIGATION_ACTIVE]); + } else if (currentHolidayTheme != 0) { + const std::map &colorMap = std::get<2>(holidayThemeConfiguration[currentHolidayTheme]); + for (const std::pair &entry : colorMap) { + pe.setColorAt(entry.first, entry.second.color().darker(120)); + } + } else if (customColors != 0) { + const std::map &colorMap = std::get<2>(themeConfiguration[customColors]); + for (const std::pair &entry : colorMap) { + pe.setColorAt(entry.first, entry.second.color().darker(120)); + } + } else { + pe.setColorAt(0.0, QColor::fromHslF(148 / 360., 0.94, 0.51, 1.0)); + pe.setColorAt(0.5, QColor::fromHslF(112 / 360., 1.00, 0.68, 0.5)); + pe.setColorAt(1.0, QColor::fromHslF(112 / 360., 1.00, 0.68, 0.1)); + } + + QPainterPath path; + path.addPolygon(scene.track_vertices); + path.addPolygon(scene.track_edge_vertices); + + painter.setBrush(pe); + painter.drawPath(path); + painter.restore(); } diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index edc7a04fc..7279c554c 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -133,7 +133,10 @@ void update_model(UIState *s, } } max_idx = get_path_length_idx(plan_position, max_distance); - update_line_data(s, plan_position, 0.9, 1.22, &scene.track_vertices, max_idx, false); + update_line_data(s, plan_position, scene.model_ui ? path * (1 - scene.path_edge_width / 100.0f) : 0.9, 1.22, &scene.track_vertices, max_idx, false); + + // Update path edges + update_line_data(s, plan_position, scene.model_ui ? path : 0, 1.22, &scene.track_edge_vertices, max_idx, false); } void update_dmonitoring(UIState *s, const cereal::DriverStateV2::Reader &driverstate, float dm_fade_state, bool is_rhd) { @@ -400,6 +403,7 @@ void ui_update_frogpilot_params(UIState *s) { scene.dynamic_path_width = scene.model_ui && params.getBool("DynamicPathWidth"); scene.hide_lead_marker = scene.model_ui && params.getBool("HideLeadMarker"); scene.lane_line_width = params.getInt("LaneLinesWidth") * (scene.is_metric ? 1.0f : INCH_TO_CM) / 200.0f; + scene.path_edge_width = params.getInt("PathEdgeWidth"); bool quality_of_life_controls = params.getBool("QOLControls"); scene.reverse_cruise = quality_of_life_controls && params.getBool("ReverseCruise"); diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 28a34a5cf..27dc2d6e9 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -205,6 +205,7 @@ typedef struct UIScene { float lane_width_right; float lat_accel; float lead_detection_threshold; + float path_edge_width; float road_curvature; float speed_jerk; float speed_jerk_difference; @@ -235,6 +236,7 @@ typedef struct UIScene { int wheel_icon; QPolygonF track_adjacent_vertices[6]; + QPolygonF track_edge_vertices; } UIScene;