Main MRPT website > C++ reference for MRPT 1.4.0
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-2016, 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
14#include <mrpt/poses/CPose3D.h>
15#include <mrpt/poses/CPose2D.h>
17#include <typeinfo>
18
19namespace mrpt
20{
21namespace obs
22{
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() */
98 /** \overload */
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
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
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>
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
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
#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...
This class stores messages from GNSS or GNSS+IMU devices, from consumer-grade inexpensive GPS receive...
void swap(CObservationGPS &o)
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< gnss::NMEA_RMC > has_RMC_datum
Evaluates as a bool; true if the corresponding field exists in messages.
mrpt::system::TTimeStamp getOriginalReceivedTimeStamp() const MRPT_OVERRIDE
By default, returns CObservation::timestamp but in sensors capable of satellite (or otherwise) accura...
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.
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.
void getSensorPose(mrpt::poses::CPose3D &out_sensorPose) const MRPT_OVERRIDE
A general method to retrieve the sensor pose on the robot.
const mrpt::obs::gnss::gnss_message * getMsgByType(const gnss::gnss_message_type_t type_id) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
mrpt::poses::CPose3D sensorPose
The sensor pose on the robot/vehicle.
bool hasMsgType(const gnss::gnss_message_type_t type_id) const
Returns true if the list CObservationGPS::messages contains one of the requested type.
void dumpToStream(mrpt::utils::CStream &out) const
Dumps the contents of the observation in a human-readable form to a given output stream.
void getDescriptionAsText(std::ostream &o) const MRPT_OVERRIDE
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...
const MSG_CLASS * getMsgByClassPtr() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool hasMsgClass() const
Like hasMsgType() but allows querying for message classes, from any of those derived from mrpt::obs::...
MSG_CLASS * getMsgByClassPtr()
Like CObservationGPS::getMsgByClass() but returns a NULL pointer if message is not found,...
void setSensorPose(const mrpt::poses::CPose3D &newSensorPose) MRPT_OVERRIDE
A general method to change the sensor pose on the robot.
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.
MSG_CLASS & getMsgByClass()
Returns a reference to the message in the list CObservationGPS::messages of the requested class.
static bool GPS_time_to_UTC(uint16_t gps_week, double gps_sec, const int leap_seconds_count, mrpt::system::TTimeStamp &utc_out)
Return false on invalid input data.
void clear()
Empties this observation, clearing the container messages.
message_list_t messages
The main piece of data in this class: a list of GNNS messages.
static bool GPS_time_to_UTC(uint16_t gps_week, double gps_sec, const int leap_seconds_count, mrpt::system::TTimeParts &utc_out)
This is an overloaded member function, provided for convenience. It differs from the above function o...
const MSG_CLASS & getMsgByClass() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
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::system::TTimeStamp originalReceivedTimestamp
The local computer-based timestamp based on the reception of the message in the computer.
Declares a class that represents any robot's observation.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition CPose3D.h:73
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition CStream.h:39
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1,...
Definition datetime.h:30
#define ASSERT_(f)
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
Definition mrpt_macros.h:28
#define ASSERTMSG_(f, __ERROR_MSG)
gnss_message_type_t
List of all known GNSS message types.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
unsigned int uint16_t
Definition pstdint.h:170
Proxy class for type-based testing existence of data inside CObservationGPS::messages.
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:36



Page generated by Doxygen 1.9.8 for MRPT 1.4.0 SVN: at Thu Dec 14 16:41:50 UTC 2023