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://www.mrpt.org/                                |
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                   * \ingroup mrpt_hwdrivers_grp
00077                 */
00078                 class HWDRIVERS_IMPEXP CGPSInterface : public utils::CDebugOutputCapable, public CGenericSensor
00079                 {
00080                         DEFINE_GENERIC_SENSOR(CGPSInterface)
00081 
00082                 public:
00083                         /** Constructor
00084                           * \param BUFFER_LENGTH The size of the communications buffer (default value should be fine always)
00085                           */
00086 //                      CGPSInterface( int BUFFER_LENGTH = 500 );
00087 
00088                         // MAR'11 -------------------------------------
00089                         CGPSInterface( int BUFFER_LENGTH = 500, mrpt::hwdrivers::CSerialPort *outPort = NULL, mrpt::synch::CCriticalSection *csOutPort = NULL);
00090             // --------------------------------------------
00091 
00092                         /** Destructor
00093                           */
00094                         virtual ~CGPSInterface();
00095 
00096                         /** This method should be called periodically (at least at 1Hz to capture ALL the real-time data)
00097                         *  It is thread safe, i.e. you can call this from one thread, then to other methods from other threads.
00098                         *  This method processes data from the GPS and update the object state accordingly.
00099                         */
00100                         void  doProcess();
00101 
00102                         /** Returns true if communications work.
00103                         */
00104                         bool  isGPS_connected();
00105 
00106                         /** Returns true if the last message from the GPS indicates that the signal from sats has been acquired.
00107                         */
00108                         bool  isGPS_signalAcquired();
00109 
00110                         void  setSerialPortName(const std::string &COM_port);  //!< Set the serial port to use (COM1, ttyUSB0, etc).
00111                         std::string getSerialPortName() const;  //!< Get the serial port to use (COM1, ttyUSB0, etc).
00112 
00113                         inline void setExternCOM( CSerialPort *outPort, mrpt::synch::CCriticalSection *csOutPort )
00114                         { m_out_COM = outPort; m_cs_out_COM = csOutPort; }
00115 
00116                         inline bool isAIMConfigured() { return m_AIMConfigured; }
00117 
00118                 protected:
00119                         /** Implements custom messages to be sent to the GPS unit just after connection and before normal use.
00120                           *  Returns false or raise an exception if something goes wrong.
00121                           */
00122                         bool OnConnectionEstablished();
00123 
00124                         CSerialPort             m_COM;
00125 
00126             // MAR'11 -------------------------------------
00127                         CSerialPort                             *m_out_COM;
00128             mrpt::synch::CCriticalSection   *m_cs_out_COM;
00129                         // --------------------------------------------
00130 
00131                         poses::CPoint3D m_sensorPose;
00132 
00133                         std::string             m_customInit;
00134 
00135                         /** 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)
00136                           *  See hwdrivers::CGPSInterface for the possible parameters
00137                           */
00138                         void  loadConfig_sensorSpecific(
00139                                 const mrpt::utils::CConfigFileBase &configSource,
00140                                 const std::string         &iniSection );
00141 
00142                         /** If not empty, will send a cmd "set,/par/pos/pd/port,...". Example value: "/dev/ser/b" */
00143                         void setJAVAD_rtk_src_port( const std::string &s) { m_JAVAD_rtk_src_port = s; }
00144 
00145                         /** Only used when "m_JAVAD_rtk_src_port" is not empty */
00146                         void setJAVAD_rtk_src_baud(unsigned int baud) { m_JAVAD_rtk_src_baud = baud; }
00147 
00148                         /** Only used when "m_JAVAD_rtk_src_port" is not empty: format of RTK corrections: "cmr", "rtcm", "rtcm3", etc. */
00149                         void setJAVAD_rtk_format(const std::string &s) {m_JAVAD_rtk_format=s;}
00150 
00151                         /** Set Advanced Input Mode for the primary port.
00152                 This can be used to send RTK corrections to the device using the same port that it's used for the commands.
00153                 The RTK correction stream must be re-packaged into a special frame with prefix ">>" */
00154             bool setJAVAD_AIM_mode();
00155 
00156                         /** Unset Advanced Input Mode for the primary port and use it only as a command port. */
00157             bool unsetJAVAD_AIM_mode();
00158 
00159             // MAR'11 -------------------------------------
00160             inline bool useExternCOM() { return (m_out_COM!=NULL); }
00161             // --------------------------------------------
00162 
00163                 private:
00164                         std::string     m_COMname;
00165                         int                             m_COMbauds;
00166                         bool                    m_GPS_comsWork;
00167                         bool                    m_GPS_signalAcquired;
00168                         int                             m_BUFFER_LENGTH;
00169 
00170                         char                    *m_buffer;
00171                         size_t                  m_bufferLength;
00172                         size_t                  m_bufferWritePos;
00173 
00174                         std::string             m_JAVAD_rtk_src_port;   //!< If not empty, will send a cmd "set,/par/pos/pd/port,...". Example value: "/dev/ser/b"
00175                         unsigned int    m_JAVAD_rtk_src_baud;   //!< Only used when "m_JAVAD_rtk_src_port" is not empty
00176                         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.
00177 
00178                         // MAR'11 -----------------------------------------
00179                         bool            m_useAIMMode;           //!< Use this mode for receive RTK corrections from a external source through the primary port
00180             // ------------------------------------------------
00181                         TTimeStamp      m_last_timestamp;
00182 
00183                         // MAR'11 -----------------------------------------
00184                         bool            m_AIMConfigured;        //!< Indicates if the AIM has been properly set up.
00185                         double          m_data_period;          //!< The period in seconds which the data should be provided by the GPS
00186             // ------------------------------------------------
00187 
00188                         /** Returns true if the COM port is already open, or try to open it in other case.
00189                           * \return true if everything goes OK, or false if there are problems opening the port.
00190                           */
00191                         bool  tryToOpenTheCOM();
00192 
00193                         /** Process data in "m_buffer" to extract GPS messages, and remove them from the buffer.
00194                           */
00195                         void  processBuffer();
00196 
00197                         /** Process a complete string from the GPS:
00198                           */
00199                         void  processGPSstring( const std::string &s);
00200 
00201                         /** Tokenize a string "str" into commas separated tokens
00202                           */
00203                         void  getNextToken(
00204                                 const std::string       &str,
00205                                 std::string                     &token,
00206                                 unsigned int            &parserPos);
00207 
00208                         /* A private copy of the last received gps datum:
00209                          */
00210                         mrpt::slam::CObservationGPS                 m_latestGPS_data;
00211                         mrpt::slam::CObservationGPS::TUTCTime   m_last_UTC_time;
00212 
00213                         void JAVAD_sendMessage(const char*str, bool waitForAnswer = true); //!< Private auxiliary method. Raises exception on error.
00214 
00215                 }; // end class
00216 
00217         } // end namespace
00218 } // end namespace
00219 
00220 #endif



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011