mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-06-16 13:06:38 +08:00
use ParamWatcher
This commit is contained in:
@@ -8,11 +8,6 @@
|
||||
#include "common/swaglog.h"
|
||||
#include "selfdrive/ui/qt/util.h"
|
||||
|
||||
void AnnotatedCameraWidget::updateParams() {
|
||||
visual_style_ = QString::fromStdString(Params().get("VisualStyle")).toInt();
|
||||
visual_wide_cam_ = QString::fromStdString(Params().get("VisualWideCam")).toInt();
|
||||
}
|
||||
|
||||
// Window that shows camera view and variety of info drawn on top
|
||||
AnnotatedCameraWidget::AnnotatedCameraWidget(VisionStreamType type, QWidget *parent)
|
||||
: fps_filter(UI_FREQ, 3, 1. / UI_FREQ), CameraWidget("camerad", type, parent) {
|
||||
@@ -31,7 +26,7 @@ void AnnotatedCameraWidget::updateState(const UIState &s) {
|
||||
experimental_btn->updateState(s);
|
||||
dmon.updateState(s);
|
||||
|
||||
if (visual_style_ == 0) {
|
||||
if (s.scene.visual_style == 0) {
|
||||
setBackgroundColor(bg_colors[STATUS_DISENGAGED]);
|
||||
} else {
|
||||
setBackgroundColor(QColor(0, 0, 0));
|
||||
@@ -46,7 +41,8 @@ void AnnotatedCameraWidget::initializeGL() {
|
||||
qInfo() << "OpenGL language version:" << QString((const char*)glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||
|
||||
prev_draw_t = millis_since_boot();
|
||||
if (visual_style_ == 0) {
|
||||
auto *s = uiState();
|
||||
if (s->scene.visual_style == 0) {
|
||||
setBackgroundColor(bg_colors[STATUS_DISENGAGED]);
|
||||
} else {
|
||||
setBackgroundColor(QColor(0, 0, 0));
|
||||
@@ -103,14 +99,6 @@ mat4 AnnotatedCameraWidget::calcFrameMatrix() {
|
||||
}
|
||||
|
||||
void AnnotatedCameraWidget::paintGL() {
|
||||
// refresh VisualWideCam param ~once per second
|
||||
static double last_params_t = 0.0;
|
||||
double params_now = millis_since_boot();
|
||||
if (params_now - last_params_t > 1000.0) {
|
||||
updateParams();
|
||||
last_params_t = params_now;
|
||||
}
|
||||
|
||||
UIState *s = uiState();
|
||||
SubMaster &sm = *(s->sm);
|
||||
const double start_draw_t = millis_since_boot();
|
||||
@@ -142,7 +130,7 @@ void AnnotatedCameraWidget::paintGL() {
|
||||
wide_cam_requested = false;
|
||||
}
|
||||
wide_cam_requested = wide_cam_requested && sm["selfdriveState"].getSelfdriveState().getExperimentalMode();
|
||||
wide_cam_requested = wide_cam_requested || (visual_wide_cam_ != 0);
|
||||
wide_cam_requested = wide_cam_requested || (s->scene.visual_wide_cam != 0);
|
||||
}
|
||||
CameraWidget::setStreamType(wide_cam_requested ? VISION_STREAM_WIDE_ROAD : VISION_STREAM_ROAD);
|
||||
CameraWidget::setFrameId(sm["modelV2"].getModelV2().getFrameId());
|
||||
|
||||
@@ -45,8 +45,4 @@ protected:
|
||||
|
||||
double prev_draw_t = 0;
|
||||
FirstOrderFilter fps_filter;
|
||||
|
||||
void updateParams();
|
||||
int visual_style_ = 0;
|
||||
int visual_wide_cam_ = 0;
|
||||
};
|
||||
|
||||
@@ -2,15 +2,6 @@
|
||||
#include <QPainterPath>
|
||||
#include <algorithm>
|
||||
|
||||
void ModelRenderer::updateParams() {
|
||||
visual_style_ = QString::fromStdString(Params().get("VisualStyle")).toInt();
|
||||
visual_blend_ = QString::fromStdString(Params().get("VisualStyleBlend")).toInt();
|
||||
visual_blend_threshold_ = QString::fromStdString(Params().get("VisualStyleBlendThreshold")).toFloat();
|
||||
visual_radar_tracks_ = QString::fromStdString(Params().get("VisualRadarTracks")).toInt();
|
||||
visual_radar_tracks_delay_ = QString::fromStdString(Params().get("VisualRadarTracksDelay")).toFloat();
|
||||
visual_fps_ = QString::fromStdString(Params().get("VisualFPS")).toInt();
|
||||
}
|
||||
|
||||
void ModelRenderer::drawRadarPoint(QPainter &painter, const QPointF &pos, float v_rel, float radius) {
|
||||
painter.setBrush(QColor(255, 255, 255, 200));
|
||||
painter.setPen(Qt::NoPen);
|
||||
@@ -18,13 +9,6 @@ void ModelRenderer::drawRadarPoint(QPainter &painter, const QPointF &pos, float
|
||||
}
|
||||
|
||||
void ModelRenderer::draw(QPainter &painter, const QRect &surface_rect) {
|
||||
static double last_params_t = 0.0;
|
||||
double params_now = millis_since_boot();
|
||||
if (params_now - last_params_t > 1000.0) {
|
||||
updateParams();
|
||||
last_params_t = params_now;
|
||||
}
|
||||
|
||||
static double last_draw_t = millis_since_boot();
|
||||
static float avg_frame_time = 50.0f;
|
||||
static float avg_fps = 20.0f;
|
||||
@@ -74,12 +58,12 @@ void ModelRenderer::draw(QPainter &painter, const QRect &surface_rect) {
|
||||
}
|
||||
}
|
||||
|
||||
if (visual_radar_tracks_) {
|
||||
if (s->scene.visual_radar_tracks) {
|
||||
if (sm.alive("liveTracks") && sm.rcv_frame("liveTracks") >= s->scene.started_frame) {
|
||||
const auto &tracks = sm["liveTracks"].getLiveTracks().getPoints();
|
||||
for (const auto &track : tracks) {
|
||||
if (!std::isfinite(track.getDRel()) || !std::isfinite(track.getYRel())) continue;
|
||||
float t_lag = visual_radar_tracks_delay_;
|
||||
float t_lag = s->scene.visual_radar_tracks_delay;
|
||||
float d_pred = track.getDRel();
|
||||
float y_pred = track.getYRel();
|
||||
if (t_lag > 0.0f) {
|
||||
@@ -95,7 +79,7 @@ void ModelRenderer::draw(QPainter &painter, const QRect &surface_rect) {
|
||||
|
||||
drawLeadStatus(painter, surface_rect.height(), surface_rect.width());
|
||||
|
||||
if (visual_fps_) {
|
||||
if (s->scene.visual_fps) {
|
||||
static double last_overlay_update_t = 0.0;
|
||||
static QString cached_fps_line;
|
||||
static QString cached_frame_line;
|
||||
@@ -138,9 +122,10 @@ void ModelRenderer::update_leads(const cereal::RadarState::Reader &radar_state,
|
||||
}
|
||||
|
||||
void ModelRenderer::update_model(const cereal::ModelDataV2::Reader &model, const cereal::RadarState::LeadData::Reader &lead) {
|
||||
auto *s = uiState();
|
||||
const auto &model_position = model.getPosition();
|
||||
float max_distance;
|
||||
if (visual_style_ == 0) {
|
||||
if (s->scene.visual_style == 0) {
|
||||
max_distance = std::clamp(*(model_position.getX().end() - 1), MIN_DRAW_DISTANCE, MAX_DRAW_DISTANCE);
|
||||
} else {
|
||||
max_distance = std::clamp(*(model_position.getX().end() - 1), 0.0f, 300.0f);
|
||||
@@ -152,7 +137,7 @@ void ModelRenderer::update_model(const cereal::ModelDataV2::Reader &model, const
|
||||
int max_idx = get_path_length_idx(lane_lines[0], max_distance);
|
||||
for (int i = 0; i < std::size(lane_line_vertices); i++) {
|
||||
lane_line_probs[i] = line_probs[i];
|
||||
if (visual_style_ == 2) {
|
||||
if (s->scene.visual_style == 2) {
|
||||
mapLineToPolygon(lane_lines[i], 0.075 * lane_line_probs[i], 0, &lane_line_vertices[i], max_idx);
|
||||
} else {
|
||||
mapLineToPolygon(lane_lines[i], 0.025 * lane_line_probs[i], 0, &lane_line_vertices[i], max_idx);
|
||||
@@ -164,7 +149,7 @@ void ModelRenderer::update_model(const cereal::ModelDataV2::Reader &model, const
|
||||
const auto &edge_stds = model.getRoadEdgeStds();
|
||||
for (int i = 0; i < std::size(road_edge_vertices); i++) {
|
||||
road_edge_stds[i] = edge_stds[i];
|
||||
if (visual_style_ == 2) {
|
||||
if (s->scene.visual_style == 2) {
|
||||
mapLineToPolygon(road_edges[i], 0.1, 0, &road_edge_vertices[i], max_idx);
|
||||
} else {
|
||||
mapLineToPolygon(road_edges[i], 0.025, 0, &road_edge_vertices[i], max_idx);
|
||||
@@ -181,7 +166,8 @@ void ModelRenderer::update_model(const cereal::ModelDataV2::Reader &model, const
|
||||
}
|
||||
|
||||
void ModelRenderer::drawLaneLines(QPainter &painter) {
|
||||
if (visual_style_ == 2) {
|
||||
auto *s = uiState();
|
||||
if (s->scene.visual_style == 2) {
|
||||
QRectF r = clip_region;
|
||||
|
||||
// --- Find horizon from road edges ---
|
||||
@@ -553,6 +539,7 @@ void ModelRenderer::drawLeadStatusAtPosition(QPainter &painter,
|
||||
|
||||
void ModelRenderer::drawLead(QPainter &painter, const cereal::RadarState::LeadData::Reader &lead_data,
|
||||
const QPointF &vd, const QRect &surface_rect) {
|
||||
auto *s = uiState();
|
||||
const float speedBuff = 10.;
|
||||
const float leadBuff = 40.;
|
||||
const float d_rel = lead_data.getDRel();
|
||||
@@ -575,7 +562,7 @@ void ModelRenderer::drawLead(QPainter &painter, const cereal::RadarState::LeadDa
|
||||
float g_yo = sz / 10;
|
||||
|
||||
QPointF glow[] = {{x + (sz * 1.35) + g_xo, y + sz + g_yo}, {x, y - g_yo}, {x - (sz * 1.35) - g_xo, y + sz + g_yo}};
|
||||
if (visual_style_ == 2) {
|
||||
if (s->scene.visual_style == 2) {
|
||||
painter.setBrush(QColor(0xE6, 0xE6, 0xE6, 255));
|
||||
} else {
|
||||
painter.setBrush(QColor(218, 202, 37, 255));
|
||||
@@ -584,7 +571,7 @@ void ModelRenderer::drawLead(QPainter &painter, const cereal::RadarState::LeadDa
|
||||
|
||||
// chevron
|
||||
QPointF chevron[] = {{x + (sz * 1.25), y + sz}, {x, y}, {x - (sz * 1.25), y + sz}};
|
||||
if (visual_style_ == 2) {
|
||||
if (s->scene.visual_style == 2) {
|
||||
painter.setBrush(QColor(0, 0, 0, fillAlpha));
|
||||
} else {
|
||||
painter.setBrush(QColor(201, 34, 49, fillAlpha));
|
||||
@@ -631,21 +618,21 @@ bool ModelRenderer::mapToScreen(float in_x, float in_y, float in_z, QPointF *out
|
||||
);
|
||||
|
||||
// Force top-down if VisualStyle == 3
|
||||
if (visual_style_ == 3) {
|
||||
if (s->scene.visual_style == 3) {
|
||||
*out = topdown_view;
|
||||
return clip_region.contains(*out);
|
||||
}
|
||||
|
||||
// Blending mode
|
||||
if (visual_blend_ == 1 && visual_style_ != 0) {
|
||||
if (s->scene.visual_blend == 1 && s->scene.visual_style != 0) {
|
||||
static float blend = 0.0f; // 0 = 3D, 1 = 2D
|
||||
static float target_blend = 0.0f; // where we want to go
|
||||
static double last_t = millis_since_boot();
|
||||
|
||||
// Hysteresis logic
|
||||
if (target_blend < 0.5f && blend_speed_mph > visual_blend_threshold_) {
|
||||
if (target_blend < 0.5f && blend_speed_mph > s->scene.visual_blend_threshold) {
|
||||
target_blend = 1.0f; // switch to 2D
|
||||
} else if (target_blend > 0.5f && blend_speed_mph < (visual_blend_threshold_ - 5)) {
|
||||
} else if (target_blend > 0.5f && blend_speed_mph < (s->scene.visual_blend_threshold - 5)) {
|
||||
target_blend = 0.0f; // switch back to 3D
|
||||
}
|
||||
|
||||
|
||||
@@ -71,12 +71,4 @@ protected:
|
||||
QColor lead_status_color;
|
||||
|
||||
void drawRadarPoint(QPainter &painter, const QPointF &pos, float v_rel, float radius = 5.0f);
|
||||
|
||||
void updateParams();
|
||||
int visual_style_ = 0;
|
||||
int visual_blend_ = 0;
|
||||
float visual_blend_threshold_ = 20.0f;
|
||||
int visual_radar_tracks_ = 0;
|
||||
int visual_radar_tracks_delay_ = 0;
|
||||
int visual_fps_ = 0;
|
||||
};
|
||||
|
||||
@@ -62,10 +62,6 @@ const char frame_fragment_shader[] =
|
||||
|
||||
} // namespace
|
||||
|
||||
void CameraWidget::updateParams() {
|
||||
visual_style_ = QString::fromStdString(Params().get("VisualStyle")).toInt();
|
||||
}
|
||||
|
||||
CameraWidget::CameraWidget(std::string stream_name, VisionStreamType type, QWidget* parent) :
|
||||
stream_name(stream_name), active_stream_type(type), requested_stream_type(type), QOpenGLWidget(parent) {
|
||||
setAttribute(Qt::WA_OpaquePaintEvent);
|
||||
@@ -200,13 +196,7 @@ mat4 CameraWidget::calcFrameMatrix() {
|
||||
}
|
||||
|
||||
void CameraWidget::paintGL() {
|
||||
static double last_params_t = 0.0;
|
||||
double now = millis_since_boot();
|
||||
if (now - last_params_t > 1000.0) {
|
||||
updateParams();
|
||||
last_params_t = now;
|
||||
}
|
||||
|
||||
auto *s = uiState();
|
||||
glClearColor(bg.redF(), bg.greenF(), bg.blueF(), bg.alphaF());
|
||||
glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||
|
||||
@@ -259,7 +249,7 @@ void CameraWidget::paintGL() {
|
||||
|
||||
glUniformMatrix4fv(program->uniformLocation("uTransform"), 1, GL_TRUE, frame_mat.v);
|
||||
glEnableVertexAttribArray(0);
|
||||
if (visual_style_ == 0) {
|
||||
if (s->scene.visual_style == 0) {
|
||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, (const void *)0);
|
||||
}
|
||||
glDisableVertexAttribArray(0);
|
||||
|
||||
@@ -60,9 +60,6 @@ protected:
|
||||
void vipcThread();
|
||||
void clearFrames();
|
||||
|
||||
void updateParams();
|
||||
int visual_style_ = 0;
|
||||
|
||||
int glWidth();
|
||||
int glHeight();
|
||||
|
||||
|
||||
@@ -35,6 +35,13 @@ UIStateSP::UIStateSP(QObject *parent) : UIState(parent) {
|
||||
});
|
||||
param_watcher->addParam("DevUIInfo");
|
||||
param_watcher->addParam("StandstillTimer");
|
||||
param_watcher->addParam("VisualStyle");
|
||||
param_watcher->addParam("VisualStyleBlend");
|
||||
param_watcher->addParam("VisualStyleBlendThreshold");
|
||||
param_watcher->addParam("VisualRadarTracks");
|
||||
param_watcher->addParam("VisualRadarTracksDelay");
|
||||
param_watcher->addParam("VisualWideCam");
|
||||
param_watcher->addParam("VisualFPS");
|
||||
}
|
||||
|
||||
// This method overrides completely the update method from the parent class intentionally.
|
||||
@@ -55,6 +62,13 @@ void ui_update_params_sp(UIStateSP *s) {
|
||||
s->scene.standstill_timer = params.getBool("StandstillTimer");
|
||||
s->scene.speed_limit_mode = std::atoi(params.get("SpeedLimitMode").c_str());
|
||||
s->scene.road_name = params.getBool("RoadNameToggle");
|
||||
s->scene.visual_style = QString::fromStdString(params.get("VisualStyle")).toInt();
|
||||
s->scene.visual_blend = QString::fromStdString(params.get("VisualStyleBlend")).toInt();
|
||||
s->scene.visual_blend_threshold = QString::fromStdString(params.get("VisualStyleBlendThreshold")).toInt();
|
||||
s->scene.visual_radar_tracks = QString::fromStdString(params.get("VisualRadarTracks")).toInt();
|
||||
s->scene.visual_radar_tracks_delay = QString::fromStdString(params.get("VisualRadarTracksDelay")).toFloat();
|
||||
s->scene.visual_wide_cam = QString::fromStdString(params.get("VisualWideCam")).toInt();
|
||||
s->scene.visual_fps = QString::fromStdString(params.get("VisualFPS")).toInt();
|
||||
}
|
||||
|
||||
DeviceSP::DeviceSP(QObject *parent) : Device(parent) {
|
||||
|
||||
@@ -12,4 +12,11 @@ typedef struct UISceneSP : UIScene {
|
||||
bool standstill_timer = false;
|
||||
int speed_limit_mode = 0;
|
||||
bool road_name = false;
|
||||
int visual_style = 0;
|
||||
int visual_blend = 0;
|
||||
int visual_blend_threshold = 20.0;
|
||||
int visual_radar_tracks = 0;
|
||||
float visual_radar_tracks_delay = 0;
|
||||
int visual_wide_cam = 0;
|
||||
int visual_fps = 0;
|
||||
} UISceneSP;
|
||||
|
||||
Reference in New Issue
Block a user