nav: simplify segment transition (#21383)

pull/21385/head
Willem Melching 4 years ago committed by GitHub
parent cdfba105ed
commit f32ca73724
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      selfdrive/ui/qt/maps/map.cc
  2. 1
      selfdrive/ui/qt/maps/map.h

@ -14,6 +14,8 @@
const int PAN_TIMEOUT = 100; const int PAN_TIMEOUT = 100;
const bool DRAW_MODEL_PATH = false; const bool DRAW_MODEL_PATH = false;
const qreal REROUTE_DISTANCE = 25; const qreal REROUTE_DISTANCE = 25;
const float MANEUVER_TRANSITION_THRESHOLD = 10;
const float MAX_ZOOM = 17; const float MAX_ZOOM = 17;
const float MIN_ZOOM = 14; const float MIN_ZOOM = 14;
const float MAX_PITCH = 50; const float MAX_PITCH = 50;
@ -179,8 +181,8 @@ void MapWindow::timerUpdate() {
auto attrs = cur_maneuver.extendedAttributes(); auto attrs = cur_maneuver.extendedAttributes();
if (cur_maneuver.isValid() && attrs.contains("mapbox.banner_instructions")) { if (cur_maneuver.isValid() && attrs.contains("mapbox.banner_instructions")) {
float along_geometry = distance_along_geometry(segment.path(), to_QGeoCoordinate(*last_position)); float along_geometry = distance_along_geometry(segment.path(), to_QGeoCoordinate(*last_position));
float distance = std::max(0.0f, float(segment.distance()) - along_geometry); float distance_to_maneuver = segment.distance() - along_geometry;
emit distanceChanged(distance); emit distanceChanged(std::max(0.0f, distance_to_maneuver));
m_map->setPitch(MAX_PITCH); // TODO: smooth pitching based on maneuver distance m_map->setPitch(MAX_PITCH); // TODO: smooth pitching based on maneuver distance
@ -188,25 +190,17 @@ void MapWindow::timerUpdate() {
if (banner.size()) { if (banner.size()) {
auto banner_0 = banner[0].toMap(); auto banner_0 = banner[0].toMap();
float show_at = banner_0["distance_along_geometry"].toDouble(); float show_at = banner_0["distance_along_geometry"].toDouble();
emit instructionsChanged(banner_0, distance < show_at); emit instructionsChanged(banner_0, distance_to_maneuver < show_at);
}
} }
// Handle transition to next route segment // Transition to next route segment
if (distance_to_maneuver < -MANEUVER_TRANSITION_THRESHOLD) {
auto next_segment = segment.nextRouteSegment(); auto next_segment = segment.nextRouteSegment();
if (next_segment.isValid()) { if (next_segment.isValid()) {
auto next_maneuver = next_segment.maneuver();
if (next_maneuver.isValid()) {
float next_maneuver_distance = next_maneuver.position().distanceTo(to_QGeoCoordinate(*last_position));
// Switch to next route segment
if (next_maneuver_distance < REROUTE_DISTANCE && next_maneuver_distance > last_maneuver_distance) {
segment = next_segment; segment = next_segment;
recompute_backoff = std::max(0, recompute_backoff - 1); recompute_backoff = std::max(0, recompute_backoff - 1);
recompute_countdown = 0; recompute_countdown = 0;
}
last_maneuver_distance = next_maneuver_distance;
}
} else { } else {
// Destination reached // Destination reached
Params().remove("NavDestination"); Params().remove("NavDestination");
@ -218,6 +212,8 @@ void MapWindow::timerUpdate() {
} }
} }
} }
}
}
} else { } else {
map_instructions->showError("Waiting for GPS"); map_instructions->showError("Waiting for GPS");
} }

@ -117,7 +117,6 @@ private:
MapETA* map_eta; MapETA* map_eta;
QMapbox::Coordinate nav_destination; QMapbox::Coordinate nav_destination;
double last_maneuver_distance = 1000;
// Route recompute // Route recompute
QTimer* recompute_timer; QTimer* recompute_timer;

Loading…
Cancel
Save