Main MRPT website > C++ reference
MRPT logo

CGPSInterface.h

Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                   http://mrpt.sourceforge.net/                            |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 
00029 #ifndef CGPSInterface_H
00030 #define CGPSInterface_H
00031 
00032 #include <mrpt/slam/CObservationGPS.h>
00033 #include <mrpt/poses/CPoint3D.h>
00034 #include <mrpt/hwdrivers/CSerialPort.h>
00035 #include <mrpt/utils/CDebugOutputCapable.h>
00036 #include <mrpt/hwdrivers/CGenericSensor.h>
00037 
00038 namespace mrpt
00039 {
00040         namespace slam { class CObservationGPS; }
00041 
00042         namespace hwdrivers
00043         {
00044                 /** A parser of NMEA commands, for connecting to a GPS by a serial port.
00045                   * This class also supports more advanced GPS equipped with RTK corrections. See the JAVAD/TopCon extra initialization parameters.
00046                   *
00047                   *  \code
00048                   *  PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS:
00049                   * -------------------------------------------------------
00050                   *   [supplied_section_name]
00051                   *    COM_port_WIN = COM3
00052                   *    COM_port_LIN = ttyS0
00053                   *    baudRate     = 4800   // The baudrate of the communications (typ. 4800 bauds)
00054                   *    pose_x       = 0      // 3D position of the sensed point relative to the robot (meters)
00055                   *    pose_y       = 0
00056                   *    pose_z       = 0
00057                   *    customInit   =       // See below for possible values
00058                   *
00059                   *        // The next parameters are optional and will be used only
00060                   *    // if customInit=="JAVAD" to enable/configure the usage of RTK corrections:
00061                   *    //JAVAD_rtk_src_port=/dev/ser/b
00062                   *    //JAVAD_rtk_src_baud=9600
00063                   *    //JAVAD_rtk_format=cmr
00064                   *
00065                   *  \endcode
00066                   *
00067                   * - customInit: Custom commands to send, depending on the sensor. Valid values are:
00068                   *             - "": Empty string
00069                   *             - "JAVAD": JAVAD or TopCon devices. Extra initialization commands will be sent.
00070                   *             - "TopCon": A synonymous with "JAVAD".
00071                   *
00072                   *  VERSIONS HISTORY:
00073                   *             -9/JUN/2006: First version (JLBC)
00074                   *             -4/JUN/2008: Added virtual methods for device-specific initialization commands.
00075                   *             -10/JUN/2008: Converted into CGenericSensor class (there are no inhirited classes anymore).
00076                 */
00077                 class HWDRIVERS_IMPEXP CGPSInterface : public utils::CDebugOutputCapable, public CGenericSensor
00078                 {
00079                         DEFINE_GENERIC_SENSOR(CGPSInterface)
00080 
00081                 public:
00082                         /** Constructor
00083                           * \param BUFFER_LENGTH The size of the communications buffer (default value should be fine always)
00084                           */
00085                         CGPSInterface( int                      BUFFER_LENGTH = 500 );
00086 
00087                         /** Destructor
00088                           */
00089                         virtual ~CGPSInterface();
00090 
00091                         /** This method should be called periodically (at least at 1Hz to capture ALL the real-time data)
00092                         *  It is thread safe, i.e. you can call this from one thread, then to other methods from other threads.
00093                         *  This method processes data from the GPS and update the object state accordingly.
00094                         */
00095                         void  doProcess();
00096 
00097                         /** Returns true if communications work.
00098                         */
00099                         bool  isGPS_connected();
00100 
00101                         /** Returns true if the last message from the GPS indicates that the signal from sats has been acquired.
00102                         */
00103                         bool  isGPS_signalAcquired();
00104 
00105                         void  setSerialPortName(const std::string &COM_port);  //!< Set the serial port to use (COM1, ttyUSB0, etc).
00106                         std::string getSerialPortName() const;  //!< Get the serial port to use (COM1, ttyUSB0, etc).
00107 
00108                 protected:
00109                         /** Implements custom messages to be sent to the GPS unit just after connection and before normal use.
00110                           *  Returns false or raise an exception if something goes wrong.
00111                           */
00112                         bool OnConnectionEstablished();
00113 
00114                         CSerialPort             m_COM;
00115 
00116                         poses::CPoint3D m_sensorPose;
00117 
00118                         std::string             m_customInit;
00119 
00120                         /** 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)
00121                           *  See hwdrivers::CGPSInterface for the possible parameters
00122                           */
00123                         void  loadConfig_sensorSpecific(
00124                                 const mrpt::utils::CConfigFileBase &configSource,
00125                                 const std::string         &iniSection );
00126 
00127                         /** If not empty, will send a cmd "set,/par/pos/pd/port,...". Example value: "/dev/ser/b" */
00128                         void setJAVAD_rtk_src_port( const std::string &s) { m_JAVAD_rtk_src_port = s; }
00129 
00130                         /** Only used when "m_JAVAD_rtk_src_port" is not empty */
00131                         void setJAVAD_rtk_src_baud(unsigned int baud) { m_JAVAD_rtk_src_baud = baud; }
00132 
00133                         /** Only used when "m_JAVAD_rtk_src_port" is not empty: format of RTK corrections: "cmr", "rtcm", "rtcm3", etc. */
00134                         void setJAVAD_rtk_format(const std::string &s) {m_JAVAD_rtk_format=s;}
00135 
00136                 private:
00137                         std::string     m_COMname;
00138                         int                             m_COMbauds;
00139                         bool                    m_GPS_comsWork;
00140                         bool                    m_GPS_signalAcquired;
00141                         int                             m_BUFFER_LENGTH;
00142 
00143                         char                    *m_buffer;
00144                         size_t                  m_bufferLength;
00145                         size_t                  m_bufferWritePos;
00146 
00147                         std::string             m_JAVAD_rtk_src_port;   //!< If not empty, will send a cmd "set,/par/pos/pd/port,...". Example value: "/dev/ser/b"
00148                         unsigned int    m_JAVAD_rtk_src_baud;   //!< Only used when "m_JAVAD_rtk_src_port" is not empty
00149                         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.
00150 
00151                         /** Returns true if the COM port is already open, or try to open it in other case.
00152                           * \return true if everything goes OK, or false if there are problems opening the port.
00153                           */
00154                         bool  tryToOpenTheCOM();
00155 
00156                         /** Process data in "m_buffer" to extract GPS messages, and remove them from the buffer.
00157                           */
00158                         void  processBuffer();
00159 
00160                         /** Process a complete string from the GPS:
00161                           */
00162                         void  processGPSstring( const std::string &s);
00163 
00164                         /** Tokenize a string "str" into commas separated tokens
00165                           */
00166                         void  getNextToken(
00167                                 const std::string       &str,
00168                                 std::string                     &token,
00169                                 unsigned int            &parserPos);
00170 
00171                         /* A private copy of the last received gps datum:
00172                          */
00173                         mrpt::slam::CObservationGPS     m_latestGPS_data;
00174 
00175                         void JAVAD_sendMessage(const char*str, bool waitForAnswer = true); //!< Private auxiliary method. Raises exception on error.
00176 
00177                 }; // end class
00178 
00179         } // end namespace
00180 } // end namespace
00181 
00182 #endif



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN:exported at Tue Jan 25 21:56:31 UTC 2011