Main MRPT website > C++ reference
MRPT logo
CGPSInterface.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-2014, 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 
10 #ifndef CGPSInterface_H
11 #define CGPSInterface_H
12 
14 #include <mrpt/poses/CPoint3D.h>
18 
19 namespace mrpt
20 {
21  namespace slam { class CObservationGPS; }
22 
23  namespace hwdrivers
24  {
25  /** A parser of NMEA commands, for connecting to a GPS by a serial port.
26  * This class also supports more advanced GPS equipped with RTK corrections. See the JAVAD/TopCon extra initialization parameters.
27  *
28  * \code
29  * PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS:
30  * -------------------------------------------------------
31  * [supplied_section_name]
32  * COM_port_WIN = COM3
33  * COM_port_LIN = ttyS0
34  * baudRate = 4800 // The baudrate of the communications (typ. 4800 bauds)
35  * pose_x = 0 // 3D position of the sensed point relative to the robot (meters)
36  * pose_y = 0
37  * pose_z = 0
38  * customInit = // See below for possible values
39  *
40  * // The next parameters are optional and will be used only
41  * // if customInit=="JAVAD" to enable/configure the usage of RTK corrections:
42  * //JAVAD_rtk_src_port=/dev/ser/b
43  * //JAVAD_rtk_src_baud=9600
44  * //JAVAD_rtk_format=cmr
45  *
46  * \endcode
47  *
48  * - customInit: Custom commands to send, depending on the sensor. Valid values are:
49  * - "": Empty string
50  * - "JAVAD": JAVAD or TopCon devices. Extra initialization commands will be sent.
51  * - "TopCon": A synonymous with "JAVAD".
52  *
53  * VERSIONS HISTORY:
54  * -9/JUN/2006: First version (JLBC)
55  * -4/JUN/2008: Added virtual methods for device-specific initialization commands.
56  * -10/JUN/2008: Converted into CGenericSensor class (there are no inhirited classes anymore).
57  * -7/DEC/2012: Added public static method to parse NMEA strings.
58  * -17/JUN/2014: Added GGA feedback.
59  *
60  * \note Verbose debug info will be dumped to cout if the environment variable "MRPT_HWDRIVERS_VERBOSE" is set to "1", or if you call CGenericSensor::enableVerbose(true)
61  *
62  * \ingroup mrpt_hwdrivers_grp
63  */
65  {
67 
68  public:
69  /** Constructor
70  * \param BUFFER_LENGTH The size of the communications buffer (default value should be fine always)
71  */
72  CGPSInterface( int BUFFER_LENGTH = 500, mrpt::hwdrivers::CSerialPort *outPort = NULL, mrpt::synch::CCriticalSection *csOutPort = NULL);
73 
74  /** Destructor
75  */
76  virtual ~CGPSInterface();
77 
78  // See docs in parent class
79  void doProcess();
80 
81  /** Returns true if communications work.
82  */
83  bool isGPS_connected();
84 
85  /** Returns true if the last message from the GPS indicates that the signal from sats has been acquired.
86  */
87  bool isGPS_signalAcquired();
88 
89  void setSerialPortName(const std::string &COM_port); //!< Set the serial port to use (COM1, ttyUSB0, etc).
90  std::string getSerialPortName() const; //!< Get the serial port to use (COM1, ttyUSB0, etc).
91 
92  inline void setExternCOM( CSerialPort *outPort, mrpt::synch::CCriticalSection *csOutPort )
93  { m_out_COM = outPort; m_cs_out_COM = csOutPort; }
94 
95  inline bool isAIMConfigured() { return m_AIMConfigured; }
96 
97  /** Parses one line of NMEA data from a GPS receiver, and writes the recognized fields (if any) into an observation object.
98  * Recognized frame types are: "GGA" and "RMC".
99  * \return true if some new data field has been correctly parsed and inserted into out_obs
100  */
101  static bool parse_NMEA(const std::string &cmd_line, mrpt::slam::CObservationGPS &out_obs, const bool verbose=false);
102 
103  /** Gets the latest GGA command or an empty string if no newer GGA command was received since the last call to this method.
104  * \param[in] reset If set to true, will empty the GGA cache so next calls will return an empty string if no new frame is received.
105  */
106  std::string getLastGGA(bool reset=true);
107 
108  protected:
109  /** Implements custom messages to be sent to the GPS unit just after connection and before normal use.
110  * Returns false or raise an exception if something goes wrong.
111  */
112  bool OnConnectionEstablished();
113 
115 
116  // MAR'11 -------------------------------------
119  // --------------------------------------------
120 
122 
123  std::string m_customInit;
124 
125  /** See the class documentation at the top for expected parameters */
126  void loadConfig_sensorSpecific(
127  const mrpt::utils::CConfigFileBase &configSource,
128  const std::string &iniSection );
129 
130  /** If not empty, will send a cmd "set,/par/pos/pd/port,...". Example value: "/dev/ser/b" */
131  void setJAVAD_rtk_src_port( const std::string &s) { m_JAVAD_rtk_src_port = s; }
132 
133  /** Only used when "m_JAVAD_rtk_src_port" is not empty */
134  void setJAVAD_rtk_src_baud(unsigned int baud) { m_JAVAD_rtk_src_baud = baud; }
135 
136  /** Only used when "m_JAVAD_rtk_src_port" is not empty: format of RTK corrections: "cmr", "rtcm", "rtcm3", etc. */
137  void setJAVAD_rtk_format(const std::string &s) {m_JAVAD_rtk_format=s;}
138 
139  /** Set Advanced Input Mode for the primary port.
140  This can be used to send RTK corrections to the device using the same port that it's used for the commands.
141  The RTK correction stream must be re-packaged into a special frame with prefix ">>" */
142  bool setJAVAD_AIM_mode();
143 
144  /** Unset Advanced Input Mode for the primary port and use it only as a command port. */
145  bool unsetJAVAD_AIM_mode();
146 
147  // MAR'11 -------------------------------------
148  inline bool useExternCOM() const { return (m_out_COM!=NULL); }
149  // --------------------------------------------
150 
151  private:
152  std::string m_COMname;
157 
158  char *m_buffer;
161 
162  std::string m_JAVAD_rtk_src_port; //!< If not empty, will send a cmd "set,/par/pos/pd/port,...". Example value: "/dev/ser/b"
163  unsigned int m_JAVAD_rtk_src_baud; //!< Only used when "m_JAVAD_rtk_src_port" is not empty
164  std::string m_JAVAD_rtk_format; //!< Only used when "m_JAVAD_rtk_src_port" is not empty: format of RTK corrections: "cmr", "rtcm", "rtcm3", etc.
165 
166  // MAR'11 -----------------------------------------
167  bool m_useAIMMode; //!< Use this mode for receive RTK corrections from a external source through the primary port
168  // ------------------------------------------------
170 
171  // MAR'11 -----------------------------------------
172  bool m_AIMConfigured; //!< Indicates if the AIM has been properly set up.
173  double m_data_period; //!< The period in seconds which the data should be provided by the GPS
174  // ------------------------------------------------
175 
176  /** Returns true if the COM port is already open, or try to open it in other case.
177  * \return true if everything goes OK, or false if there are problems opening the port.
178  */
179  bool tryToOpenTheCOM();
180 
181  /** Process data in "m_buffer" to extract GPS messages, and remove them from the buffer.
182  */
183  void processBuffer();
184 
185  /** Process a complete string from the GPS:
186  */
187  void processGPSstring( const std::string &s);
188 
189  /* A private copy of the last received gps datum:
190  */
193 
194  std::string m_last_GGA; //!< Used in getLastGGA()
195 
196  void JAVAD_sendMessage(const char*str, bool waitForAnswer = true); //!< Private auxiliary method. Raises exception on error.
197 
198  }; // end class
199 
200  } // end namespace
201 } // end namespace
202 
203 #endif
A generic interface for a wide-variety of sensors designed to be used in the application RawLogGrabbe...
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:30
This class provides simple critical sections functionality.
A parser of NMEA commands, for connecting to a GPS by a serial port.
Definition: CGPSInterface.h:64
void setJAVAD_rtk_src_baud(unsigned int baud)
Only used when "m_JAVAD_rtk_src_port" is not empty.
A communications serial port built as an implementation of a utils::CStream.
Definition: CSerialPort.h:44
bool m_useAIMMode
Use this mode for receive RTK corrections from a external source through the primary port...
bool m_AIMConfigured
Indicates if the AIM has been properly set up.
unsigned int m_JAVAD_rtk_src_baud
Only used when "m_JAVAD_rtk_src_port" is not empty.
std::string m_JAVAD_rtk_src_port
If not empty, will send a cmd "set,/par/pos/pd/port,...". Example value: "/dev/ser/b".
void setJAVAD_rtk_format(const std::string &s)
Only used when "m_JAVAD_rtk_src_port" is not empty: format of RTK corrections: "cmr", "rtcm", "rtcm3", etc.
This class allows loading and storing values and vectors of different types from a configuration text...
double m_data_period
The period in seconds which the data should be provided by the GPS.
std::string m_JAVAD_rtk_format
Only used when "m_JAVAD_rtk_src_port" is not empty: format of RTK corrections: "cmr", "rtcm", "rtcm3", etc.
A class used to store a 3D point.
Definition: CPoint3D.h:32
Declares a class derived from "CObservation" that represents a Global Positioning System (GPS) readin...
#define DEFINE_GENERIC_SENSOR(class_name)
This declaration must be inserted in all CGenericSensor classes definition, within the class declarat...
mrpt::slam::CObservationGPS m_latestGPS_data
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void setJAVAD_rtk_src_port(const std::string &s)
If not empty, will send a cmd "set,/par/pos/pd/port,...".
#define HWDRIVERS_IMPEXP
mrpt::synch::CCriticalSection * m_cs_out_COM
mrpt::system::TTimeStamp m_last_timestamp
std::string m_last_GGA
Used in getLastGGA()
This base class provides a common printf-like method to send debug information to std::cout...
void setExternCOM(CSerialPort *outPort, mrpt::synch::CCriticalSection *csOutPort)
Definition: CGPSInterface.h:92
A UTC time-stamp structure for GPS messages.
mrpt::slam::CObservationGPS::TUTCTime m_last_UTC_time



Page generated by Doxygen 1.8.8 for MRPT 1.2.2 SVN:Unversioned directory at Tue Oct 14 02:14:08 UTC 2014