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 CHokuyoURG_H 00029 #define CHokuyoURG_H 00030 00031 #include <mrpt/poses/CPose3D.h> 00032 #include <mrpt/hwdrivers/C2DRangeFinderAbstract.h> 00033 #include <mrpt/utils/stl_extensions.h> 00034 00035 namespace mrpt 00036 { 00037 namespace hwdrivers 00038 { 00039 /** This software driver implements the protocol SCIP-2.0 for interfacing HOKUYO URG and UTM laser scanners. 00040 * Refer to the wiki page for more details: 00041 * http://www.mrpt.org/Example:HOKUYO_URG/UTM_Laser_Scanner 00042 * 00043 * See also the application "rawlog-grabber" for a ready-to-use application to gather data from the scanner. 00044 * 00045 * \code 00046 * PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS: 00047 * ------------------------------------------------------- 00048 * [supplied_section_name] 00049 * HOKUYO_motorSpeed_rpm=600 00050 * COM_port_WIN = COM3 00051 * COM_port_LIN = ttyS0 00052 * pose_x=0.21 ; Laser range scaner 3D position in the robot (meters) 00053 * pose_y=0 00054 * pose_z=0.34 00055 * pose_yaw=0 ; Angles in degrees 00056 * pose_pitch=0 00057 * pose_roll=0 00058 * 00059 * // Optional: reduced FOV: 00060 * // reduced_fov = 25 // Deg 00061 * 00062 * // Optional: Exclusion zones to avoid the robot seeing itself: 00063 * //exclusionZone1_x = 0.20 0.30 0.30 0.20 00064 * //exclusionZone1_y = 0.20 0.30 0.30 0.20 00065 * 00066 * // Optional: Exclusion zones to avoid the robot seeing itself: 00067 * //exclusionAngles1_ini = 20 // Deg 00068 * //exclusionAngles1_end = 25 // Deg 00069 * 00070 * \endcode 00071 */ 00072 class HWDRIVERS_IMPEXP CHokuyoURG : public C2DRangeFinderAbstract 00073 { 00074 DEFINE_GENERIC_SENSOR(CHokuyoURG) 00075 public: 00076 00077 /** Used in CHokuyoURG::displayVersionInfo */ 00078 struct TSensorInfo 00079 { 00080 std::string model; //!< The sensor model 00081 double d_min,d_max; //!< Min/Max ranges, in meters. 00082 int scans_per_360deg; //!< Number of measuremens per 360 degrees. 00083 int scan_first,scan_last, scan_front; //!< First, last, and front step of the scanner angular span. 00084 int motor_speed_rpm; //!< Standard motor speed, rpm. 00085 }; 00086 00087 private: 00088 /** The first and last ranges to consider from the scan. 00089 */ 00090 int m_firstRange,m_lastRange; 00091 00092 /** The motor speed (default=600rpm) 00093 */ 00094 int m_motorSpeed_rpm; 00095 00096 /** The sensor 6D pose: 00097 */ 00098 poses::CPose3D m_sensorPose; 00099 00100 mrpt::utils::circular_buffer<uint8_t> m_rx_buffer; //!< Auxiliary buffer for readings 00101 00102 std::string m_lastSentMeasCmd; //!< The last sent measurement command (MDXXX), including the last 0x0A. 00103 00104 bool m_verbose; 00105 00106 /** Enables the SCIP2.0 protocol (this must be called at the very begining!). 00107 * \return false on any error 00108 */ 00109 bool enableSCIP20(); 00110 00111 /** Passes to 115200bps bitrate. 00112 * \return false on any error 00113 */ 00114 bool setHighBaudrate(); 00115 00116 /** Switchs the laser on. 00117 * \return false on any error 00118 */ 00119 bool switchLaserOn(); 00120 00121 /** Switchs the laser off 00122 * \return false on any error 00123 */ 00124 bool switchLaserOff(); 00125 00126 /** Changes the motor speed in rpm's (default 600rpm) 00127 * \return false on any error 00128 */ 00129 bool setMotorSpeed(int motoSpeed_rpm); 00130 00131 /** Ask to the device, and print to the debug stream, details about the firmware version,serial number,... 00132 * \return false on any error 00133 */ 00134 bool displayVersionInfo( ); 00135 00136 /** Ask to the device, and print to the debug stream, details about the sensor model. 00137 * It also optionally saves all the information in an user supplied data structure "out_data". 00138 * \return false on any error 00139 */ 00140 bool displaySensorInfo( CHokuyoURG::TSensorInfo * out_data = NULL ); 00141 00142 /** Start the scanning mode, using parameters stored in the object (loaded from the .ini file) 00143 * After this command the device will start to send scans until "switchLaserOff" is called. 00144 * \return false on any error 00145 */ 00146 bool startScanningMode(); 00147 00148 /** Turns the laser on */ 00149 void initialize(); 00150 00151 /** Waits for a response from the device. 00152 * \return false on any error 00153 */ 00154 bool receiveResponse( 00155 const char *sentCmd_forEchoVerification, 00156 char &rcv_status0, 00157 char &rcv_status1, 00158 char *rcv_data, 00159 int &rcv_dataLength); 00160 00161 00162 /** Assures a minimum number of bytes in the input buffer, reading from the serial port only if required. 00163 * \return false if the number of bytes are not available, even after trying to fetch more data from the serial port. 00164 */ 00165 bool assureBufferHasBytes(const size_t nDesiredBytes); 00166 00167 public: 00168 /** Constructor 00169 */ 00170 CHokuyoURG(); 00171 00172 /** Destructor: turns the laser off */ 00173 virtual ~CHokuyoURG(); 00174 00175 /** Specific laser scanner "software drivers" must process here new data from the I/O stream, and, if a whole scan has arrived, return it. 00176 * This method will be typically called in a different thread than other methods, and will be called in a timely fashion. 00177 */ 00178 void doProcessSimple( 00179 bool &outThereIsObservation, 00180 mrpt::slam::CObservation2DRangeScan &outObservation, 00181 bool &hardwareError ); 00182 00183 /** Enables the scanning mode (which may depend on the specific laser device); this must be called before asking for observations to assure that the protocol has been initializated. 00184 * \return If everything works "true", or "false" if there is any error. 00185 */ 00186 bool turnOn(); 00187 00188 /** Disables the scanning mode (this can be used to turn the device in low energy mode, if available) 00189 * \return If everything works "true", or "false" if there is any error. 00190 */ 00191 bool turnOff(); 00192 00193 /** Empties the RX buffers of the serial port */ 00194 void purgeBuffers(); 00195 00196 /** 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. */ 00197 void setSerialPort(const std::string &port_name) { m_com_port = port_name; } 00198 00199 /** Returns the currently set serial port \sa setSerialPort */ 00200 const std::string getSerialPort() { return m_com_port; } 00201 00202 /** If called (before calling "turnOn"), the field of view of the laser is reduced to the given range (in radians), discarding the rest of measures. 00203 * Call with "0" to disable this reduction again (the default). 00204 */ 00205 void setReducedFOV(const double fov) { m_reduced_fov = fov; } 00206 00207 void setVerbose(bool enable = true) { m_verbose = enable; } 00208 00209 00210 protected: 00211 /** Returns true if there is a valid stream bound to the laser scanner, otherwise it first try to open the serial port "m_com_port" 00212 */ 00213 bool checkCOMisOpen(); 00214 00215 double m_reduced_fov; //!< Used to reduce artificially the interval of scan ranges. 00216 00217 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. 00218 00219 /** The information gathered when the laser is first open */ 00220 TSensorInfo m_sensor_info; 00221 00222 bool m_I_am_owner_serial_port; 00223 00224 uint32_t m_timeStartUI; //!< Time of the first data packet, for synchronization purposes. 00225 mrpt::system::TTimeStamp m_timeStartTT; 00226 00227 std::string m_sensorLabel; 00228 00229 /** 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) 00230 * See hwdrivers::CHokuyoURG for the possible parameters 00231 */ 00232 void loadConfig_sensorSpecific( 00233 const mrpt::utils::CConfigFileBase &configSource, 00234 const std::string &iniSection ); 00235 00236 }; // End of class 00237 00238 } // End of namespace 00239 00240 } // End of namespace 00241 00242 #endif
| Page generated by Doxygen 1.6.1 for MRPT 0.9.0 SVN: at Mon Jun 7 06:47:58 UTC 2010 |
