Main MRPT website > C++ reference
MRPT logo

CHokuyoURG.h

Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                   http://mrpt.sourceforge.net/                            |
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                   */
00075                 class HWDRIVERS_IMPEXP CHokuyoURG : public C2DRangeFinderAbstract
00076                 {
00077                         DEFINE_GENERIC_SENSOR(CHokuyoURG)
00078                 public:
00079 
00080                         /** Used in CHokuyoURG::displayVersionInfo */
00081                         struct TSensorInfo
00082                         {
00083                                 std::string             model;                  //!< The sensor model
00084                                 double                  d_min,d_max;    //!< Min/Max ranges, in meters.
00085                                 int                             scans_per_360deg;       //!< Number of measuremens per 360 degrees.
00086                                 int                             scan_first,scan_last, scan_front;       //!< First, last, and front step of the scanner angular span.
00087                                 int                             motor_speed_rpm;                //!< Standard motor speed, rpm.
00088                         };
00089 
00090                 private:
00091                         int             m_firstRange,m_lastRange;   //!< The first and last ranges to consider from the scan.
00092                         int             m_motorSpeed_rpm;           //!< The motor speed (default=600rpm)
00093                         poses::CPose3D  m_sensorPose;       //!< The sensor 6D pose:
00094                         mrpt::utils::circular_buffer<uint8_t> m_rx_buffer; //!< Auxiliary buffer for readings
00095 
00096                         std::string     m_lastSentMeasCmd; //!< The last sent measurement command (MDXXX), including the last 0x0A.
00097 
00098                         bool                    m_verbose;
00099                         bool                    m_highSensMode;  //!< High sensitivity [HS] mode (default: false)
00100 
00101                         /** Enables the SCIP2.0 protocol (this must be called at the very begining!).
00102                           * \return false on any error
00103                           */
00104                         bool  enableSCIP20();
00105 
00106                         /** Passes to 115200bps bitrate.
00107                           * \return false on any error
00108                           */
00109                         bool  setHighBaudrate();
00110 
00111                         /** Switchs the laser on.
00112                           * \return false on any error
00113                           */
00114                         bool  switchLaserOn();
00115 
00116                         /** Switchs the laser off
00117                           * \return false on any error
00118                           */
00119                         bool  switchLaserOff();
00120 
00121                         /** Changes the motor speed in rpm's (default 600rpm)
00122                           * \return false on any error
00123                           */
00124                         bool  setMotorSpeed(int motoSpeed_rpm);
00125 
00126                         /** Ask to the device, and print to the debug stream, details about the firmware version,serial number,...
00127                           * \return false on any error
00128                           */
00129                         bool  displayVersionInfo(  );
00130 
00131                         /** Ask to the device, and print to the debug stream, details about the sensor model.
00132                           *  It also optionally saves all the information in an user supplied data structure "out_data".
00133                           * \return false on any error
00134                           */
00135                         bool  displaySensorInfo( CHokuyoURG::TSensorInfo * out_data = NULL );
00136 
00137                         /** Start the scanning mode, using parameters stored in the object (loaded from the .ini file)
00138                           * After this command the device will start to send scans until "switchLaserOff" is called.
00139                           * \return false on any error
00140                           */
00141                         bool  startScanningMode();
00142 
00143                         /** Turns the laser on */
00144                         void initialize();
00145 
00146                         /** Waits for a response from the device.
00147                           * \return false on any error
00148                           */
00149                         bool  receiveResponse(
00150                                         const char      *sentCmd_forEchoVerification,
00151                                         char    &rcv_status0,
00152                                         char    &rcv_status1,
00153                                         char    *rcv_data,
00154                                         int             &rcv_dataLength);
00155 
00156 
00157                         /** Assures a minimum number of bytes in the input buffer, reading from the serial port only if required.
00158                           * \return false if the number of bytes are not available, even after trying to fetch more data from the serial port.
00159                           */
00160                         bool assureBufferHasBytes(const size_t nDesiredBytes);
00161 
00162                 public:
00163                         /** Constructor
00164                           */
00165                         CHokuyoURG();
00166 
00167                         /** Destructor: turns the laser off */
00168                         virtual ~CHokuyoURG();
00169 
00170                         /** Specific laser scanner "software drivers" must process here new data from the I/O stream, and, if a whole scan has arrived, return it.
00171                           *  This method will be typically called in a different thread than other methods, and will be called in a timely fashion.
00172                           */
00173                         void  doProcessSimple(
00174                                 bool                                                    &outThereIsObservation,
00175                                 mrpt::slam::CObservation2DRangeScan     &outObservation,
00176                                 bool                                                    &hardwareError );
00177 
00178                         /** 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.
00179                           * \return If everything works "true", or "false" if there is any error.
00180                           */
00181                         bool  turnOn();
00182 
00183                         /** Disables the scanning mode (this can be used to turn the device in low energy mode, if available)
00184                           * \return If everything works "true", or "false" if there is any error.
00185                           */
00186                         bool  turnOff();
00187 
00188                         /** Empties the RX buffers of the serial port */
00189                         void purgeBuffers();
00190 
00191                         /** 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.  */
00192                         void setSerialPort(const std::string &port_name) { m_com_port = port_name; }
00193                         
00194                         /** Set the ip direction and port to connect using Ethernet communication */
00195                         void setIPandPort(const std::string &ip, const unsigned int &port) { m_ip_dir = ip; m_port_dir = port; }
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                         /** Changes the high sensitivity mode (HS) (default: false)
00206                           * \return false on any error
00207                           */
00208                         bool  setHighSensitivityMode(bool enabled);
00209 
00210                         void setVerbose(bool enable = true) { m_verbose = enable; }
00211 
00212 
00213                 protected:
00214                         /** 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"
00215                           */
00216                         bool  checkCOMisOpen();
00217 
00218                         double                  m_reduced_fov; //!< Used to reduce artificially the interval of scan ranges.
00219 
00220                         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.
00221 
00222                         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
00223                         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     
00224 
00225                         /** The information gathered when the laser is first open */
00226                         TSensorInfo             m_sensor_info;
00227 
00228                         bool                    m_I_am_owner_serial_port;
00229 
00230                         uint32_t                m_timeStartUI;  //!< Time of the first data packet, for synchronization purposes.
00231                         mrpt::system::TTimeStamp        m_timeStartTT;
00232 
00233                         /** 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)
00234                           *  See hwdrivers::CHokuyoURG for the possible parameters
00235                           */
00236                         void  loadConfig_sensorSpecific(
00237                                 const mrpt::utils::CConfigFileBase &configSource,
00238                                 const std::string         &iniSection );
00239 
00240                 };      // End of class
00241 
00242         } // End of namespace
00243 
00244 } // End of namespace
00245 
00246 #endif



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN:exported at Tue Jan 25 21:56:31 UTC 2011