Main MRPT website > C++ reference
MRPT logo
CGPSInterface.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 
29 #ifndef CGPSInterface_H
30 #define CGPSInterface_H
31 
33 #include <mrpt/poses/CPoint3D.h>
37 
38 namespace mrpt
39 {
40  namespace slam { class CObservationGPS; }
41 
42  namespace hwdrivers
43  {
44  /** A parser of NMEA commands, for connecting to a GPS by a serial port.
45  * This class also supports more advanced GPS equipped with RTK corrections. See the JAVAD/TopCon extra initialization parameters.
46  *
47  * \code
48  * PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS:
49  * -------------------------------------------------------
50  * [supplied_section_name]
51  * COM_port_WIN = COM3
52  * COM_port_LIN = ttyS0
53  * baudRate = 4800 // The baudrate of the communications (typ. 4800 bauds)
54  * pose_x = 0 // 3D position of the sensed point relative to the robot (meters)
55  * pose_y = 0
56  * pose_z = 0
57  * customInit = // See below for possible values
58  *
59  * // The next parameters are optional and will be used only
60  * // if customInit=="JAVAD" to enable/configure the usage of RTK corrections:
61  * //JAVAD_rtk_src_port=/dev/ser/b
62  * //JAVAD_rtk_src_baud=9600
63  * //JAVAD_rtk_format=cmr
64  *
65  * \endcode
66  *
67  * - customInit: Custom commands to send, depending on the sensor. Valid values are:
68  * - "": Empty string
69  * - "JAVAD": JAVAD or TopCon devices. Extra initialization commands will be sent.
70  * - "TopCon": A synonymous with "JAVAD".
71  *
72  * VERSIONS HISTORY:
73  * -9/JUN/2006: First version (JLBC)
74  * -4/JUN/2008: Added virtual methods for device-specific initialization commands.
75  * -10/JUN/2008: Converted into CGenericSensor class (there are no inhirited classes anymore).
76  * \ingroup mrpt_hwdrivers_grp
77  */
79  {
81 
82  public:
83  /** Constructor
84  * \param BUFFER_LENGTH The size of the communications buffer (default value should be fine always)
85  */
86 // CGPSInterface( int BUFFER_LENGTH = 500 );
87 
88  // MAR'11 -------------------------------------
89  CGPSInterface( int BUFFER_LENGTH = 500, mrpt::hwdrivers::CSerialPort *outPort = NULL, mrpt::synch::CCriticalSection *csOutPort = NULL);
90  // --------------------------------------------
91 
92  /** Destructor
93  */
94  virtual ~CGPSInterface();
95 
96  /** This method should be called periodically (at least at 1Hz to capture ALL the real-time data)
97  * It is thread safe, i.e. you can call this from one thread, then to other methods from other threads.
98  * This method processes data from the GPS and update the object state accordingly.
99  */
100  void doProcess();
101 
102  /** Returns true if communications work.
103  */
104  bool isGPS_connected();
105 
106  /** Returns true if the last message from the GPS indicates that the signal from sats has been acquired.
107  */
108  bool isGPS_signalAcquired();
109 
110  void setSerialPortName(const std::string &COM_port); //!< Set the serial port to use (COM1, ttyUSB0, etc).
111  std::string getSerialPortName() const; //!< Get the serial port to use (COM1, ttyUSB0, etc).
112 
113  inline void setExternCOM( CSerialPort *outPort, mrpt::synch::CCriticalSection *csOutPort )
114  { m_out_COM = outPort; m_cs_out_COM = csOutPort; }
115 
116  inline bool isAIMConfigured() { return m_AIMConfigured; }
117 
118  protected:
119  /** Implements custom messages to be sent to the GPS unit just after connection and before normal use.
120  * Returns false or raise an exception if something goes wrong.
121  */
122  bool OnConnectionEstablished();
123 
125 
126  // MAR'11 -------------------------------------
129  // --------------------------------------------
130 
132 
133  std::string m_customInit;
134 
135  /** Loads specific configuration for the device from a given source of configuration parameters, for example, an ".ini" file, loading from the section "[iniSection]" (see utils::CConfigFileBase and derived classes)
136  * See hwdrivers::CGPSInterface for the possible parameters
137  */
138  void loadConfig_sensorSpecific(
139  const mrpt::utils::CConfigFileBase &configSource,
140  const std::string &iniSection );
141 
142  /** If not empty, will send a cmd "set,/par/pos/pd/port,...". Example value: "/dev/ser/b" */
143  void setJAVAD_rtk_src_port( const std::string &s) { m_JAVAD_rtk_src_port = s; }
144 
145  /** Only used when "m_JAVAD_rtk_src_port" is not empty */
146  void setJAVAD_rtk_src_baud(unsigned int baud) { m_JAVAD_rtk_src_baud = baud; }
147 
148  /** Only used when "m_JAVAD_rtk_src_port" is not empty: format of RTK corrections: "cmr", "rtcm", "rtcm3", etc. */
149  void setJAVAD_rtk_format(const std::string &s) {m_JAVAD_rtk_format=s;}
150 
151  /** Set Advanced Input Mode for the primary port.
152  This can be used to send RTK corrections to the device using the same port that it's used for the commands.
153  The RTK correction stream must be re-packaged into a special frame with prefix ">>" */
154  bool setJAVAD_AIM_mode();
155 
156  /** Unset Advanced Input Mode for the primary port and use it only as a command port. */
157  bool unsetJAVAD_AIM_mode();
158 
159  // MAR'11 -------------------------------------
160  inline bool useExternCOM() { return (m_out_COM!=NULL); }
161  // --------------------------------------------
162 
163  private:
164  std::string m_COMname;
169 
170  char *m_buffer;
173 
174  std::string m_JAVAD_rtk_src_port; //!< If not empty, will send a cmd "set,/par/pos/pd/port,...". Example value: "/dev/ser/b"
175  unsigned int m_JAVAD_rtk_src_baud; //!< Only used when "m_JAVAD_rtk_src_port" is not empty
176  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.
177 
178  // MAR'11 -----------------------------------------
179  bool m_useAIMMode; //!< Use this mode for receive RTK corrections from a external source through the primary port
180  // ------------------------------------------------
182 
183  // MAR'11 -----------------------------------------
184  bool m_AIMConfigured; //!< Indicates if the AIM has been properly set up.
185  double m_data_period; //!< The period in seconds which the data should be provided by the GPS
186  // ------------------------------------------------
187 
188  /** Returns true if the COM port is already open, or try to open it in other case.
189  * \return true if everything goes OK, or false if there are problems opening the port.
190  */
191  bool tryToOpenTheCOM();
192 
193  /** Process data in "m_buffer" to extract GPS messages, and remove them from the buffer.
194  */
195  void processBuffer();
196 
197  /** Process a complete string from the GPS:
198  */
199  void processGPSstring( const std::string &s);
200 
201  /** Tokenize a string "str" into commas separated tokens
202  */
203  void getNextToken(
204  const std::string &str,
205  std::string &token,
206  unsigned int &parserPos);
207 
208  /* A private copy of the last received gps datum:
209  */
212 
213  void JAVAD_sendMessage(const char*str, bool waitForAnswer = true); //!< Private auxiliary method. Raises exception on error.
214 
215  }; // end class
216 
217  } // end namespace
218 } // end namespace
219 
220 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013