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 HWDLLIMPEXP 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 00106 protected: 00107 /** 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) 00108 * See hwdrivers::CSickLaserSerial for the possible parameters 00109 */ 00110 void loadConfig_sensorSpecific( 00111 const mrpt::utils::CConfigFileBase &configSource, 00112 const std::string &iniSection ); 00113 00114 public: 00115 /** Constructor */ 00116 CSickLaserSerial(); 00117 00118 /** Destructor */ 00119 virtual ~CSickLaserSerial(); 00120 00121 /** Changes the serial port to connect to (call prior to 'doProcess'), for example "COM1" or "ttyS0". 00122 * This is not needed if the configuration is loaded with "loadConfig". 00123 */ 00124 void setSerialPort(const std::string &port) { m_com_port = port; } 00125 00126 /** \sa setSerialPort */ 00127 std::string getSerialPort() const { return m_com_port; } 00128 00129 /** Changes the serial port baud rate (call prior to 'doProcess'); valid values are 9600,38400 and 500000. 00130 * This is not needed if the configuration is loaded with "loadConfig". 00131 * \sa getBaudRate */ 00132 void setBaudRate(int baud) { 00133 m_com_baudRate = baud; 00134 } 00135 /** \sa setBaudRate */ 00136 int getBaudRate() const { return m_com_baudRate; } 00137 00138 00139 /** Enables/Disables the millimeter mode, with a greater accuracy but a shorter range (default=false) 00140 * (call prior to 'doProcess') This is not needed if the configuration is loaded with "loadConfig". 00141 */ 00142 void setMillimeterMode(bool mm_mode=true) { m_mm_mode = mm_mode; } 00143 00144 /** Set the scanning field of view - possible values are 100 or 180 (default) 00145 * (call prior to 'doProcess') This is not needed if the configuration is loaded with "loadConfig". 00146 */ 00147 void setScanFOV(int fov_degrees) { m_scans_FOV = fov_degrees; } 00148 int getScanFOV() const { return m_scans_FOV; } 00149 00150 /** 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. 00151 * (call prior to 'doProcess') This is not needed if the configuration is loaded with "loadConfig". 00152 */ 00153 void setScanResolution(int res_1_100th_degree) { m_scans_res=res_1_100th_degree; } 00154 int getScanResolution() const { return m_scans_res; } 00155 00156 00157 /** Specific laser scanner "software drivers" must process here new data from the I/O stream, and, if a whole scan has arrived, return it. 00158 * This method will be typically called in a different thread than other methods, and will be called in a timely fashion. 00159 */ 00160 void doProcessSimple( 00161 bool &outThereIsObservation, 00162 mrpt::slam::CObservation2DRangeScan &outObservation, 00163 bool &hardwareError ); 00164 00165 00166 /** Set-up communication with the laser. 00167 * Called automatically by rawlog-grabber. 00168 * If used manually, call after "loadConfig" and before "doProcess". 00169 * 00170 * In this class this method does nothing, since the communications are setup at the first try from "doProcess" or "doProcessSimple". 00171 */ 00172 void initialize(); 00173 00174 /** Enables the scanning mode (in this class this has no effect). 00175 * \return If everything works "true", or "false" if there is any error. 00176 */ 00177 bool turnOn(); 00178 00179 /** Disables 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 turnOff(); 00183 00184 }; // End of class 00185 00186 } // End of namespace 00187 } // End of namespace 00188 00189 #endif
| Page generated by Doxygen 1.6.2 for MRPT 0.8.1 SVN:exported at Mon Feb 15 22:01:07 UTC 2010 |
