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



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST