libosmscout 1.1.1
Loading...
Searching...
No Matches
PositionAgent.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_NAVIGATION_ROUTE_POSITION_AGENT_H
2#define OSMSCOUT_NAVIGATION_ROUTE_POSITION_AGENT_H
3
4/*
5 This source is part of the libosmscout library
6 Copyright (C) 2019 Lukas Karas
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
26
27namespace osmscout {
28
33 class OSMSCOUT_API PositionAgent CLASS_FINAL : public NavigationAgent
34 {
35 public:
41
45 Distance horizontalAccuracy{Meters(2000)};
46
48 std::string GetStateStr(const Timestamp &now) const;
49
51
52 void Update(const Timestamp &time,
53 const GeoCoord &position,
54 const Distance &horizontalAccuracy);
55 };
56
58 Uninitialised, // position is uninitialised yet
59 NoGpsSignal, // last know position is used, may be inaccurate
60 OnRoute, // vehicle is on the planned route
61 OffRoute, // vehicle is out off planned route, route should be re-computed
62 EstimateInTunnel // vehicle position is estimated in tunnel
63 };
64
68 std::list<RouteDescription::Node>::const_iterator routeNode; // last passed node on the route
69
70 // resolved object
75
76 std::string StateStr() const;
77 };
78
82 struct OSMSCOUT_API PositionMessage CLASS_FINAL : public NavigationMessage
83 {
86
88 ~PositionMessage() override = default;
89
90 template<typename Description>
91 std::shared_ptr<Description> GetRouteDescription(const char* name) const
92 {
93 if (route &&
94 position.routeNode != route->Nodes().cend() &&
95 position.state != PositionAgent::Uninitialised &&
96 position.state != PositionAgent::OffRoute) {
97
98 return std::dynamic_pointer_cast<Description>(position.routeNode->GetDescription(name));
99 }
100 return nullptr;
101 }
102 };
103
104 using PositionMessageRef=std::shared_ptr<PositionMessage>;
105
106 private:
107 GpsPosition gps;
108 Timestamp lastUpdate; // last update of agent state
109 RoutableObjectsRef routableObjects; // routable objects around current position
110 RouteDescriptionRef route; // current route description
111 osmscout::Vehicle vehicle; // current vehicle
112 Position position;
113 Distance snapDistanceInMeters{Meters(20)}; // max distance from the route path to consider being on route
114
115 public:
116 PositionAgent() = default;
117 ~PositionAgent() override = default;
118
119 std::list<NavigationMessageRef> Process(const NavigationMessageRef& message) override;
120
121 private:
122 bool SearchClosestSegment(const GeoCoord& location,
123 const std::list<RouteDescription::Node>::const_iterator& locationOnRoute,
124 GeoCoord &closestPosition,
125 std::list<RouteDescription::Node>::const_iterator& foundNode,
126 double& foundAbscissa,
127 double& minDistance) const;
128 };
129
130}
131#endif
#define OSMSCOUT_API
Definition CoreImportExport.h:45
Definition Area.h:88
std::list< NavigationMessageRef > Process(const NavigationMessageRef &message) override
std::shared_ptr< PositionMessage > PositionMessageRef
Definition PositionAgent.h:104
~PositionAgent() override=default
GpsPositionState
Definition PositionAgent.h:36
@ Outdated
Definition PositionAgent.h:39
@ LowAccuracy
Definition PositionAgent.h:38
@ Good
Definition PositionAgent.h:37
PositionState
Definition PositionAgent.h:57
@ NoGpsSignal
Definition PositionAgent.h:59
@ Uninitialised
Definition PositionAgent.h:58
@ EstimateInTunnel
Definition PositionAgent.h:62
@ OffRoute
Definition PositionAgent.h:61
@ OnRoute
Definition PositionAgent.h:60
std::vector< VoiceSample > message
Definition VoiceInstructionAgent.h:99
osmscout::Vehicle vehicle
Definition Agents.h:87
Definition Engine.h:79
std::shared_ptr< TypeConfig > TypeConfigRef
Definition TypeConfig.h:1396
Definition Area.h:39
Distance Meters(double m)
Definition Distance.h:358
std::shared_ptr< Way > WayRef
Definition Way.h:213
std::chrono::system_clock::time_point Timestamp
Definition Time.h:27
std::shared_ptr< Area > AreaRef
Definition Area.h:360
uint32_t DatabaseId
Definition DBFileOffset.h:30
std::shared_ptr< RouteDescription > RouteDescriptionRef
Definition RouteDescription.h:834
std::shared_ptr< RoutableObjects > RoutableObjectsRef
Definition DataAgent.h:49
Vehicle
Definition OSMScoutTypes.h:55
std::shared_ptr< NavigationMessage > NavigationMessageRef
Definition Engine.h:56
Definition LaneAgent.h:61
Position position
Definition PositionAgent.h:85
RouteDescriptionRef route
Definition PositionAgent.h:84
PositionMessage(const Timestamp &timestamp, const RouteDescriptionRef &route, const Position &position)
~PositionMessage() override=default
std::shared_ptr< Description > GetRouteDescription(const char *name) const
Definition PositionAgent.h:91
Definition PositionAgent.h:42
Distance horizontalAccuracy
Definition PositionAgent.h:45
GpsPositionState GetState(const Timestamp &now) const
Timestamp lastUpdate
Definition PositionAgent.h:43
void Update(const Timestamp &time, const GeoCoord &position, const Distance &horizontalAccuracy)
GeoCoord position
Definition PositionAgent.h:44
std::string GetStateStr(const Timestamp &now) const
Definition PositionAgent.h:65
GeoCoord coord
Definition PositionAgent.h:67
WayRef way
Definition PositionAgent.h:73
PositionState state
Definition PositionAgent.h:66
std::list< RouteDescription::Node >::const_iterator routeNode
Definition PositionAgent.h:68
std::string StateStr() const
AreaRef area
Definition PositionAgent.h:74
TypeConfigRef typeConfig
Definition PositionAgent.h:72
DatabaseId databaseId
Definition PositionAgent.h:71
NavigationMessage(const Timestamp &timestamp)
const Timestamp timestamp
Definition Engine.h:50