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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019