mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-04-07 12:23:54 +08:00
Radar Track UI - init
This commit is contained in:
@@ -122,4 +122,5 @@ inline static std::unordered_map<std::string, uint32_t> keys = {
|
||||
{"Version", PERSISTENT},
|
||||
{"dp_device_last_log", CLEAR_ON_ONROAD_TRANSITION},
|
||||
{"dp_device_reset_conf", CLEAR_ON_MANAGER_START},
|
||||
{"dp_ui_radar_tracks", PERSISTENT},
|
||||
};
|
||||
|
||||
@@ -172,6 +172,11 @@ void DPPanel::add_ui_toggles() {
|
||||
QString::fromUtf8("🐉 ") + tr("UI"),
|
||||
"",
|
||||
},
|
||||
{
|
||||
"dp_ui_radar_tracks",
|
||||
tr("Display Radar Tracks"),
|
||||
"",
|
||||
},
|
||||
};
|
||||
|
||||
QWidget *label = nullptr;
|
||||
@@ -183,6 +188,9 @@ void DPPanel::add_ui_toggles() {
|
||||
addItem(label);
|
||||
continue;
|
||||
}
|
||||
if (param == "dp_ui_radar_tracks" && !vehicle_has_long_ctrl) {
|
||||
continue;
|
||||
}
|
||||
|
||||
has_toggle = true;
|
||||
auto toggle = new ParamControl(param, title, desc, "", this);
|
||||
|
||||
@@ -48,6 +48,11 @@ void ModelRenderer::draw(QPainter &painter, const QRect &surface_rect) {
|
||||
}
|
||||
}
|
||||
|
||||
if (s->scene.dp_ui_radar_tracks) {
|
||||
const auto &live_tracks = sm["liveTracks"].getLiveTracks();
|
||||
drawLiveTracks(painter, live_tracks, model, surface_rect);
|
||||
}
|
||||
|
||||
painter.restore();
|
||||
}
|
||||
|
||||
@@ -186,6 +191,56 @@ QColor ModelRenderer::blendColors(const QColor &start, const QColor &end, float
|
||||
(1 - t) * start.alphaF() + t * end.alphaF());
|
||||
}
|
||||
|
||||
void ModelRenderer::drawLiveTracks(QPainter &painter,
|
||||
const cereal::RadarData::Reader &live_tracks,
|
||||
const cereal::ModelDataV2::Reader &model_data,
|
||||
const QRect &surface_rect) {
|
||||
|
||||
// Get the model's predicted path for Z-coordinate calculation
|
||||
const auto& model_path_position = model_data.getPosition();
|
||||
|
||||
// Set text properties
|
||||
painter.setPen(Qt::white);
|
||||
painter.setFont(QFont("Inter", 24, QFont::Bold));
|
||||
|
||||
// Iterate through each radar point from live_tracks
|
||||
for (const auto& point : live_tracks.getPoints()) {
|
||||
float dRel = point.getDRel();
|
||||
float yRel = point.getYRel();
|
||||
float yvRel = point.getYvRel();
|
||||
float vRel = point.getVRel();
|
||||
|
||||
// Calculate Z-coordinate using the model's path
|
||||
float z_on_path = path_offset_z; // Default base offset
|
||||
|
||||
// Ensure dRel is non-negative for indexing
|
||||
if (dRel >= 0) {
|
||||
z_on_path += model_path_position.getZ()[get_path_length_idx(model_path_position, dRel)];
|
||||
}
|
||||
|
||||
QPointF screen_pos;
|
||||
// mapToScreen projects a point from car space to screen space
|
||||
if (mapToScreen(dRel, -yRel, z_on_path, &screen_pos)) { // yRel is negated as in update_leads
|
||||
// Basic drawing: Draw a small circle for the point
|
||||
painter.setBrush(QColor(255, 0, 0, 200)); // Cyan color for live tracks
|
||||
painter.drawEllipse(screen_pos, 10, 10); // Draw a small circle of radius 5
|
||||
|
||||
// Prepare text to display
|
||||
QString infoText = QString("ID: %1\nd: %2 m\ny: %3 m\ndV: %4 m/s\nyV: %5 m/s")
|
||||
.arg(point.getTrackId())
|
||||
.arg(dRel, 0, 'f', 2)
|
||||
.arg(yRel, 0, 'f', 2)
|
||||
.arg(vRel, 0, 'f', 2)
|
||||
.arg(yvRel, 0, 'f', 2);
|
||||
|
||||
// Draw text near the point
|
||||
// Adjust text position for better visibility (e.g., slightly offset from the point)
|
||||
QRectF textRect(screen_pos.x() + 10, screen_pos.y() - 20, 250, 250); // Adjust size as needed
|
||||
painter.drawText(textRect, Qt::AlignLeft, infoText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ModelRenderer::drawLead(QPainter &painter, const cereal::RadarState::LeadData::Reader &lead_data,
|
||||
const QPointF &vd, const QRect &surface_rect) {
|
||||
const float speedBuff = 10.;
|
||||
|
||||
@@ -15,6 +15,7 @@ private:
|
||||
bool mapToScreen(float in_x, float in_y, float in_z, QPointF *out);
|
||||
void mapLineToPolygon(const cereal::XYZTData::Reader &line, float y_off, float z_off,
|
||||
QPolygonF *pvd, int max_idx, bool allow_invert = true);
|
||||
void drawLiveTracks(QPainter &painter, const cereal::RadarData::Reader &live_tracks, const cereal::ModelDataV2::Reader &model_data, const QRect &surface_rect);
|
||||
void drawLead(QPainter &painter, const cereal::RadarState::LeadData::Reader &lead_data, const QPointF &vd, const QRect &surface_rect);
|
||||
void update_leads(const cereal::RadarState::Reader &radar_state, const cereal::XYZTData::Reader &line);
|
||||
void update_model(const cereal::ModelDataV2::Reader &model, const cereal::RadarState::LeadData::Reader &lead);
|
||||
|
||||
@@ -65,6 +65,7 @@ static void update_state(UIState *s) {
|
||||
void ui_update_params(UIState *s) {
|
||||
auto params = Params();
|
||||
s->scene.is_metric = params.getBool("IsMetric");
|
||||
s->scene.dp_ui_radar_tracks = params.getBool("dp_ui_radar_tracks");
|
||||
}
|
||||
|
||||
void UIState::updateStatus() {
|
||||
@@ -99,6 +100,7 @@ UIState::UIState(QObject *parent) : QObject(parent) {
|
||||
"modelV2", "controlsState", "liveCalibration", "radarState", "deviceState",
|
||||
"pandaStates", "carParams", "driverMonitoringState", "carState", "driverStateV2",
|
||||
"wideRoadCameraState", "managerState", "selfdriveState", "longitudinalPlan",
|
||||
"liveTracks",
|
||||
});
|
||||
prime_state = new PrimeState(this);
|
||||
language = QString::fromStdString(Params().get("LanguageSetting"));
|
||||
|
||||
@@ -60,6 +60,7 @@ typedef struct UIScene {
|
||||
float light_sensor = -1;
|
||||
bool started, ignition, is_metric;
|
||||
uint64_t started_frame;
|
||||
bool dp_ui_radar_tracks = false;
|
||||
} UIScene;
|
||||
|
||||
class UIState : public QObject {
|
||||
|
||||
@@ -40,6 +40,7 @@ def manager_init() -> None:
|
||||
("OpenpilotEnabledToggle", "1"),
|
||||
("LongitudinalPersonality", str(log.LongitudinalPersonality.standard)),
|
||||
("DisableLogging", "0"),
|
||||
("dp_ui_radar_tracks", "0"),
|
||||
]
|
||||
|
||||
if params.get_bool("RecordFrontLock"):
|
||||
|
||||
Reference in New Issue
Block a user