00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://www.mrpt.org/ | 00005 | | 00006 | Copyright (C) 2005-2011 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, UTM and UXM 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 * //HOKUYO_HS_mode = false // Optional (un-comment line if used): Set/unset the High-sensitivity mode (not on all models/firmwares!) 00051 * COM_port_WIN = COM3 00052 * COM_port_LIN = ttyS0 00053 * pose_x=0.21 // Laser range scaner 3D position in the robot (meters) 00054 * pose_y=0 00055 * pose_z=0.34 00056 * pose_yaw=0 // Angles in degrees 00057 * pose_pitch=0 00058 * pose_roll=0 00059 * //IP_DIR = 192.168.0.10 // Uncommented this and "PORT_DIR" if the used HOKUYO is connected by Ethernet instead of USB 00060 * //PORT_DIR = 10940 00061 * 00062 * // Optional: reduced FOV: 00063 * // reduced_fov = 25 // Deg 00064 * 00065 * // Optional: Exclusion zones to avoid the robot seeing itself: 00066 * //exclusionZone1_x = 0.20 0.30 0.30 0.20 00067 * //exclusionZone1_y = 0.20 0.30 0.30 0.20 00068 * 00069 * // Optional: Exclusion zones to avoid the robot seeing itself: 00070 * //exclusionAngles1_ini = 20 // Deg 00071 * //exclusionAngles1_end = 25 // Deg 00072 * 00073 * \endcode 00074 * \ingroup mrpt_hwdrivers_grp 00075 */ 00076 class HWDRIVERS_IMPEXP CHokuyoURG : public C2DRangeFinderAbstract 00077 { 00078 DEFINE_GENERIC_SENSOR(CHokuyoURG) 00079 public: 00080 00081 /** Used in CHokuyoURG::displayVersionInfo */ 00082 struct TSensorInfo 00083 { 00084 std::string model; //!< The sensor model 00085 double d_min,d_max; //!< Min/Max ranges, in meters. 00086 int scans_per_360deg; //!< Number of measuremens per 360 degrees. 00087 int scan_first,scan_last, scan_front; //!< First, last, and front step of the scanner angular span. 00088 int motor_speed_rpm; //!< Standard motor speed, rpm. 00089 }; 00090 00091 private: 00092 int m_firstRange,m_lastRange; //!< The first and last ranges to consider from the scan. 00093 int m_motorSpeed_rpm; //!< The motor speed (default=600rpm) 00094 poses::CPose3D m_sensorPose; //!< The sensor 6D pose: 00095 mrpt::utils::circular_buffer<uint8_t> m_rx_buffer; //!< Auxiliary buffer for readings 00096 00097 std::string m_lastSentMeasCmd; //!< The last sent measurement command (MDXXX), including the last 0x0A. 00098 00099 bool m_verbose; 00100 bool m_highSensMode; //!< High sensitivity [HS] mode (default: false) 00101 00102 /** Enables the SCIP2.0 protocol (this must be called at the very begining!). 00103 * \return false on any error 00104 */ 00105 bool enableSCIP20(); 00106 00107 /** Passes to 115200bps bitrate. 00108 * \return false on any error 00109 */ 00110 bool setHighBaudrate(); 00111 00112 /** Switchs the laser on. 00113 * \return false on any error 00114 */ 00115 bool switchLaserOn(); 00116 00117 /** Switchs the laser off 00118 * \return false on any error 00119 */ 00120 bool switchLaserOff(); 00121 00122 /** Changes the motor speed in rpm's (default 600rpm) 00123 * \return false on any error 00124 */ 00125 bool setMotorSpeed(int motoSpeed_rpm); 00126 00127 /** Ask to the device, and print to the debug stream, details about the firmware version,serial number,... 00128 * \return false on any error 00129 */ 00130 bool displayVersionInfo( ); 00131 00132 /** Ask to the device, and print to the debug stream, details about the sensor model. 00133 * It also optionally saves all the information in an user supplied data structure "out_data". 00134 * \return false on any error 00135 */ 00136 bool displaySensorInfo( CHokuyoURG::TSensorInfo * out_data = NULL ); 00137 00138 /** Start the scanning mode, using parameters stored in the object (loaded from the .ini file) 00139 * After this command the device will start to send scans until "switchLaserOff" is called. 00140 * \return false on any error 00141 */ 00142 bool startScanningMode(); 00143 00144 /** Turns the laser on */ 00145 void initialize(); 00146 00147 /** Waits for a response from the device. 00148 * \return false on any error 00149 */ 00150 bool receiveResponse( 00151 const char *sentCmd_forEchoVerification, 00152 char &rcv_status0, 00153 char &rcv_status1, 00154 char *rcv_data, 00155 int &rcv_dataLength); 00156 00157 00158 /** Assures a minimum number of bytes in the input buffer, reading from the serial port only if required. 00159 * \return false if the number of bytes are not available, even after trying to fetch more data from the serial port. 00160 */ 00161 bool assureBufferHasBytes(const size_t nDesiredBytes); 00162 00163 public: 00164 /** Constructor 00165 */ 00166 CHokuyoURG(); 00167 00168 /** Destructor: turns the laser off */ 00169 virtual ~CHokuyoURG(); 00170 00171 /** Specific laser scanner "software drivers" must process here new data from the I/O stream, and, if a whole scan has arrived, return it. 00172 * This method will be typically called in a different thread than other methods, and will be called in a timely fashion. 00173 */ 00174 void doProcessSimple( 00175 bool &outThereIsObservation, 00176 mrpt::slam::CObservation2DRangeScan &outObservation, 00177 bool &hardwareError ); 00178 00179 /** 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. 00180 * \return If everything works "true", or "false" if there is any error. 00181 */ 00182 bool turnOn(); 00183 00184 /** Disables the scanning mode (this can be used to turn the device in low energy mode, if available) 00185 * \return If everything works "true", or "false" if there is any error. 00186 */ 00187 bool turnOff(); 00188 00189 /** Empties the RX buffers of the serial port */ 00190 void purgeBuffers(); 00191 00192 /** 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. */ 00193 void setSerialPort(const std::string &port_name) { m_com_port = port_name; } 00194 00195 /** Set the ip direction and port to connect using Ethernet communication */ 00196 void setIPandPort(const std::string &ip, const unsigned int &port) { m_ip_dir = ip; m_port_dir = port; } 00197 00198 /** Returns the currently set serial port \sa setSerialPort */ 00199 const std::string getSerialPort() { return m_com_port; } 00200 00201 /** 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. 00202 * Call with "0" to disable this reduction again (the default). 00203 */ 00204 void setReducedFOV(const double fov) { m_reduced_fov = fov; } 00205 00206 /** Changes the high sensitivity mode (HS) (default: false) 00207 * \return false on any error 00208 */ 00209 bool setHighSensitivityMode(bool enabled); 00210 00211 void setVerbose(bool enable = true) { m_verbose = enable; } 00212 00213 00214 protected: 00215 /** 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" 00216 */ 00217 bool checkCOMisOpen(); 00218 00219 double m_reduced_fov; //!< Used to reduce artificially the interval of scan ranges. 00220 00221 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. 00222 00223 std::string m_ip_dir; //!< If set to non-empty and m_port_dir too, the program will try to connect to a Hokuyo using Ethernet communication 00224 unsigned int m_port_dir; //!< If set to non-empty and m_ip_dir too, the program will try to connect to a Hokuyo using Ethernet communication 00225 00226 /** The information gathered when the laser is first open */ 00227 TSensorInfo m_sensor_info; 00228 00229 bool m_I_am_owner_serial_port; 00230 00231 uint32_t m_timeStartUI; //!< Time of the first data packet, for synchronization purposes. 00232 mrpt::system::TTimeStamp m_timeStartTT; 00233 00234 /** 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) 00235 * See hwdrivers::CHokuyoURG for the possible parameters 00236 */ 00237 void loadConfig_sensorSpecific( 00238 const mrpt::utils::CConfigFileBase &configSource, 00239 const std::string &iniSection ); 00240 00241 }; // End of class 00242 00243 } // End of namespace 00244 00245 } // End of namespace 00246 00247 #endif
| Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011 |