nav: cleanup errors and wait for map to be loaded (#21381)

* Cleanup errors

* prevent flicker
old-commit-hash: 7e6a9ce9a5
commatwo_master
Willem Melching 4 years ago committed by GitHub
parent 1966c6d908
commit 16143bef1b
  1. 62
      selfdrive/ui/qt/maps/map.cc
  2. 7
      selfdrive/ui/qt/maps/map.h

@ -37,13 +37,13 @@ MapWindow::MapWindow(const QMapboxGLSettings &settings) : m_settings(settings) {
// Instructions // Instructions
map_instructions = new MapInstructions(this); map_instructions = new MapInstructions(this);
connect(this, &MapWindow::instructionsChanged, map_instructions, &MapInstructions::updateInstructions); QObject::connect(this, &MapWindow::instructionsChanged, map_instructions, &MapInstructions::updateInstructions);
connect(this, &MapWindow::distanceChanged, map_instructions, &MapInstructions::updateDistance); QObject::connect(this, &MapWindow::distanceChanged, map_instructions, &MapInstructions::updateDistance);
connect(this, &MapWindow::GPSValidChanged, map_instructions, &MapInstructions::updateGPSValid);
map_instructions->setFixedWidth(width()); map_instructions->setFixedWidth(width());
map_instructions->setVisible(false);
map_eta = new MapETA(this); map_eta = new MapETA(this);
connect(this, &MapWindow::ETAChanged, map_eta, &MapETA::updateETA); QObject::connect(this, &MapWindow::ETAChanged, map_eta, &MapETA::updateETA);
const int h = 120; const int h = 120;
map_eta->setFixedHeight(h); map_eta->setFixedHeight(h);
@ -60,7 +60,7 @@ MapWindow::MapWindow(const QMapboxGLSettings &settings) : m_settings(settings) {
qDebug() << geoservice_provider->errorString(); qDebug() << geoservice_provider->errorString();
assert(routing_manager); assert(routing_manager);
} }
connect(routing_manager, SIGNAL(finished(QGeoRouteReply*)), this, SLOT(routeCalculated(QGeoRouteReply*))); QObject::connect(routing_manager, &QGeoRoutingManager::finished, this, &MapWindow::routeCalculated);
auto last_gps_position = coordinate_from_param("LastGPSPosition"); auto last_gps_position = coordinate_from_param("LastGPSPosition");
if (last_gps_position) { if (last_gps_position) {
@ -115,6 +115,11 @@ void MapWindow::initLayers() {
} }
void MapWindow::timerUpdate() { void MapWindow::timerUpdate() {
if (!loaded_once) {
map_instructions->showError("Map loading");
return;
}
initLayers(); initLayers();
sm->update(0); sm->update(0);
@ -123,7 +128,6 @@ void MapWindow::timerUpdate() {
gps_ok = location.getGpsOK(); gps_ok = location.getGpsOK();
bool localizer_valid = location.getStatus() == cereal::LiveLocationKalman::Status::VALID; bool localizer_valid = location.getStatus() == cereal::LiveLocationKalman::Status::VALID;
emit GPSValidChanged(localizer_valid);
if (localizer_valid) { if (localizer_valid) {
auto pos = location.getPositionGeodetic(); auto pos = location.getPositionGeodetic();
@ -213,15 +217,13 @@ void MapWindow::timerUpdate() {
clearRoute(); clearRoute();
} }
} }
} else {
map_instructions->setVisible(false);
} }
} else {
map_instructions->showError("Waiting for GPS");
} }
} }
update(); update();
} }
void MapWindow::resizeGL(int w, int h) { void MapWindow::resizeGL(int w, int h) {
@ -242,6 +244,12 @@ void MapWindow::initializeGL() {
m_map->setStyleUrl("mapbox://styles/commadotai/ckq7zp8ts1k0o17p8m6rv6cet"); m_map->setStyleUrl("mapbox://styles/commadotai/ckq7zp8ts1k0o17p8m6rv6cet");
connect(m_map.data(), SIGNAL(needsRendering()), this, SLOT(update())); connect(m_map.data(), SIGNAL(needsRendering()), this, SLOT(update()));
QObject::connect(m_map.data(), &QMapboxGL::mapChanged, [=](QMapboxGL::MapChange change) {
if (change == QMapboxGL::MapChange::MapChangeDidFinishLoadingMap) {
loaded_once = true;
}
});
timer->start(100); timer->start(100);
} }
@ -361,7 +369,7 @@ void MapWindow::clearRoute() {
m_map->setPitch(MIN_PITCH); m_map->setPitch(MIN_PITCH);
} }
map_instructions->setVisible(false); map_instructions->hideIfNoError();
map_eta->setVisible(false); map_eta->setVisible(false);
} }
@ -528,20 +536,19 @@ void MapInstructions::updateDistance(float d) {
distance->setText(distance_str); distance->setText(distance_str);
} }
void MapInstructions::updateGPSValid(bool valid) { void MapInstructions::showError(QString error) {
if (!valid) { primary->setText("");
primary->setText(""); distance->setText(error);
distance->setText("Waiting for GPS position"); distance->setAlignment(Qt::AlignCenter);
distance->setAlignment(Qt::AlignCenter);
secondary->setVisible(false); secondary->setVisible(false);
icon_01->setVisible(false); icon_01->setVisible(false);
last_banner = {}; last_banner = {};
error = true;
setVisible(true); setVisible(true);
adjustSize(); adjustSize();
}
} }
void MapInstructions::updateInstructions(QMap<QString, QVariant> banner, bool full) { void MapInstructions::updateInstructions(QMap<QString, QVariant> banner, bool full) {
@ -550,7 +557,7 @@ void MapInstructions::updateInstructions(QMap<QString, QVariant> banner, bool fu
// the size can only be changed afterwards // the size can only be changed afterwards
adjustSize(); adjustSize();
// Word wrap widgets neet fixed width // Word wrap widgets need fixed width
primary->setFixedWidth(width() - 250); primary->setFixedWidth(width() - 250);
secondary->setFixedWidth(width() - 250); secondary->setFixedWidth(width() - 250);
@ -637,11 +644,18 @@ void MapInstructions::updateInstructions(QMap<QString, QVariant> banner, bool fu
secondary->setText(secondary_str); secondary->setText(secondary_str);
last_banner = banner; last_banner = banner;
error = false;
setVisible(true); show();
adjustSize(); adjustSize();
} }
void MapInstructions::hideIfNoError() {
if (!error) {
hide();
}
}
MapETA::MapETA(QWidget * parent) : QWidget(parent) { MapETA::MapETA(QWidget * parent) : QWidget(parent) {
QHBoxLayout *main_layout = new QHBoxLayout(this); QHBoxLayout *main_layout = new QHBoxLayout(this);
main_layout->setContentsMargins(40, 25, 40, 25); main_layout->setContentsMargins(40, 25, 40, 25);

@ -36,14 +36,16 @@ private:
QLabel *icon_01; QLabel *icon_01;
QHBoxLayout *lane_layout; QHBoxLayout *lane_layout;
QMap<QString, QVariant> last_banner; QMap<QString, QVariant> last_banner;
bool error = false;
public: public:
MapInstructions(QWidget * parent=nullptr); MapInstructions(QWidget * parent=nullptr);
void showError(QString error);
void hideIfNoError();
public slots: public slots:
void updateDistance(float d); void updateDistance(float d);
void updateInstructions(QMap<QString, QVariant> banner, bool full); void updateInstructions(QMap<QString, QVariant> banner, bool full);
void updateGPSValid(bool valid);
}; };
class MapETA : public QWidget { class MapETA : public QWidget {
@ -93,6 +95,8 @@ private:
SubMaster *sm; SubMaster *sm;
QTimer* timer; QTimer* timer;
bool loaded_once = false;
// Panning // Panning
QPointF m_lastPos; QPointF m_lastPos;
int pan_counter = 0; int pan_counter = 0;
@ -136,6 +140,5 @@ signals:
void distanceChanged(float distance); void distanceChanged(float distance);
void instructionsChanged(QMap<QString, QVariant> banner, bool full); void instructionsChanged(QMap<QString, QVariant> banner, bool full);
void ETAChanged(float seconds, float seconds_typical, float distance); void ETAChanged(float seconds, float seconds_typical, float distance);
void GPSValidChanged(bool valid);
}; };

Loading…
Cancel
Save