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://babel.isa.uma.es/mrpt/index.php/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 HWDLLIMPEXP 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 /** Enables the SCIP2.0 protocol (this must be called at the very begining!). 00105 * \return false on any error 00106 */ 00107 bool enableSCIP20(); 00108 00109 /** Passes to 115200bps bitrate. 00110 * \return false on any error 00111 */ 00112 bool setHighBaudrate(); 00113 00114 /** Switchs the laser on. 00115 * \return false on any error 00116 */ 00117 bool switchLaserOn(); 00118 00119 /** Switchs the laser off 00120 * \return false on any error 00121 */ 00122 bool switchLaserOff(); 00123 00124 /** Changes the motor speed in rpm's (default 600rpm) 00125 * \return false on any error 00126 */ 00127 bool setMotorSpeed(int motoSpeed_rpm); 00128 00129 /** Ask to the device, and print to the debug stream, details about the firmware version,serial number,... 00130 * \return false on any error 00131 */ 00132 bool displayVersionInfo( ); 00133 00134 /** Ask to the device, and print to the debug stream, details about the sensor model. 00135 * It also optionally saves all the information in an user supplied data structure "out_data". 00136 * \return false on any error 00137 */ 00138 bool displaySensorInfo( CHokuyoURG::TSensorInfo * out_data = NULL ); 00139 00140 /** Start the scanning mode, using parameters stored in the object (loaded from the .ini file) 00141 * After this command the device will start to send scans until "switchLaserOff" is called. 00142 * \return false on any error 00143 */ 00144 bool startScanningMode(); 00145 00146 /** Turns the laser on */ 00147 void initialize(); 00148 00149 /** Waits for a response from the device. 00150 * \return false on any error 00151 */ 00152 bool receiveResponse( 00153 const char *sentCmd_forEchoVerification, 00154 char &rcv_status0, 00155 char &rcv_status1, 00156 char *rcv_data, 00157 int &rcv_dataLength); 00158 00159 00160 /** Assures a minimum number of bytes in the input buffer, reading from the serial port only if required. 00161 * \return false if the number of bytes are not available, even after trying to fetch more data from the serial port. 00162 */ 00163 bool assureBufferHasBytes(const size_t nDesiredBytes); 00164 00165 public: 00166 /** Constructor 00167 */ 00168 CHokuyoURG(); 00169 00170 /** Destructor: turns the laser off */ 00171 virtual ~CHokuyoURG(); 00172 00173 /** Specific laser scanner "software drivers" must process here new data from the I/O stream, and, if a whole scan has arrived, return it. 00174 * This method will be typically called in a different thread than other methods, and will be called in a timely fashion. 00175 */ 00176 void doProcessSimple( 00177 bool &outThereIsObservation, 00178 mrpt::slam::CObservation2DRangeScan &outObservation, 00179 bool &hardwareError ); 00180 00181 /** 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. 00182 * \return If everything works "true", or "false" if there is any error. 00183 */ 00184 bool turnOn(); 00185 00186 /** Disables the scanning mode (this can be used to turn the device in low energy mode, if available) 00187 * \return If everything works "true", or "false" if there is any error. 00188 */ 00189 bool turnOff(); 00190 00191 /** Empties the RX buffers of the serial port */ 00192 void purgeBuffers(); 00193 00194 /** 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. */ 00195 void setSerialPort(const std::string &port_name) { m_com_port = port_name; } 00196 00197 /** Returns the currently set serial port \sa setSerialPort */ 00198 const std::string getSerialPort() { return m_com_port; } 00199 00200 /** 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. 00201 * Call with "0" to disable this reduction again (the default). 00202 */ 00203 void setReducedFOV(const double fov) { m_reduced_fov = fov; } 00204 00205 00206 protected: 00207 /** 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" 00208 */ 00209 bool checkCOMisOpen(); 00210 00211 double m_reduced_fov; //!< Used to reduce artificially the interval of scan ranges. 00212 00213 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. 00214 00215 /** The information gathered when the laser is first open */ 00216 TSensorInfo m_sensor_info; 00217 00218 bool m_I_am_owner_serial_port; 00219 00220 uint32_t m_timeStartUI; //!< Time of the first data packet, for synchronization purposes. 00221 mrpt::system::TTimeStamp m_timeStartTT; 00222 00223 std::string m_sensorLabel; 00224 00225 /** 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) 00226 * See hwdrivers::CHokuyoURG for the possible parameters 00227 */ 00228 void loadConfig_sensorSpecific( 00229 const mrpt::utils::CConfigFileBase &configSource, 00230 const std::string &iniSection ); 00231 00232 }; // End of class 00233 00234 } // End of namespace 00235 00236 } // End of namespace 00237 00238 #endif
| Page generated by Doxygen 1.6.2 for MRPT 0.8.1 SVN:exported at Mon Feb 15 22:01:07 UTC 2010 |
