From 3b539476ae59c3d24d6ae95f62a96e14430a997d Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Thu, 25 Jul 2019 15:09:18 +0300 Subject: [PATCH] [routing] Using PositionAccumulator to calculate better an end user direction. --- map/routing_manager.cpp | 3 +++ routing/routing_session.cpp | 10 +++------- routing/routing_session.hpp | 13 ++++++++----- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/map/routing_manager.cpp b/map/routing_manager.cpp index 3c3a4dc226..1c605d532d 100644 --- a/map/routing_manager.cpp +++ b/map/routing_manager.cpp @@ -1015,6 +1015,7 @@ void RoutingManager::BuildRoute(uint32_t timeoutSec) m_drapeEngine.SafeCall(&df::DrapeEngine::SetModelViewRect, rect, true /* applyRotation */, -1 /* zoom */, true /* isAnim */, true /* useVisibleViewport */); + m_routingSession.ClearPositionAccumulator(); m_routingSession.SetUserCurrentPosition(routePoints.front().m_position); vector points; @@ -1027,6 +1028,8 @@ void RoutingManager::BuildRoute(uint32_t timeoutSec) void RoutingManager::SetUserCurrentPosition(m2::PointD const & position) { + // @TODO(bykoianko) PositionAccumulator should be filled even if there's no route. + // That means IsRoutingActive() returns false. if (IsRoutingActive()) m_routingSession.SetUserCurrentPosition(position); diff --git a/routing/routing_session.cpp b/routing/routing_session.cpp index e8269e605d..e5f355bab7 100644 --- a/routing/routing_session.cpp +++ b/routing/routing_session.cpp @@ -111,7 +111,7 @@ void RoutingSession::RebuildRoute(m2::PointD const & startPoint, // Use old-style callback construction, because lambda constructs buggy function on Android // (callback param isn't captured by value). - m_router->CalculateRoute(m_checkpoints, m_currentDirection, adjustToPrevRoute, + m_router->CalculateRoute(m_checkpoints, m_positionAccumulator.GetDirection(), adjustToPrevRoute, DoReadyCallback(*this, readyCallback), needMoreMapsCallback, removeRouteCallback, m_progressCallback, timeoutSec); } @@ -342,9 +342,6 @@ SessionState RoutingSession::OnLocationPositionChanged(GpsInfo const & info) } } - if (m_userCurrentPositionValid && m_userFormerPositionValid) - m_currentDirection = m_userCurrentPosition - m_userFormerPosition; - return m_state; } @@ -610,12 +607,11 @@ void RoutingSession::SetChangeSessionStateCallback( void RoutingSession::SetUserCurrentPosition(m2::PointD const & position) { CHECK_THREAD_CHECKER(m_threadChecker, ()); - // All methods which read/write m_userCurrentPosition*, m_userFormerPosition* work in RoutingManager thread - m_userFormerPosition = m_userCurrentPosition; - m_userFormerPositionValid = m_userCurrentPositionValid; m_userCurrentPosition = position; m_userCurrentPositionValid = true; + + m_positionAccumulator.PushNextPoint(position); } void RoutingSession::EnableTurnNotifications(bool enable) diff --git a/routing/routing_session.hpp b/routing/routing_session.hpp index 03036b8af9..cb4fcfafea 100644 --- a/routing/routing_session.hpp +++ b/routing/routing_session.hpp @@ -1,6 +1,7 @@ #pragma once #include "routing/async_router.hpp" +#include "routing/position_accumulator.hpp" #include "routing/route.hpp" #include "routing/router.hpp" #include "routing/routing_callbacks.hpp" @@ -105,6 +106,10 @@ public: void SetUserCurrentPosition(m2::PointD const & position); + void ClearPositionAccumulator() { m_positionAccumulator.Clear(); } + + void ActivateAdditionalFeatures() {} + /// Disable following mode on GPS updates. Following mode is disabled only for the current route. /// If a route is rebuilt you must call DisableFollowMode again. /// Returns true if following was disabled, false if a route is not ready for the following yet. @@ -188,17 +193,13 @@ private: bool m_isFollowing; Checkpoints m_checkpoints; - /// Current position metrics to check for RouteNeedRebuild state. double m_lastDistance = 0.0; int m_moveAwayCounter = 0; m2::PointD m_lastGoodPosition; - // |m_currentDirection| is a vector from the position before last good position to last good position. - m2::PointD m_currentDirection; + m2::PointD m_userCurrentPosition; - m2::PointD m_userFormerPosition; bool m_userCurrentPositionValid = false; - bool m_userFormerPositionValid = false; // Sound turn notification parameters. turns::sound::NotificationManager m_turnNotificationsMgr; @@ -206,6 +207,8 @@ private: SpeedCameraManager m_speedCameraManager; RoutingSettings m_routingSettings; + PositionAccumulator m_positionAccumulator; + ReadyCallback m_buildReadyCallback; ReadyCallback m_rebuildReadyCallback; NeedMoreMapsCallback m_needMoreMapsCallback;