Merge remote-tracking branch 'dev/min-feat/rainbow-path' into full

This commit is contained in:
Rick Lan
2025-05-27 12:30:10 +08:00
7 changed files with 45 additions and 1 deletions

View File

@@ -132,4 +132,5 @@ inline static std::unordered_map<std::string, uint32_t> keys = {
{"dp_ui_hide_hud_speed_kph", PERSISTENT},
{"dp_lon_ext_radar", PERSISTENT},
{"dp_lat_road_edge_detection", PERSISTENT},
{"dp_ui_rainbow", PERSISTENT},
};

View File

@@ -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<QString> 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"),

View File

@@ -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<qreal>(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<int>(track_vertices.length() / 2, acceleration.size());

View File

@@ -36,4 +36,7 @@ private:
QPointF lead_vertices[2] = {};
Eigen::Matrix3f car_space_transform = Eigen::Matrix3f::Zero();
QRectF clip_region;
QVector<QColor> dp_rainbow_color_list;
qreal dp_rainbow_rotation = 0;
bool dp_rainbow_init = false;
};

View File

@@ -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() {

View File

@@ -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;

View File

@@ -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"):