00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2009 University of Malaga | 00007 | | 00008 | This software was written by the Perception and Robotics | 00009 | research group, 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 * 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 = 00058 * 00059 * \endcode 00060 * 00061 * - customInit: Custom commands to send, depending on the sensor. Valid values are: 00062 * - "": Empty string 00063 * - "JAVAD": JAVAD devices. 00064 * 00065 * VERSIONS HISTORY: 00066 * -9/JUN/2006: First version (JLBC) 00067 * -4/JUN/2008: Added virtual methods for device-specific initialization commands. 00068 * -10/JUN/2008: Converted into CGenericSensor class (there are no inhirited classes anymore). 00069 */ 00070 class HWDLLIMPEXP CGPSInterface : public utils::CDebugOutputCapable, public CGenericSensor 00071 { 00072 DEFINE_GENERIC_SENSOR(CGPSInterface) 00073 00074 public: 00075 /** Constructor 00076 * \param BUFFER_LENGTH The size of the communications buffer (default value should be fine always) 00077 */ 00078 CGPSInterface( int BUFFER_LENGTH = 500 ); 00079 00080 /** Destructor 00081 */ 00082 virtual ~CGPSInterface(); 00083 00084 /** This method should be called periodically (at least at 1Hz to capture ALL the real-time data) 00085 * It is thread safe, i.e. you can call this from one thread, then to other methods from other threads. 00086 * This method processes data from the GPS and update the object state accordingly. 00087 */ 00088 void doProcess(); 00089 00090 /** 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) 00091 * See hwdrivers::CGPSInterface for the possible parameters 00092 */ 00093 void loadConfig( 00094 const mrpt::utils::CConfigFileBase &configSource, 00095 const std::string &iniSection ); 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 /* This will be NULL on any error opening the com port: 00115 */ 00116 CSerialPort *m_COM; 00117 00118 poses::CPoint3D m_sensorPose; 00119 00120 std::string m_sensorLabel; 00121 std::string m_customInit; 00122 00123 private: 00124 std::string m_COMname; 00125 int m_COMbauds; 00126 bool m_GPS_comsWork; 00127 bool m_GPS_signalAcquired; 00128 int m_BUFFER_LENGTH; 00129 00130 char *m_buffer; 00131 size_t m_bufferLength; 00132 size_t m_bufferWritePos; 00133 00134 /** Returns true if the COM port is already open, or try to open it in other case. 00135 * \return true if everything goes OK, or false if there are problems opening the port. 00136 */ 00137 bool tryToOpenTheCOM(); 00138 00139 /** Process data in "m_buffer" to extract GPS messages, and remove them from the buffer. 00140 */ 00141 void processBuffer(); 00142 00143 /** Process a complete string from the GPS: 00144 */ 00145 void processGPSstring( const std::string &s); 00146 00147 /** Tokenize a string "str" into commas separated tokens 00148 */ 00149 void getNextToken( 00150 const std::string &str, 00151 std::string &token, 00152 unsigned int &parserPos); 00153 00154 /* A private copy of the last received gps datum: 00155 */ 00156 mrpt::slam::CObservationGPS m_latestGPS_data; 00157 00158 }; // end class 00159 00160 } // end namespace 00161 } // end namespace 00162 00163 #endif
Page generated by Doxygen 1.5.7.1 for MRPT 0.7.1 SVN: at Mon Aug 17 23:10:56 EDT 2009 |