mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-02 12:02:09 +08:00
UI: draw map with uiUpdate signal (#24632)
* draw map with same uiUpdate signal as onroad window * fix * fix * fix * test * test * clean up * clean up * clean up * draw instantly when dragging * self explanatory * remove line * fix spacing * see if we call ui'c sm->update before mapwindow * Revert "see if we call ui'c sm->update before mapwindow" This reverts commit e5dcd70013750b871894c276e4d15d55b0c92e97. * sort includes old-commit-hash: fb4b4773a58a62783dd48e6058be5a0da6bb1fab
This commit is contained in:
+16
-25
@@ -3,14 +3,14 @@
|
||||
#include <cmath>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QPainterPath>
|
||||
#include <QFileInfo>
|
||||
#include <QPainterPath>
|
||||
|
||||
#include "common/swaglog.h"
|
||||
#include "selfdrive/ui/ui.h"
|
||||
#include "selfdrive/ui/qt/util.h"
|
||||
#include "selfdrive/ui/qt/maps/map_helpers.h"
|
||||
#include "selfdrive/ui/qt/request_repeater.h"
|
||||
#include "selfdrive/ui/qt/util.h"
|
||||
#include "selfdrive/ui/ui.h"
|
||||
|
||||
|
||||
const int PAN_TIMEOUT = 100;
|
||||
@@ -24,16 +24,8 @@ const float MAP_SCALE = 2;
|
||||
|
||||
const QString ICON_SUFFIX = ".png";
|
||||
|
||||
MapWindow::MapWindow(const QMapboxGLSettings &settings) :
|
||||
m_settings(settings), velocity_filter(0, 10, 0.05) {
|
||||
sm = new SubMaster({"liveLocationKalman", "navInstruction", "navRoute"});
|
||||
|
||||
// Connect now, so any navRoutes sent while the map is initializing are not dropped
|
||||
sm->update(0);
|
||||
|
||||
timer = new QTimer(this);
|
||||
QObject::connect(timer, SIGNAL(timeout()), this, SLOT(timerUpdate()));
|
||||
timer->start(50);
|
||||
MapWindow::MapWindow(const QMapboxGLSettings &settings) : m_settings(settings), velocity_filter(0, 10, 0.05) {
|
||||
QObject::connect(uiState(), &UIState::uiUpdate, this, &MapWindow::updateState);
|
||||
|
||||
// Instructions
|
||||
map_instructions = new MapInstructions(this);
|
||||
@@ -105,16 +97,15 @@ void MapWindow::initLayers() {
|
||||
}
|
||||
}
|
||||
|
||||
void MapWindow::timerUpdate() {
|
||||
void MapWindow::updateState(const UIState &s) {
|
||||
if (!uiState()->scene.started) {
|
||||
return;
|
||||
}
|
||||
|
||||
const SubMaster &sm = *(s.sm);
|
||||
update();
|
||||
|
||||
sm->update(0);
|
||||
if (sm->updated("liveLocationKalman")) {
|
||||
auto location = (*sm)["liveLocationKalman"].getLiveLocationKalman();
|
||||
if (sm.updated("liveLocationKalman")) {
|
||||
auto location = sm["liveLocationKalman"].getLiveLocationKalman();
|
||||
auto pos = location.getPositionGeodetic();
|
||||
auto orientation = location.getCalibratedOrientationNED();
|
||||
auto velocity = location.getVelocityCalibrated();
|
||||
@@ -129,7 +120,7 @@ void MapWindow::timerUpdate() {
|
||||
}
|
||||
}
|
||||
|
||||
if (sm->updated("navRoute") && (*sm)["navRoute"].getNavRoute().getCoordinates().size()) {
|
||||
if (sm.updated("navRoute") && sm["navRoute"].getNavRoute().getCoordinates().size()) {
|
||||
qWarning() << "Got new navRoute from navd. Opening map:" << allow_open;
|
||||
|
||||
// Only open the map on setting destination the first time
|
||||
@@ -178,9 +169,9 @@ void MapWindow::timerUpdate() {
|
||||
zoom_counter--;
|
||||
}
|
||||
|
||||
if (sm->updated("navInstruction")) {
|
||||
if (sm->valid("navInstruction")) {
|
||||
auto i = (*sm)["navInstruction"].getNavInstruction();
|
||||
if (sm.updated("navInstruction")) {
|
||||
if (sm.valid("navInstruction")) {
|
||||
auto i = sm["navInstruction"].getNavInstruction();
|
||||
emit ETAChanged(i.getTimeRemaining(), i.getTimeRemainingTypical(), i.getDistanceRemaining());
|
||||
|
||||
if (localizer_valid) {
|
||||
@@ -194,9 +185,9 @@ void MapWindow::timerUpdate() {
|
||||
}
|
||||
}
|
||||
|
||||
if (sm->rcv_frame("navRoute") != route_rcv_frame) {
|
||||
if (sm.rcv_frame("navRoute") != route_rcv_frame) {
|
||||
qWarning() << "Updating navLayer with new route";
|
||||
auto route = (*sm)["navRoute"].getNavRoute();
|
||||
auto route = sm["navRoute"].getNavRoute();
|
||||
auto route_points = capnp_coordinate_list_to_collection(route.getCoordinates());
|
||||
QMapbox::Feature feature(QMapbox::Feature::LineStringType, route_points, {}, {});
|
||||
QVariantMap navSource;
|
||||
@@ -205,7 +196,7 @@ void MapWindow::timerUpdate() {
|
||||
m_map->updateSource("navSource", navSource);
|
||||
m_map->setLayoutProperty("navLayer", "visibility", "visible");
|
||||
|
||||
route_rcv_frame = sm->rcv_frame("navRoute");
|
||||
route_rcv_frame = sm.rcv_frame("navRoute");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,22 +5,22 @@
|
||||
#include <QGeoCoordinate>
|
||||
#include <QGestureEvent>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QMap>
|
||||
#include <QMapboxGL>
|
||||
#include <QMouseEvent>
|
||||
#include <QOpenGLWidget>
|
||||
#include <QPixmap>
|
||||
#include <QScopedPointer>
|
||||
#include <QString>
|
||||
#include <QtGlobal>
|
||||
#include <QTimer>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWheelEvent>
|
||||
#include <QMap>
|
||||
#include <QPixmap>
|
||||
#include <QtGlobal>
|
||||
|
||||
#include "cereal/messaging/messaging.h"
|
||||
#include "common/params.h"
|
||||
#include "common/util.h"
|
||||
#include "cereal/messaging/messaging.h"
|
||||
#include "selfdrive/ui/ui.h"
|
||||
|
||||
class MapInstructions : public QWidget {
|
||||
Q_OBJECT
|
||||
@@ -91,8 +91,6 @@ private:
|
||||
void pinchTriggered(QPinchGesture *gesture);
|
||||
|
||||
bool m_sourceAdded = false;
|
||||
SubMaster *sm;
|
||||
QTimer* timer;
|
||||
|
||||
bool loaded_once = false;
|
||||
bool allow_open = true;
|
||||
@@ -115,7 +113,7 @@ private:
|
||||
uint64_t route_rcv_frame = 0;
|
||||
|
||||
private slots:
|
||||
void timerUpdate();
|
||||
void updateState(const UIState &s);
|
||||
|
||||
public slots:
|
||||
void offroadTransition(bool offroad);
|
||||
|
||||
+1
-1
@@ -233,7 +233,7 @@ UIState::UIState(QObject *parent) : QObject(parent) {
|
||||
sm = std::make_unique<SubMaster, const std::initializer_list<const char *>>({
|
||||
"modelV2", "controlsState", "liveCalibration", "radarState", "deviceState", "roadCameraState",
|
||||
"pandaStates", "carParams", "driverMonitoringState", "sensorEvents", "carState", "liveLocationKalman",
|
||||
"wideRoadCameraState", "managerState",
|
||||
"wideRoadCameraState", "managerState", "navInstruction", "navRoute",
|
||||
});
|
||||
|
||||
Params params;
|
||||
|
||||
Reference in New Issue
Block a user