MRPT  1.9.9
CObservationGPS.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #ifndef CObservationGPS_H
10 #define CObservationGPS_H
11 
13 #include <mrpt/obs/CObservation.h>
14 #include <mrpt/poses/CPose3D.h>
15 #include <mrpt/poses/CPose2D.h>
16 #include <mrpt/obs/gnss_messages.h>
17 #include <typeinfo>
18 #include <map>
19 
20 namespace mrpt::obs
21 {
22 /** This class <b>stores messages</b> from GNSS or GNSS+IMU devices, from
23  * consumer-grade inexpensive GPS receivers to Novatel/Topcon/... advanced RTK
24  * solutions.
25  *
26  * See mrpt::hwdrivers::CGPSInterface for a class capable of reading from a
27  * serial port or any input stream and \b parsing the ASCII/binary stream into
28  * indivual messages \b stored in mrpt::obs::CObservationGPS objects.
29  *
30  * Supported message types are:
31  * - NMEA 0183 (ASCII): GGA, RMC
32  * - Topcon GRIL (Binary): PZS, SATS
33  * - Novatel GNSS/SPAN OEM6 (Binary): See list of log packets under namespace
34  * mrpt::obs::gnss and in enum type mrpt::obs::gnss::gnss_message_type_t
35  *
36  * Note that this object has \b two timestamp fields:
37  * - The standard CObservation::timestamp field in the base class, which should
38  * contain the accurate satellite-based UTC timestamp, and
39  * - the field CObservationGPS::originalReceivedTimestamp, with the local
40  * computer-based timestamp based on the reception of the message in the
41  * computer.
42  *
43  * Normally, users read and write messages by means of these methods:
44  * - CObservationGPS::getMsgByClass()
45  * - CObservationGPS::setMsg()
46  * - CObservationGPS::hasMsgType()
47  * - CObservationGPS::hasMsgClass()
48  *
49  * Example access to GPS datum:
50  * \code
51  * mrpt::obs::CObservationGPS obs;
52  * //...
53  * if (obs.hasMsgClass<mrpt::obs::gnss::Message_NMEA_GGA>()) {
54  * const mrpt::obs::gnss::Message_NMEA_GGA &gga =
55  * o.getMsgByClass<mrpt::obs::gnss::Message_NMEA_GGA>();
56  * //gga.fields.XXX ...
57  * }
58  * \endcode
59  *
60  * \note <b>[API changed in MRPT 1.4.0]</b> mrpt::obs::CObservationGPS now
61  * stores message objects in a more flexible way. API clean-up and extended so
62  * the number of GNSS message types is larger and more scalable.
63  * \note Porting old code: For example, replace `observation.GGA_datum.XXX` with
64  * `observation.getMsgByClass<gnss::Message_NMEA_GGA>().fields.XXX`, etc.
65  * \sa CObservation
66  * \ingroup mrpt_obs_grp
67  */
69 {
71 
72  public:
74  std::map<gnss::gnss_message_type_t, gnss::gnss_message_ptr>;
75 
76  /** @name GNSS (GPS) data fields
77  * @{ */
78  /** The sensor pose on the robot/vehicle */
80  /** The local computer-based timestamp based on the reception of the message
81  * in the computer. \sa CObservation::timestamp in the base class, which
82  * should contain the accurate satellite-based UTC timestamp. */
84  /** If true, CObservation::timestamp has been generated from accurate
85  * satellite clock. Otherwise, no GPS data is available and timestamps are
86  * based on the local computer clock. */
88  /** The main piece of data in this class: a list of GNNS messages.
89  * Normally users might prefer to access the list via the methods
90  * CObservationGPS::getMsgByClass() and CObservationGPS::setMsg()
91  * Typically only one message, may be multiple if all have the same
92  * timestamp. */
94  /** @} */
95 
96  /** @name Main API to access to the data fields
97  * @{ */
98  /** Stores a message in the list \a messages, making a copy of the passed
99  * object.
100  * Valid message classes are those derived from
101  * mrpt::obs::gnss::gnss_message. If another message of the same type
102  * exists, it is overwritten. */
103  template <class MSG_CLASS>
104  void setMsg(const MSG_CLASS& msg)
105  {
106  messages[static_cast<gnss::gnss_message_type_t>(MSG_CLASS::msg_type)]
107  .set(new MSG_CLASS(msg));
108  }
109  /** Returns true if the list \a CObservationGPS::messages contains one of
110  * the requested type. \sa mrpt::obs::gnss::gnss_message_type_t,
111  * CObservationGPS::getMsgByType() */
112  bool hasMsgType(const gnss::gnss_message_type_t type_id) const;
113  /** Like \a hasMsgType() but allows querying for message classes, from any
114  * of those derived from mrpt::obs::gnss::gnss_message \sa
115  * CObservationGPS::hasMsgType(), */
116  template <class MSG_CLASS>
117  bool hasMsgClass() const
118  {
119  return hasMsgType(
120  static_cast<gnss::gnss_message_type_t>(MSG_CLASS::msg_type));
121  }
122  /** Returns a pointer to the message in the list CObservationGPS::messages
123  * of the requested type. Users normally would prefer using
124  * CObservationGPS::getMsgByClass()
125  * to avoid having to perform a dynamic_cast<>() on the returned pointer.
126  * \exception std::runtime_error If there is no such a message in the list.
127  * Please, check existence before calling this method with
128  * CObservationGPS::hasMsgType()
129  * \sa mrpt::obs::gnss::gnss_message_type_t,
130  * CObservationGPS::getMsgByClass(), CObservationGPS::hasMsgType() */
132  const gnss::gnss_message_type_t type_id);
133  /** \overload */
135  const gnss::gnss_message_type_t type_id) const;
136 
137  /** Returns a reference to the message in the list CObservationGPS::messages
138  * of the requested class.
139  * \exception std::runtime_error If there is no such a message in the list.
140  * Please, check existence before calling this method with
141  * CObservationGPS::hasMsgClass()
142  * \sa mrpt::obs::gnss::gnss_message_type_t,
143  * CObservationGPS::getMsgByType(), CObservationGPS::hasMsgType() */
144  template <class MSG_CLASS>
145  MSG_CLASS& getMsgByClass()
146  {
148  static_cast<gnss::gnss_message_type_t>(MSG_CLASS::msg_type));
149  ASSERTMSG_(
150  it != messages.end(), mrpt::format(
151  "[CObservationGPS::getMsgByClass] Cannot "
152  "find any observation of type `%s`",
153  typeid(MSG_CLASS).name()));
154  ASSERT_(it->second.get());
155  return *dynamic_cast<MSG_CLASS*>(it->second.get());
156  }
157  /** \overload */
158  template <class MSG_CLASS>
159  const MSG_CLASS& getMsgByClass() const
160  {
162  static_cast<gnss::gnss_message_type_t>(MSG_CLASS::msg_type));
163  ASSERTMSG_(
164  it != messages.end(), mrpt::format(
165  "[CObservationGPS::getMsgByClass] Cannot "
166  "find any observation of type `%s`",
167  typeid(MSG_CLASS).name()));
168  ASSERT_(it->second.get());
169  return *dynamic_cast<const MSG_CLASS*>(it->second.get());
170  }
171 
172  /** Like CObservationGPS::getMsgByClass() but returns a nullptr pointer if
173  * message is not found, instead of launching an exception */
174  template <class MSG_CLASS>
175  MSG_CLASS* getMsgByClassPtr()
176  {
178  static_cast<gnss::gnss_message_type_t>(MSG_CLASS::msg_type));
179  return it == messages.end()
180  ? static_cast<MSG_CLASS*>(nullptr)
181  : dynamic_cast<MSG_CLASS*>(it->second.get());
182  }
183  /** \overload */
184  template <class MSG_CLASS>
185  const MSG_CLASS* getMsgByClassPtr() const
186  {
188  static_cast<gnss::gnss_message_type_t>(MSG_CLASS::msg_type));
189  return it == messages.end()
190  ? dynamic_cast<MSG_CLASS*>(nullptr)
191  : dynamic_cast<MSG_CLASS*>(it->second.get());
192  }
193 
194  /** Dumps the contents of the observation in a human-readable form to a
195  * given output stream \sa dumpToConsole(), getDescriptionAsText() */
196  void dumpToStream(std::ostream& out) const;
197  /** Dumps the contents of the observation in a human-readable form to an
198  * std::ostream (use std::cout to print to console) */
199  void dumpToConsole(std::ostream& o) const;
200  /** Empties this observation, clearing the container \a messages */
201  void clear();
202  void swap(CObservationGPS& o);
203 
204  void getSensorPose(mrpt::poses::CPose3D& out_sensorPose) const override
205  {
206  out_sensorPose = sensorPose;
207  } // See base class docs
208  void setSensorPose(const mrpt::poses::CPose3D& newSensorPose) override
209  {
210  sensorPose = newSensorPose;
211  } // See base class docs
213  std::ostream& o) const override; // See base class docs
214 
216  const override; // See base class docs
217  /** @} */
218 
219  /** @name Deprecated, backwards compatible (MRPT <1.4.0) data and types
220  * @{ */
221  /** Deprecated, kept for backwards compatibility */
223  /** Deprecated, kept for backwards compatibility */
225  /** Deprecated, kept for backwards compatibility */
227  /** Deprecated, kept for backwards compatibility */
229  /** Deprecated, kept for backwards compatibility */
231 
232  /** Proxy class for type-based testing existence of data inside
233  * CObservationGPS::messages */
234  template <mrpt::obs::gnss::gnss_message_type_t MSG_TYPE>
236  {
238  operator bool(void) const { return msgs.find(MSG_TYPE) != msgs.end(); }
241  {
242  return *this;
243  }
244 
245  private:
247  };
248 
249  // Was: bool has_GGA_datum;
250  /** Evaluates as a bool; true if the corresponding field exists in \a
251  * messages. */
253  /** Evaluates as a bool; true if the corresponding field exists in \a
254  * messages. */
256  /** Evaluates as a bool; true if the corresponding field exists in \a
257  * messages. */
259  /** Evaluates as a bool; true if the corresponding field exists in \a
260  * messages. */
262  /** @} */
263 
264  /** @name Utilities
265  * @{ */
266  static bool GPS_time_to_UTC(
267  uint16_t gps_week, double gps_sec,
268  const int leap_seconds_count /**< [in] GPS to UTC time number of leap
269  seconds (normally grabbed from
270  satellital live data) */
271  ,
272  /** Return false on invalid input data */
273  mrpt::system::TTimeStamp& utc_out /**< [out] UTC timestamp */);
274  /** \overload */
275  static bool GPS_time_to_UTC(
276  uint16_t gps_week, double gps_sec, const int leap_seconds_count,
277  mrpt::system::TTimeParts& utc_out);
278  /** @} */
279 }; // End of class def.
280 
281 }
282 #endif
283 
284 
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
This class stores messages from GNSS or GNSS+IMU devices, from consumer-grade inexpensive GPS receive...
static bool GPS_time_to_UTC(uint16_t gps_week, double gps_sec, const int leap_seconds_count, mrpt::system::TTimeStamp &utc_out)
std::map< gnss::gnss_message_type_t, gnss::gnss_message_ptr > message_list_t
internal_msg_test_proxy< gnss::NMEA_RMC > has_RMC_datum
Evaluates as a bool; true if the corresponding field exists in messages.
bool has_satellite_timestamp
If true, CObservation::timestamp has been generated from accurate satellite clock.
internal_msg_test_proxy< gnss::TOPCON_PZS > has_PZS_datum
Evaluates as a bool; true if the corresponding field exists in messages.
mrpt::poses::CPose3D sensorPose
The sensor pose on the robot/vehicle.
MSG_CLASS & getMsgByClass()
Returns a reference to the message in the list CObservationGPS::messages of the requested class.
void getDescriptionAsText(std::ostream &o) const override
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...
bool hasMsgClass() const
Like hasMsgType() but allows querying for message classes, from any of those derived from mrpt::obs::...
void dumpToStream(std::ostream &out) const
Dumps the contents of the observation in a human-readable form to a given output stream.
const MSG_CLASS & getMsgByClass() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void swap(CObservationGPS &o)
bool hasMsgType(const gnss::gnss_message_type_t type_id) const
Returns true if the list CObservationGPS::messages contains one of the requested type.
internal_msg_test_proxy< gnss::TOPCON_SATS > has_SATS_datum
Evaluates as a bool; true if the corresponding field exists in messages.
MSG_CLASS * getMsgByClassPtr()
Like CObservationGPS::getMsgByClass() but returns a nullptr pointer if message is not found,...
message_list_t messages
The main piece of data in this class: a list of GNNS messages.
mrpt::system::TTimeStamp getOriginalReceivedTimeStamp() const override
By default, returns CObservation::timestamp but in sensors capable of satellite (or otherwise) accura...
void clear()
Empties this observation, clearing the container messages.
void setSensorPose(const mrpt::poses::CPose3D &newSensorPose) override
A general method to change the sensor pose on the robot.
void setMsg(const MSG_CLASS &msg)
Stores a message in the list messages, making a copy of the passed object.
mrpt::obs::gnss::gnss_message * getMsgByType(const gnss::gnss_message_type_t type_id)
Returns a pointer to the message in the list CObservationGPS::messages of the requested type.
internal_msg_test_proxy< gnss::NMEA_GGA > has_GGA_datum
Evaluates as a bool; true if the corresponding field exists in messages.
void getSensorPose(mrpt::poses::CPose3D &out_sensorPose) const override
A general method to retrieve the sensor pose on the robot.
mrpt::system::TTimeStamp originalReceivedTimestamp
The local computer-based timestamp based on the reception of the message in the computer.
void dumpToConsole(std::ostream &o) const
Dumps the contents of the observation in a human-readable form to an std::ostream (use std::cout to p...
const MSG_CLASS * getMsgByClassPtr() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Declares a class that represents any robot's observation.
Definition: CObservation.h:44
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:87
Scalar * iterator
Definition: eigen_plugins.h:26
const Scalar * const_iterator
Definition: eigen_plugins.h:27
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
Definition: exceptions.h:101
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
#define INVALID_TIMESTAMP
Represents an invalid timestamp, where applicable.
Definition: datetime.h:43
mrpt::Clock::time_point TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1,...
Definition: datetime.h:40
gnss_message_type_t
List of all known GNSS message types.
This namespace contains representation of robot actions and observations.
unsigned __int16 uint16_t
Definition: rptypes.h:44
Proxy class for type-based testing existence of data inside CObservationGPS::messages.
internal_msg_test_proxy< MSG_TYPE > & operator=(const internal_msg_test_proxy< MSG_TYPE > &)
GPS datum for TopCon's mmGPS devices: PZS.
TopCon mmGPS devices: SATS, a generic structure for statistics about tracked satelites and their posi...
UTC (Coordinated Universal Time) time-stamp structure for GPS messages.
Pure virtual base for all message types.
The parts of a date/time (it's like the standard 'tm' but with fractions of seconds).
Definition: datetime.h:50



Page generated by Doxygen 1.9.1 for MRPT 1.9.9 Git: 814d80880 Fri Aug 24 01:51:28 2018 +0200 at mar 26 may 2026 12:30:59 CEST