Main MRPT website > C++ reference
MRPT logo
CHokuyoURG.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef CHokuyoURG_H
29 #define CHokuyoURG_H
30 
31 #include <mrpt/poses/CPose3D.h>
34 
35 namespace mrpt
36 {
37  namespace hwdrivers
38  {
39  /** This software driver implements the protocol SCIP-2.0 for interfacing HOKUYO URG, UTM and UXM laser scanners.
40  * Refer to the wiki page for more details:
41  * http://www.mrpt.org/Example:HOKUYO_URG/UTM_Laser_Scanner
42  *
43  * See also the application "rawlog-grabber" for a ready-to-use application to gather data from the scanner.
44  *
45  * \code
46  * PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS:
47  * -------------------------------------------------------
48  * [supplied_section_name]
49  * HOKUYO_motorSpeed_rpm=600
50  * //HOKUYO_HS_mode = false // Optional (un-comment line if used): Set/unset the High-sensitivity mode (not on all models/firmwares!)
51  * COM_port_WIN = COM3
52  * COM_port_LIN = ttyS0
53  * pose_x=0.21 // Laser range scaner 3D position in the robot (meters)
54  * pose_y=0
55  * pose_z=0.34
56  * pose_yaw=0 // Angles in degrees
57  * pose_pitch=0
58  * pose_roll=0
59  * //IP_DIR = 192.168.0.10 // Uncommented this and "PORT_DIR" if the used HOKUYO is connected by Ethernet instead of USB
60  * //PORT_DIR = 10940
61  *
62  * // Optional: reduced FOV:
63  * // reduced_fov = 25 // Deg
64  *
65  * // Optional: Exclusion zones to avoid the robot seeing itself:
66  * //exclusionZone1_x = 0.20 0.30 0.30 0.20
67  * //exclusionZone1_y = 0.20 0.30 0.30 0.20
68  *
69  * // Optional: Exclusion zones to avoid the robot seeing itself:
70  * //exclusionAngles1_ini = 20 // Deg
71  * //exclusionAngles1_end = 25 // Deg
72  *
73  * \endcode
74  * \ingroup mrpt_hwdrivers_grp
75  */
77  {
79  public:
80 
81  /** Used in CHokuyoURG::displayVersionInfo */
82  struct TSensorInfo
83  {
84  std::string model; //!< The sensor model
85  double d_min,d_max; //!< Min/Max ranges, in meters.
86  int scans_per_360deg; //!< Number of measuremens per 360 degrees.
87  int scan_first,scan_last, scan_front; //!< First, last, and front step of the scanner angular span.
88  int motor_speed_rpm; //!< Standard motor speed, rpm.
89  };
90 
91  private:
92  int m_firstRange,m_lastRange; //!< The first and last ranges to consider from the scan.
93  int m_motorSpeed_rpm; //!< The motor speed (default=600rpm)
94  poses::CPose3D m_sensorPose; //!< The sensor 6D pose:
95  mrpt::utils::circular_buffer<uint8_t> m_rx_buffer; //!< Auxiliary buffer for readings
96 
97  std::string m_lastSentMeasCmd; //!< The last sent measurement command (MDXXX), including the last 0x0A.
98 
99  bool m_verbose;
100  bool m_highSensMode; //!< High sensitivity [HS] mode (default: false)
101 
102  /** Enables the SCIP2.0 protocol (this must be called at the very begining!).
103  * \return false on any error
104  */
105  bool enableSCIP20();
106 
107  /** Passes to 115200bps bitrate.
108  * \return false on any error
109  */
110  bool setHighBaudrate();
111 
112  /** Switchs the laser on.
113  * \return false on any error
114  */
115  bool switchLaserOn();
116 
117  /** Switchs the laser off
118  * \return false on any error
119  */
120  bool switchLaserOff();
121 
122  /** Changes the motor speed in rpm's (default 600rpm)
123  * \return false on any error
124  */
125  bool setMotorSpeed(int motoSpeed_rpm);
126 
127  /** Ask to the device, and print to the debug stream, details about the firmware version,serial number,...
128  * \return false on any error
129  */
130  bool displayVersionInfo( );
131 
132  /** Ask to the device, and print to the debug stream, details about the sensor model.
133  * It also optionally saves all the information in an user supplied data structure "out_data".
134  * \return false on any error
135  */
136  bool displaySensorInfo( CHokuyoURG::TSensorInfo * out_data = NULL );
137 
138  /** Start the scanning mode, using parameters stored in the object (loaded from the .ini file)
139  * After this command the device will start to send scans until "switchLaserOff" is called.
140  * \return false on any error
141  */
142  bool startScanningMode();
143 
144  /** Turns the laser on */
145  void initialize();
146 
147  /** Waits for a response from the device.
148  * \return false on any error
149  */
150  bool receiveResponse(
151  const char *sentCmd_forEchoVerification,
152  char &rcv_status0,
153  char &rcv_status1,
154  char *rcv_data,
155  int &rcv_dataLength);
156 
157 
158  /** Assures a minimum number of bytes in the input buffer, reading from the serial port only if required.
159  * \return false if the number of bytes are not available, even after trying to fetch more data from the serial port.
160  */
161  bool assureBufferHasBytes(const size_t nDesiredBytes);
162 
163  public:
164  /** Constructor
165  */
166  CHokuyoURG();
167 
168  /** Destructor: turns the laser off */
169  virtual ~CHokuyoURG();
170 
171  /** Specific laser scanner "software drivers" must process here new data from the I/O stream, and, if a whole scan has arrived, return it.
172  * This method will be typically called in a different thread than other methods, and will be called in a timely fashion.
173  */
174  void doProcessSimple(
175  bool &outThereIsObservation,
176  mrpt::slam::CObservation2DRangeScan &outObservation,
177  bool &hardwareError );
178 
179  /** 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.
180  * \return If everything works "true", or "false" if there is any error.
181  */
182  bool turnOn();
183 
184  /** Disables the scanning mode (this can be used to turn the device in low energy mode, if available)
185  * \return If everything works "true", or "false" if there is any error.
186  */
187  bool turnOff();
188 
189  /** Empties the RX buffers of the serial port */
190  void purgeBuffers();
191 
192  /** 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. */
193  void setSerialPort(const std::string &port_name) { m_com_port = port_name; }
194 
195  /** Set the ip direction and port to connect using Ethernet communication */
196  void setIPandPort(const std::string &ip, const unsigned int &port) { m_ip_dir = ip; m_port_dir = port; }
197 
198  /** Returns the currently set serial port \sa setSerialPort */
199  const std::string getSerialPort() { return m_com_port; }
200 
201  /** 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.
202  * Call with "0" to disable this reduction again (the default).
203  */
204  void setReducedFOV(const double fov) { m_reduced_fov = fov; }
205 
206  /** Changes the high sensitivity mode (HS) (default: false)
207  * \return false on any error
208  */
209  bool setHighSensitivityMode(bool enabled);
210 
211  void setVerbose(bool enable = true) { m_verbose = enable; }
212 
213 
214  protected:
215  /** 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"
216  */
217  bool checkCOMisOpen();
218 
219  double m_reduced_fov; //!< Used to reduce artificially the interval of scan ranges.
220 
221  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.
222 
223  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
224  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
225 
226  /** The information gathered when the laser is first open */
228 
230 
231  uint32_t m_timeStartUI; //!< Time of the first data packet, for synchronization purposes.
233 
234  /** 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)
235  * See hwdrivers::CHokuyoURG for the possible parameters
236  */
237  void loadConfig_sensorSpecific(
238  const mrpt::utils::CConfigFileBase &configSource,
239  const std::string &iniSection );
240 
241  }; // End of class
242 
243  } // End of namespace
244 
245 } // End of namespace
246 
247 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013