diff --git a/common/params_keys.h b/common/params_keys.h index 2d0ea8605..7a563bd2b 100644 --- a/common/params_keys.h +++ b/common/params_keys.h @@ -132,4 +132,5 @@ inline static std::unordered_map keys = { {"dp_ui_hide_hud_speed_kph", PERSISTENT}, {"dp_lon_ext_radar", PERSISTENT}, {"dp_lat_road_edge_detection", PERSISTENT}, + {"dp_ui_rainbow", PERSISTENT}, }; diff --git a/selfdrive/ui/qt/offroad/dp_panel.cc b/selfdrive/ui/qt/offroad/dp_panel.cc index 3eead0558..998a76718 100644 --- a/selfdrive/ui/qt/offroad/dp_panel.cc +++ b/selfdrive/ui/qt/offroad/dp_panel.cc @@ -197,6 +197,11 @@ void DPPanel::add_ui_toggles() { QString::fromUtf8("🐉 ") + tr("UI"), "", }, + { + "dp_ui_rainbow", + tr("Rainbow Driving Path like Tesla"), + tr("Why not?"), + }, }; std::vector display_off_mode_texts{tr("Std."), tr("MAIN+"), tr("OP+"), tr("MAIN-"), tr("OP-")}; ButtonParamControl* display_off_mode_setting = new ButtonParamControl("dp_ui_display_mode", tr("Display Mode"), diff --git a/selfdrive/ui/qt/onroad/model.cc b/selfdrive/ui/qt/onroad/model.cc index 52902abdc..5dc6117cc 100644 --- a/selfdrive/ui/qt/onroad/model.cc +++ b/selfdrive/ui/qt/onroad/model.cc @@ -107,7 +107,39 @@ void ModelRenderer::drawLaneLines(QPainter &painter) { void ModelRenderer::drawPath(QPainter &painter, const cereal::ModelDataV2::Reader &model, int height) { QLinearGradient bg(0, height, 0, 0); - if (experimental_mode) { + + auto *s = uiState(); + if (s->scene.dp_ui_rainbow) { + constexpr int NUM_COLORS = 25; + constexpr int ALPHA = 128; + + float v_ego = (*uiState()->sm)["carState"].getCarState().getVEgo(); + + if (!dp_rainbow_init) { + dp_rainbow_color_list.reserve(NUM_COLORS); + for (int i = 0; i < NUM_COLORS; ++i) { + qreal t = static_cast(i) / (NUM_COLORS - 1); + dp_rainbow_color_list.append(QColor::fromHsvF(t, 1.0, 1.0, ALPHA / 255.0)); + } + dp_rainbow_init = true; + } + bg.setSpread(QGradient::RepeatSpread); + // bigger = faster, however it is still limited to the global UI_FREQ (refresh rate) + // only way to make it move faster is to reduce NUM_COLORS, but that will also reduce the color smoothness. + qreal rotation_speed = std::max(0.01f, v_ego) / UI_FREQ; + dp_rainbow_rotation -= rotation_speed; + + if (dp_rainbow_rotation < 0.0) { + dp_rainbow_rotation += 1.0; + dp_rainbow_color_list.append(dp_rainbow_color_list.takeFirst()); + } + // fill color + const qreal step = 1.0 / (NUM_COLORS - 1); + for (int i = 0; i < NUM_COLORS; ++i) { + bg.setColorAt(i * step, dp_rainbow_color_list.at(i)); + } + + } else if (experimental_mode) { // The first half of track_vertices are the points for the right side of the path const auto &acceleration = model.getAcceleration().getX(); const int max_len = std::min(track_vertices.length() / 2, acceleration.size()); diff --git a/selfdrive/ui/qt/onroad/model.h b/selfdrive/ui/qt/onroad/model.h index 79547e4b8..ea2d1ddda 100644 --- a/selfdrive/ui/qt/onroad/model.h +++ b/selfdrive/ui/qt/onroad/model.h @@ -36,4 +36,7 @@ private: QPointF lead_vertices[2] = {}; Eigen::Matrix3f car_space_transform = Eigen::Matrix3f::Zero(); QRectF clip_region; + QVector dp_rainbow_color_list; + qreal dp_rainbow_rotation = 0; + bool dp_rainbow_init = false; }; diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 98676aba4..0ef2ba59d 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -69,6 +69,7 @@ void ui_update_params(UIState *s) { s->scene.disable_driver = getenv("DISABLE_DRIVER"); s->scene.display_mode = std::atoi(params.get("dp_ui_display_mode").c_str()); s->scene.dp_ui_hide_hud_speed_kph = std::atoi(params.get("dp_ui_hide_hud_speed_kph").c_str()); + s->scene.dp_ui_rainbow = params.getBool("dp_ui_rainbow"); } void UIState::updateStatus() { diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 3c47c821d..379ddea0e 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -61,6 +61,7 @@ typedef struct UIScene { float light_sensor = -1; bool started, ignition, is_metric; + bool dp_ui_rainbow; uint64_t started_frame; bool disable_driver = false; bool alka_active; diff --git a/system/manager/manager.py b/system/manager/manager.py index 991a5b0bb..60e312db1 100755 --- a/system/manager/manager.py +++ b/system/manager/manager.py @@ -54,6 +54,7 @@ def manager_init() -> None: ("dp_ui_hide_hud_speed_kph", "0"), ("dp_lon_ext_radar", "0"), ("dp_lat_road_edge_detection", "0"), + ("dp_ui_rainbow", "0"), ] if params.get_bool("RecordFrontLock"):