Main MRPT website > C++ reference for MRPT 1.5.9
obs/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  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CObservationGPS , CObservation, OBS_IMPEXP)
24 
25  /** This class <b>stores messages</b> from GNSS or GNSS+IMU devices, from consumer-grade inexpensive GPS receivers to Novatel/Topcon/... advanced RTK solutions.
26  *
27  * See mrpt::hwdrivers::CGPSInterface for a class capable of reading from a 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 mrpt::obs::gnss and in enum type mrpt::obs::gnss::gnss_message_type_t
34  *
35  * Note that this object has \b two timestamp fields:
36  * - The standard CObservation::timestamp field in the base class, which should contain the accurate satellite-based UTC timestamp, and
37  * - the field CObservationGPS::originalReceivedTimestamp, with the local computer-based timestamp based on the reception of the message in the computer.
38  *
39  * Normally, users read and write messages by means of these methods:
40  * - CObservationGPS::getMsgByClass()
41  * - CObservationGPS::setMsg()
42  * - CObservationGPS::hasMsgType()
43  * - CObservationGPS::hasMsgClass()
44  *
45  * Example access to GPS datum:
46  * \code
47  * mrpt::obs::CObservationGPS obs;
48  * //...
49  * if (obs.hasMsgClass<mrpt::obs::gnss::Message_NMEA_GGA>()) {
50  * const mrpt::obs::gnss::Message_NMEA_GGA &gga = o.getMsgByClass<mrpt::obs::gnss::Message_NMEA_GGA>();
51  * //gga.fields.XXX ...
52  * }
53  * \endcode
54  *
55  * \note <b>[API changed in MRPT 1.4.0]</b> mrpt::obs::CObservationGPS now stores message objects in a more flexible way. API clean-up and extended so the number of GNSS message types is larger and more scalable.
56  * \note Porting old code: For example, replace `observation.GGA_datum.XXX` with `observation.getMsgByClass<gnss::Message_NMEA_GGA>().fields.XXX`, etc.
57  * \sa CObservation
58  * \ingroup mrpt_obs_grp
59  */
61  {
62  // This must be added to any CSerializable derived class:
64 
65  public:
66  typedef std::map<gnss::gnss_message_type_t, gnss::gnss_message_ptr> message_list_t;
67 
68  CObservationGPS(); //!< ctor
69 
70  /** @name GNSS (GPS) data fields
71  * @{ */
72  mrpt::poses::CPose3D sensorPose;//!< The sensor pose on the robot/vehicle
73  mrpt::system::TTimeStamp originalReceivedTimestamp; //!< The local computer-based timestamp based on the reception of the message in the computer. \sa CObservation::timestamp in the base class, which should contain the accurate satellite-based UTC timestamp.
74  bool has_satellite_timestamp; //!< If true, CObservation::timestamp has been generated from accurate satellite clock. Otherwise, no GPS data is available and timestamps are based on the local computer clock.
75  /** The main piece of data in this class: a list of GNNS messages.
76  * Normally users might prefer to access the list via the methods CObservationGPS::getMsgByClass() and CObservationGPS::setMsg()
77  * Typically only one message, may be multiple if all have the same timestamp. */
79  /** @} */
80 
81  /** @name Main API to access to the data fields
82  * @{ */
83  /** Stores a message in the list \a messages, making a copy of the passed object.
84  * Valid message classes are those derived from mrpt::obs::gnss::gnss_message. If another message of the same type exists, it is overwritten. */
85  template <class MSG_CLASS>
86  void setMsg(const MSG_CLASS &msg) {
87  messages[static_cast<gnss::gnss_message_type_t>(MSG_CLASS::msg_type)].set(new MSG_CLASS(msg));
88  }
89  /** Returns true if the list \a CObservationGPS::messages contains one of the requested type. \sa mrpt::obs::gnss::gnss_message_type_t, CObservationGPS::getMsgByType() */
90  bool hasMsgType(const gnss::gnss_message_type_t type_id) const;
91  /** Like \a hasMsgType() but allows querying for message classes, from any of those derived from mrpt::obs::gnss::gnss_message \sa CObservationGPS::hasMsgType(), */
92  template <class MSG_CLASS> bool hasMsgClass() const { return hasMsgType(static_cast<gnss::gnss_message_type_t>(MSG_CLASS::msg_type)); }
93  /** Returns a pointer to the message in the list CObservationGPS::messages of the requested type. Users normally would prefer using CObservationGPS::getMsgByClass()
94  * to avoid having to perform a dynamic_cast<>() on the returned pointer.
95  * \exception std::runtime_error If there is no such a message in the list. Please, check existence before calling this method with CObservationGPS::hasMsgType()
96  * \sa mrpt::obs::gnss::gnss_message_type_t, CObservationGPS::getMsgByClass(), CObservationGPS::hasMsgType() */
97  mrpt::obs::gnss::gnss_message* getMsgByType(const gnss::gnss_message_type_t type_id);
98  /** \overload */
99  const mrpt::obs::gnss::gnss_message* getMsgByType(const gnss::gnss_message_type_t type_id) const;
100 
101  /** Returns a reference to the message in the list CObservationGPS::messages of the requested class.
102  * \exception std::runtime_error If there is no such a message in the list. Please, check existence before calling this method with CObservationGPS::hasMsgClass()
103  * \sa mrpt::obs::gnss::gnss_message_type_t, CObservationGPS::getMsgByType(), CObservationGPS::hasMsgType() */
104  template <class MSG_CLASS>
105  MSG_CLASS & getMsgByClass() {
106  message_list_t::iterator it = messages.find(static_cast<gnss::gnss_message_type_t>(MSG_CLASS::msg_type));
107  ASSERTMSG_(it!=messages.end(), mrpt::format("[CObservationGPS::getMsgByClass] Cannot find any observation of type `%s`",typeid(MSG_CLASS).name()));
108  ASSERT_(it->second.get());
109  return *dynamic_cast<MSG_CLASS*>(it->second.get());
110  }
111  /** \overload */
112  template <class MSG_CLASS>
113  const MSG_CLASS & getMsgByClass() const {
114  message_list_t::const_iterator it = messages.find(static_cast<gnss::gnss_message_type_t>(MSG_CLASS::msg_type));
115  ASSERTMSG_(it!=messages.end(), mrpt::format("[CObservationGPS::getMsgByClass] Cannot find any observation of type `%s`",typeid(MSG_CLASS).name()));
116  ASSERT_(it->second.get());
117  return *dynamic_cast<const MSG_CLASS*>(it->second.get());
118  }
119 
120  /** Like CObservationGPS::getMsgByClass() but returns a NULL pointer if message is not found, instead of launching an exception */
121  template <class MSG_CLASS>
122  MSG_CLASS * getMsgByClassPtr() {
123  message_list_t::iterator it = messages.find(static_cast<gnss::gnss_message_type_t>(MSG_CLASS::msg_type));
124  return it==messages.end() ? reinterpret_cast<MSG_CLASS*>(NULL) : dynamic_cast<MSG_CLASS*>(it->second.get());
125  }
126  /** \overload */
127  template <class MSG_CLASS>
128  const MSG_CLASS * getMsgByClassPtr() const {
129  message_list_t::const_iterator it = messages.find(static_cast<gnss::gnss_message_type_t>(MSG_CLASS::msg_type));
130  return it==messages.end() ? dynamic_cast<MSG_CLASS*>(NULL) : dynamic_cast<MSG_CLASS*>(it->second.get());
131  }
132 
133  void dumpToStream( mrpt::utils::CStream &out ) const; //!< Dumps the contents of the observation in a human-readable form to a given output stream \sa dumpToConsole(), getDescriptionAsText()
134  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)
135  void clear(); //!< Empties this observation, clearing the container \a messages
136  void swap(CObservationGPS &o);
137 
138  void getSensorPose( mrpt::poses::CPose3D &out_sensorPose ) const MRPT_OVERRIDE { out_sensorPose = sensorPose; } // See base class docs
139  void setSensorPose( const mrpt::poses::CPose3D &newSensorPose ) MRPT_OVERRIDE { sensorPose = newSensorPose; } // See base class docs
140  void getDescriptionAsText(std::ostream &o) const MRPT_OVERRIDE; // See base class docs
141 
142  mrpt::system::TTimeStamp getOriginalReceivedTimeStamp() const MRPT_OVERRIDE; // See base class docs
143  /** @} */
144 
145  /** @name Deprecated, backwards compatible (MRPT <1.4.0) data and types
146  * @{ */
147  typedef gnss::UTC_time TUTCTime; //!< Deprecated, kept for backwards compatibility
148  typedef gnss::Message_TOPCON_PZS TGPSDatum_PZS; //!< Deprecated, kept for backwards compatibility
149  typedef gnss::Message_TOPCON_SATS TGPSDatum_SATS; //!< Deprecated, kept for backwards compatibility
150  typedef gnss::Message_NMEA_GGA TGPSDatum_GGA; //!< Deprecated, kept for backwards compatibility
151  typedef gnss::Message_NMEA_RMC TGPSDatum_RMC; //!< Deprecated, kept for backwards compatibility
152 
153  /** Proxy class for type-based testing existence of data inside CObservationGPS::messages */
154  template <mrpt::obs::gnss::gnss_message_type_t MSG_TYPE>
156  internal_msg_test_proxy(message_list_t &msgs_) : msgs(msgs_) {}
157  operator bool(void) const { return msgs.find(MSG_TYPE)!=msgs.end(); }
159  private:
161  };
162 
163  // Was: bool has_GGA_datum;
164  internal_msg_test_proxy<gnss::NMEA_GGA> has_GGA_datum; //!< Evaluates as a bool; true if the corresponding field exists in \a messages.
165  internal_msg_test_proxy<gnss::NMEA_RMC> has_RMC_datum; //!< Evaluates as a bool; true if the corresponding field exists in \a messages.
166  internal_msg_test_proxy<gnss::TOPCON_PZS> has_PZS_datum; //!< Evaluates as a bool; true if the corresponding field exists in \a messages.
167  internal_msg_test_proxy<gnss::TOPCON_SATS> has_SATS_datum; //!< Evaluates as a bool; true if the corresponding field exists in \a messages.
168  /** @} */
169 
170  /** @name Utilities
171  * @{ */
172  static bool GPS_time_to_UTC(
173  uint16_t gps_week,double gps_sec,
174  const int leap_seconds_count /**< [in] GPS to UTC time number of leap seconds (normally grabbed from satellital live data) */,
175  mrpt::system::TTimeStamp &utc_out /**< [out] UTC timestamp */ ); //!< Return false on invalid input data
176  static bool GPS_time_to_UTC(uint16_t gps_week,double gps_sec,const int leap_seconds_count, mrpt::system::TTimeParts &utc_out); //!< \overload
177  /** @} */
178  }; // End of class def.
180 
181 
182  } // End of namespace
183 } // End of namespace
184 
185 #endif
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:30
MSG_CLASS * getMsgByClassPtr()
Like CObservationGPS::getMsgByClass() but returns a NULL pointer if message is not found...
unsigned __int16 uint16_t
Definition: rptypes.h:46
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.
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
mrpt::system::TTimeStamp originalReceivedTimestamp
The local computer-based timestamp based on the reception of the message in the computer.
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:23
const Scalar * const_iterator
Definition: eigen_plugins.h:24
GPS datum for TopCon&#39;s mmGPS devices: PZS.
void clear()
Clear the contents of this container.
Definition: ts_hash_map.h:113
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
const MSG_CLASS * getMsgByClassPtr() const
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
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:35
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. Otherwise, no GPS data is available and timestamps are based on the local computer clock.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
internal_msg_test_proxy< gnss::TOPCON_PZS > has_PZS_datum
Evaluates as a bool; true if the corresponding field exists in messages.
MSG_CLASS & getMsgByClass()
Returns a reference to the message in the list CObservationGPS::messages of the requested class...
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.
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:72
Declares a class that represents any robot&#39;s observation.
Pure virtual base for all message types.
bool hasMsgClass() const
Like hasMsgType() but allows querying for message classes, from any of those derived from mrpt::obs::...
void setSensorPose(const mrpt::poses::CPose3D &newSensorPose) MRPT_OVERRIDE
A general method to change the sensor pose on the robot.
GLuint const GLchar * name
Definition: glext.h:3891
#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.
This class stores messages from GNSS or GNSS+IMU devices, from consumer-grade inexpensive GPS receive...
void getSensorPose(mrpt::poses::CPose3D &out_sensorPose) const MRPT_OVERRIDE
A general method to retrieve the sensor pose on the robot.
const MSG_CLASS & getMsgByClass() const
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
#define ASSERTMSG_(f, __ERROR_MSG)



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020