libosmscout  1.1.1
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 
27 namespace osmscout {
28 
33  class OSMSCOUT_API PositionAgent CLASS_FINAL : public NavigationAgent
34  {
35  public:
39  Outdated
40  };
41 
44  GeoCoord position;
45  Distance horizontalAccuracy{Meters(2000)};
46 
47  GpsPositionState GetState(const Timestamp &now) const;
48  std::string GetStateStr(const Timestamp &now) const;
49 
50  GeoBox GetGeoBox() const;
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 
66  PositionState state{PositionState::Uninitialised};
67  GeoCoord coord;
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 
87  PositionMessage(const Timestamp& timestamp, const RouteDescriptionRef &route, const Position &position);
88 
89  template<typename Description>
90  std::shared_ptr<Description> GetRouteDescription(const char* name) const
91  {
92  if (route &&
93  position.routeNode != route->Nodes().cend() &&
94  position.state != PositionAgent::Uninitialised &&
95  position.state != PositionAgent::OffRoute) {
96 
97  return std::dynamic_pointer_cast<Description>(position.routeNode->GetDescription(name));
98  }
99  return nullptr;
100  }
101  };
102 
103  using PositionMessageRef=std::shared_ptr<PositionMessage>;
104 
105  private:
106  GpsPosition gps;
107  Timestamp lastUpdate; // last update of agent state
108  RoutableObjectsRef routableObjects; // routable objects around current position
109  RouteDescriptionRef route; // current route description
110  osmscout::Vehicle vehicle; // current vehicle
111  Position position;
112  Distance snapDistanceInMeters{Meters(20)}; // max distance from the route path to consider being on route
113 
114  public:
115  PositionAgent();
116 
117  std::list<NavigationMessageRef> Process(const NavigationMessageRef& message) override;
118 
119  private:
120  bool SearchClosestSegment(const GeoCoord& location,
121  const std::list<RouteDescription::Node>::const_iterator& locationOnRoute,
122  GeoCoord &closestPosition,
123  std::list<RouteDescription::Node>::const_iterator& foundNode,
124  double& foundAbscissa,
125  double& minDistance) const;
126  };
127 
128 }
129 #endif
PositionState
Definition: PositionAgent.h:57
std::shared_ptr< PositionMessage > PositionMessageRef
Definition: PositionAgent.h:103
Definition: PositionAgent.h:59
std::chrono::system_clock::time_point Timestamp
Definition: Time.h:27
Definition: PositionAgent.h:65
AreaRef area
Definition: PositionAgent.h:74
std::list< RouteDescription::Node >::const_iterator routeNode
Definition: PositionAgent.h:68
Definition: PositionAgent.h:37
Vehicle
Definition: OSMScoutTypes.h:55
Definition: PositionAgent.h:60
std::shared_ptr< Description > GetRouteDescription(const char *name) const
Definition: PositionAgent.h:90
std::shared_ptr< Way > WayRef
Definition: Way.h:202
Position position
Definition: PositionAgent.h:85
TypeConfigRef typeConfig
Definition: PositionAgent.h:72
Definition: Area.h:38
#define CLASS_FINAL
Definition: Compiler.h:26
std::shared_ptr< Area > AreaRef
Definition: Area.h:358
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
Definition: LaneAgent.h:60
GeoCoord position
Definition: PositionAgent.h:44
Timestamp lastUpdate
Definition: PositionAgent.h:43
GeoCoord coord
Definition: PositionAgent.h:67
DatabaseId databaseId
Definition: PositionAgent.h:71
PositionState state
Definition: PositionAgent.h:66
std::shared_ptr< RouteDescription > RouteDescriptionRef
Definition: RouteDescription.h:814
Definition: PositionAgent.h:58
Definition: PositionAgent.h:42
Definition: PositionAgent.h:38
RouteDescriptionRef route
Definition: PositionAgent.h:84
Distance Meters(double m)
Definition: Distance.h:358
std::shared_ptr< RoutableObjects > RoutableObjectsRef
Definition: DataAgent.h:49
GpsPositionState
Definition: PositionAgent.h:36
std::shared_ptr< NavigationMessage > NavigationMessageRef
Definition: Engine.h:56
std::shared_ptr< TypeConfig > TypeConfigRef
Definition: TypeConfig.h:1227
WayRef way
Definition: PositionAgent.h:73
Definition: Engine.h:48
Definition: PositionAgent.h:61
uint32_t DatabaseId
Definition: DBFileOffset.h:30