00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2010 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 #ifndef CSickLaserSerial_H 00029 #define CSickLaserSerial_H 00030 00031 #include <mrpt/hwdrivers/C2DRangeFinderAbstract.h> 00032 #include <mrpt/hwdrivers/CSerialPort.h> 00033 00034 namespace mrpt 00035 { 00036 namespace hwdrivers 00037 { 00038 /** This "software driver" implements the communication protocol for interfacing a SICK LMS 2XX laser scanners through a standard RS232 serial port (or a USB2SERIAL converter). 00039 * The serial port is opened upon the first call to "doProcess" or "initialize", so you must call "loadConfig" before 00040 * this, or manually call "setSerialPort". Another alternative is to call the base class method C2DRangeFinderAbstract::bindIO, 00041 * but the "setSerialPort" interface is probably much simpler to use. 00042 * 00043 * For an example of usage see the example in "samples/SICK_laser_serial_test". 00044 * See also the example configuration file for rawlog-grabber in "share/mrpt/config_files/rawlog-grabber". 00045 * 00046 * \code 00047 * PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS: 00048 * ------------------------------------------------------- 00049 * [supplied_section_name] 00050 * COM_port_WIN = COM1 // Serial port to connect to 00051 * COM_port_LIN = ttyS0 00052 * 00053 * COM_baudRate = 38400 // Possible values: 9600 (default), 38400, 5000000 00054 * mm_mode = 1/0 // 1: millimeter mode, 0:centimeter mode (Default=0) 00055 * FOV = 180 // Field of view: 100 or 180 degrees (Default=180) 00056 * resolution = 50 // Scanning resolution, in units of 1/100 degree. Valid values: 25,50,100 (Default=50) 00057 * 00058 * 00059 * pose_x=0.21 // Laser range scaner 3D position in the robot (meters) 00060 * pose_y=0 00061 * pose_z=0.34 00062 * pose_yaw=0 // Angles in degrees 00063 * pose_pitch=0 00064 * pose_roll=0 00065 * \endcode 00066 * 00067 * \sa C2DRangeFinderAbstract 00068 */ 00069 class HWDRIVERS_IMPEXP CSickLaserSerial : public C2DRangeFinderAbstract 00070 { 00071 DEFINE_GENERIC_SENSOR(CSickLaserSerial) 00072 00073 private: 00074 bool m_mm_mode; 00075 int m_scans_FOV; //!< 100 or 180 deg 00076 int m_scans_res; //!< 1/100th of deg: 100, 50 or 25 00077 00078 /** The sensor 6D pose: */ 00079 poses::TPose3D m_sensorPose; 00080 00081 static int CRC16_GEN_POL; 00082 00083 00084 bool tryToOpenComms(std::string *err_msg=NULL); //!< Tries to open the com port and setup all the LMS protocol. Returns true if OK or already open. 00085 bool waitContinuousSampleFrame( vector_float &ranges, unsigned char &LMS_status, bool &is_mm_mode ); 00086 00087 00088 bool LMS_setupSerialComms(); //!< Assures laser is connected and operating at 38400, in its case returns true. 00089 bool LMS_setupBaudrate(int baud); //!< Send a command to change the LMS comms baudrate, return true if ACK is OK. baud can be: 9600, 19200, 38400, 500000 00090 bool LMS_statusQuery(); //!< Send a status query and wait for the answer. Return true on OK. 00091 bool LMS_waitACK(uint16_t timeout_ms); //!< Returns false if timeout 00092 bool LMS_waitIncomingFrame(uint16_t timeout); //!< Returns false if timeout 00093 bool LMS_sendMeasuringMode_cm_mm(); //!< Returns false on error 00094 bool LMS_startContinuousMode(); 00095 bool LMS_endContinuousMode(); 00096 00097 bool SendCommandToSICK(const uint8_t *cmd,const uint16_t cmd_len); //!< Send header+command-data+crc and waits for ACK. Return false on error. 00098 00099 uint8_t m_received_frame_buffer[2000]; 00100 00101 std::string m_com_port; //!< If set to non-empty, the serial port will be attempted to be opened automatically when this class is first used to request data from the laser. 00102 CSerialPort *m_mySerialPort; //!< Will be !=NULL only if I created it, so I must destroy it at the end. 00103 std::string m_sensorLabel; 00104 int m_com_baudRate; //!< Baudrate: 9600, 38400, 500000 00105 unsigned int m_nTries_connect; //!< Default = 1 00106 unsigned int m_nTries_current; 00107 00108 protected: 00109 /** 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) 00110 * See hwdrivers::CSickLaserSerial for the possible parameters 00111 */ 00112 void loadConfig_sensorSpecific( 00113 const mrpt::utils::CConfigFileBase &configSource, 00114 const std::string &iniSection ); 00115 00116 public: 00117 /** Constructor */ 00118 CSickLaserSerial(); 00119 00120 /** Destructor */ 00121 virtual ~CSickLaserSerial(); 00122 00123 /** Changes the serial port to connect to (call prior to 'doProcess'), for example "COM1" or "ttyS0". 00124 * This is not needed if the configuration is loaded with "loadConfig". 00125 */ 00126 void setSerialPort(const std::string &port) { m_com_port = port; } 00127 00128 /** \sa setSerialPort */ 00129 std::string getSerialPort() const { return m_com_port; } 00130 00131 /** Changes the serial port baud rate (call prior to 'doProcess'); valid values are 9600,38400 and 500000. 00132 * This is not needed if the configuration is loaded with "loadConfig". 00133 * \sa getBaudRate */ 00134 void setBaudRate(int baud) { 00135 m_com_baudRate = baud; 00136 } 00137 /** \sa setBaudRate */ 00138 int getBaudRate() const { return m_com_baudRate; } 00139 00140 00141 /** Enables/Disables the millimeter mode, with a greater accuracy but a shorter range (default=false) 00142 * (call prior to 'doProcess') This is not needed if the configuration is loaded with "loadConfig". 00143 */ 00144 void setMillimeterMode(bool mm_mode=true) { m_mm_mode = mm_mode; } 00145 00146 /** Set the scanning field of view - possible values are 100 or 180 (default) 00147 * (call prior to 'doProcess') This is not needed if the configuration is loaded with "loadConfig". 00148 */ 00149 void setScanFOV(int fov_degrees) { m_scans_FOV = fov_degrees; } 00150 int getScanFOV() const { return m_scans_FOV; } 00151 00152 /** Set the scanning resolution, in units of 1/100 degree - Possible values are 25, 50 and 100, for 0.25, 0.5 (default) and 1 deg. 00153 * (call prior to 'doProcess') This is not needed if the configuration is loaded with "loadConfig". 00154 */ 00155 void setScanResolution(int res_1_100th_degree) { m_scans_res=res_1_100th_degree; } 00156 int getScanResolution() const { return m_scans_res; } 00157 00158 /** If performing several tries in ::initialize(), this is the current try loop number. */ 00159 unsigned int getCurrentConnectTry() const { return m_nTries_current; } 00160 00161 00162 /** Specific laser scanner "software drivers" must process here new data from the I/O stream, and, if a whole scan has arrived, return it. 00163 * This method will be typically called in a different thread than other methods, and will be called in a timely fashion. 00164 */ 00165 void doProcessSimple( 00166 bool &outThereIsObservation, 00167 mrpt::slam::CObservation2DRangeScan &outObservation, 00168 bool &hardwareError ); 00169 00170 00171 /** Set-up communication with the laser. 00172 * Called automatically by rawlog-grabber. 00173 * If used manually, call after "loadConfig" and before "doProcess". 00174 * 00175 * In this class this method does nothing, since the communications are setup at the first try from "doProcess" or "doProcessSimple". 00176 */ 00177 void initialize(); 00178 00179 /** Enables the scanning mode (in this class this has no effect). 00180 * \return If everything works "true", or "false" if there is any error. 00181 */ 00182 bool turnOn(); 00183 00184 /** Disables the scanning mode (in this class this has no effect). 00185 * \return If everything works "true", or "false" if there is any error. 00186 */ 00187 bool turnOff(); 00188 00189 }; // End of class 00190 00191 } // End of namespace 00192 } // End of namespace 00193 00194 #endif
| Page generated by Doxygen 1.6.1 for MRPT 0.9.0 SVN: at Mon Jun 7 06:47:58 UTC 2010 |
