Main MRPT website > C++ reference
MRPT logo
CHokuyoURG.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2015, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #ifndef CHokuyoURG_H
10 #define CHokuyoURG_H
11 
12 #include <mrpt/poses/CPose3D.h>
16 
17 namespace mrpt
18 {
19  namespace hwdrivers
20  {
21  /** This software driver implements the protocol SCIP-2.0 for interfacing HOKUYO URG, UTM and UXM laser scanners.
22  * Refer to the wiki page for more details:
23  * http://www.mrpt.org/Example:HOKUYO_URG/UTM_Laser_Scanner
24  *
25  * See also the application "rawlog-grabber" for a ready-to-use application to gather data from the scanner.
26  *
27  * \code
28  * PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS:
29  * -------------------------------------------------------
30  * [supplied_section_name]
31  * HOKUYO_motorSpeed_rpm=600
32  * //HOKUYO_HS_mode = false // Optional (un-comment line if used): Set/unset the High-sensitivity mode (not on all models/firmwares!)
33  * COM_port_WIN = COM3
34  * COM_port_LIN = ttyS0
35  * pose_x=0.21 // Laser range scaner 3D position in the robot (meters)
36  * pose_y=0
37  * pose_z=0.34
38  * pose_yaw=0 // Angles in degrees
39  * pose_pitch=0
40  * pose_roll=0
41  * //IP_DIR = 192.168.0.10 // Uncommented this and "PORT_DIR" if the used HOKUYO is connected by Ethernet instead of USB
42  * //PORT_DIR = 10940
43  *
44  * // Optional: reduced FOV:
45  * // reduced_fov = 25 // Deg
46  *
47  * //preview = true // Enable GUI visualization of captured data
48  *
49  * // Optional: Exclusion zones to avoid the robot seeing itself:
50  * //exclusionZone1_x = 0.20 0.30 0.30 0.20
51  * //exclusionZone1_y = 0.20 0.30 0.30 0.20
52  *
53  * // Optional: Exclusion zones to avoid the robot seeing itself:
54  * //exclusionAngles1_ini = 20 // Deg
55  * //exclusionAngles1_end = 25 // Deg
56  *
57  * \endcode
58  * \ingroup mrpt_hwdrivers_grp
59  */
61  {
63  public:
64 
65  /** Used in CHokuyoURG::displayVersionInfo */
66  struct TSensorInfo
67  {
68  std::string model; //!< The sensor model
69  double d_min,d_max; //!< Min/Max ranges, in meters.
70  int scans_per_360deg; //!< Number of measuremens per 360 degrees.
71  int scan_first,scan_last, scan_front; //!< First, last, and front step of the scanner angular span.
72  int motor_speed_rpm; //!< Standard motor speed, rpm.
73  };
74 
75  private:
76  int m_firstRange,m_lastRange; //!< The first and last ranges to consider from the scan.
77  int m_motorSpeed_rpm; //!< The motor speed (default=600rpm)
78  poses::CPose3D m_sensorPose; //!< The sensor 6D pose:
79  mrpt::utils::circular_buffer<uint8_t> m_rx_buffer; //!< Auxiliary buffer for readings
80 
81  std::string m_lastSentMeasCmd; //!< The last sent measurement command (MDXXX), including the last 0x0A.
82 
83  bool m_verbose;
84  bool m_highSensMode; //!< High sensitivity [HS] mode (default: false)
85  mrpt::gui::CDisplayWindow3DPtr m_win;
86 
87  /** Enables the SCIP2.0 protocol (this must be called at the very begining!).
88  * \return false on any error
89  */
90  bool enableSCIP20();
91 
92  /** Passes to 115200bps bitrate.
93  * \return false on any error
94  */
95  bool setHighBaudrate();
96 
97  /** Switchs the laser on.
98  * \return false on any error
99  */
100  bool switchLaserOn();
101 
102  /** Switchs the laser off
103  * \return false on any error
104  */
105  bool switchLaserOff();
106 
107  /** Changes the motor speed in rpm's (default 600rpm)
108  * \return false on any error
109  */
110  bool setMotorSpeed(int motoSpeed_rpm);
111 
112  /** Ask to the device, and print to the debug stream, details about the firmware version,serial number,...
113  * \return false on any error
114  */
115  bool displayVersionInfo( );
116 
117  /** Ask to the device, and print to the debug stream, details about the sensor model.
118  * It also optionally saves all the information in an user supplied data structure "out_data".
119  * \return false on any error
120  */
121  bool displaySensorInfo( CHokuyoURG::TSensorInfo * out_data = NULL );
122 
123  /** Start the scanning mode, using parameters stored in the object (loaded from the .ini file)
124  * After this command the device will start to send scans until "switchLaserOff" is called.
125  * \return false on any error
126  */
127  bool startScanningMode();
128 
129  /** Turns the laser on */
130  void initialize();
131 
132  /** Waits for a response from the device.
133  * \return false on any error
134  */
135  bool receiveResponse(
136  const char *sentCmd_forEchoVerification,
137  char &rcv_status0,
138  char &rcv_status1,
139  char *rcv_data,
140  int &rcv_dataLength);
141 
142 
143  /** Assures a minimum number of bytes in the input buffer, reading from the serial port only if required.
144  * \return false if the number of bytes are not available, even after trying to fetch more data from the serial port.
145  */
146  bool assureBufferHasBytes(const size_t nDesiredBytes);
147 
148  public:
149  /** Constructor
150  */
151  CHokuyoURG();
152 
153  /** Destructor: turns the laser off */
154  virtual ~CHokuyoURG();
155 
156  /** Specific laser scanner "software drivers" must process here new data from the I/O stream, and, if a whole scan has arrived, return it.
157  * This method will be typically called in a different thread than other methods, and will be called in a timely fashion.
158  */
159  void doProcessSimple(
160  bool &outThereIsObservation,
161  mrpt::obs::CObservation2DRangeScan &outObservation,
162  bool &hardwareError );
163 
164  /** 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.
165  * \return If everything works "true", or "false" if there is any error.
166  */
167  bool turnOn();
168 
169  /** Disables the scanning mode (this can be used to turn the device in low energy mode, if available)
170  * \return If everything works "true", or "false" if there is any error.
171  */
172  bool turnOff();
173 
174  /** Empties the RX buffers of the serial port */
175  void purgeBuffers();
176 
177  /** 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. */
178  void setSerialPort(const std::string &port_name) { m_com_port = port_name; }
179 
180  /** Set the ip direction and port to connect using Ethernet communication */
181  void setIPandPort(const std::string &ip, const unsigned int &port) { m_ip_dir = ip; m_port_dir = port; }
182 
183  /** Returns the currently set serial port \sa setSerialPort */
184  const std::string getSerialPort() { return m_com_port; }
185 
186  /** 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.
187  * Call with "0" to disable this reduction again (the default).
188  */
189  void setReducedFOV(const double fov) { m_reduced_fov = fov; }
190 
191  /** Changes the high sensitivity mode (HS) (default: false)
192  * \return false on any error
193  */
194  bool setHighSensitivityMode(bool enabled);
195 
196  void setVerbose(bool enable = true) { m_verbose = enable; }
197 
198 
199  protected:
200  /** 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"
201  */
202  bool checkCOMisOpen();
203 
204  double m_reduced_fov; //!< Used to reduce artificially the interval of scan ranges.
205 
206  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.
207 
208  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
209  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
210 
211  /** The information gathered when the laser is first open */
213 
215 
216  uint32_t m_timeStartUI; //!< Time of the first data packet, for synchronization purposes.
218 
219  /** See the class documentation at the top for expected parameters */
220  void loadConfig_sensorSpecific(
221  const mrpt::utils::CConfigFileBase &configSource,
222  const std::string &iniSection );
223 
224  }; // End of class
225 
226  } // End of namespace
227 
228 } // End of namespace
229 
230 #endif
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:30
void setVerbose(bool enable=true)
Definition: CHokuyoURG.h:196
const std::string getSerialPort()
Returns the currently set serial port.
Definition: CHokuyoURG.h:184
std::string m_com_port
If set to non-empty, the serial port will be attempted to be opened automatically when this class is ...
Definition: CHokuyoURG.h:206
uint32_t m_timeStartUI
Time of the first data packet, for synchronization purposes.
Definition: CHokuyoURG.h:216
void setReducedFOV(const double fov)
If called (before calling "turnOn"), the field of view of the laser is reduced to the given range (in...
Definition: CHokuyoURG.h:189
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 comm...
Definition: CHokuyoURG.h:209
This class allows loading and storing values and vectors of different types from a configuration text...
std::string m_lastSentMeasCmd
The last sent measurement command (MDXXX), including the last 0x0A.
Definition: CHokuyoURG.h:81
void setSerialPort(const std::string &port_name)
If set to non-empty, the serial port will be attempted to be opened automatically when this class is ...
Definition: CHokuyoURG.h:178
mrpt::gui::CDisplayWindow3DPtr m_win
Definition: CHokuyoURG.h:85
Used in CHokuyoURG::displayVersionInfo.
Definition: CHokuyoURG.h:66
mrpt::system::TTimeStamp m_timeStartTT
Definition: CHokuyoURG.h:217
int m_motorSpeed_rpm
The motor speed (default=600rpm)
Definition: CHokuyoURG.h:77
#define DEFINE_GENERIC_SENSOR(class_name)
This declaration must be inserted in all CGenericSensor classes definition, within the class declarat...
This is the base, abstract class for "software drivers" interfaces to 2D scanners (laser range finder...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:69
void setIPandPort(const std::string &ip, const unsigned int &port)
Set the ip direction and port to connect using Ethernet communication.
Definition: CHokuyoURG.h:181
This software driver implements the protocol SCIP-2.0 for interfacing HOKUYO URG, UTM and UXM laser s...
Definition: CHokuyoURG.h:60
poses::CPose3D m_sensorPose
The sensor 6D pose:
Definition: CHokuyoURG.h:78
TSensorInfo m_sensor_info
The information gathered when the laser is first open.
Definition: CHokuyoURG.h:212
#define HWDRIVERS_IMPEXP
bool m_highSensMode
High sensitivity [HS] mode (default: false)
Definition: CHokuyoURG.h:84
std::string model
The sensor model.
Definition: CHokuyoURG.h:68
double m_reduced_fov
Used to reduce artificially the interval of scan ranges.
Definition: CHokuyoURG.h:204
mrpt::utils::circular_buffer< uint8_t > m_rx_buffer
Auxiliary buffer for readings.
Definition: CHokuyoURG.h:79
int motor_speed_rpm
Standard motor speed, rpm.
Definition: CHokuyoURG.h:72
int m_lastRange
The first and last ranges to consider from the scan.
Definition: CHokuyoURG.h:76
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 co...
Definition: CHokuyoURG.h:208
int scans_per_360deg
Number of measuremens per 360 degrees.
Definition: CHokuyoURG.h:70



Page generated by Doxygen 1.8.9.1 for MRPT 1.3.0 SVN: at Sun Sep 13 03:55:12 UTC 2015