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



Page generated by Doxygen 1.8.9.1 for MRPT 1.3.2 SVN:Unversioned directory at Thu Dec 10 00:07:55 UTC 2015