Main MRPT website > C++ reference for MRPT 1.9.9
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-2017, 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
22  * URG/UTM/UXM/UST laser scanners (USB or Ethernet).
23  * Refer to the example code
24  * [HOKUYO_laser_test](http://www.mrpt.org/tutorials/mrpt-examples/example_hokuyo_urgutm_laser_scanner/)
25  * and to example rawlog-grabber [config
26  * files](https://github.com/MRPT/mrpt/tree/master/share/mrpt/config_files/rawlog-grabber)
27  *
28  * See also the application "rawlog-grabber" for a ready-to-use application to
29  * gather data from the scanner.
30  *
31  * \code
32  * PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS:
33  * -------------------------------------------------------
34  * [supplied_section_name]
35  * HOKUYO_motorSpeed_rpm=600
36  * #HOKUYO_HS_mode = false // Optional (un-comment line if used):
37  * Set/unset the High-sensitivity mode (not on all models/firmwares!)
38  *
39  * # Uncomment serial port or IP address, depending on the Hokuyo model
40  * (serial/USB vs. Ethernet):
41  * COM_port_WIN = COM3 // Serial port name in Windows
42  * COM_port_LIN = ttyS0 // Serial port name in GNU/Linux
43  * #IP_DIR = 192.168.0.10 // Uncommented this and "PORT_DIR" if the
44  * used HOKUYO is connected by Ethernet instead of USB
45  * #PORT_DIR = 10940 // Default value: 10940
46  *
47  * pose_x=0.21 // Laser range scaner 3D position in the robot (meters)
48  * pose_y=0
49  * pose_z=0.34
50  * pose_yaw=0 // Angles in degrees
51  * pose_pitch=0
52  * pose_roll=0
53  *
54  * #disable_firmware_timestamp = true // Uncomment to use PC time instead
55  * of laser time
56  *
57  * # Optional: reduced FOV:
58  * # reduced_fov = 25 // Deg
59  *
60  * #preview = true // Enable GUI visualization of captured data
61  *
62  * # Optional: Exclusion zones to avoid the robot seeing itself:
63  * #exclusionZone1_x = 0.20 0.30 0.30 0.20
64  * #exclusionZone1_y = 0.20 0.30 0.30 0.20
65  *
66  * # Optional: Exclusion zones to avoid the robot seeing itself:
67  * #exclusionAngles1_ini = 20 // Deg
68  * #exclusionAngles1_end = 25 // Deg
69  *
70  * \endcode
71  * \ingroup mrpt_hwdrivers_grp
72  */
74 {
76  public:
77  /** Used in CHokuyoURG::displayVersionInfo */
78  struct TSensorInfo
79  {
80  /** The sensor model */
82  /** Min/Max ranges, in meters. */
83  double d_min, d_max;
84  /** Number of measuremens per 360 degrees. */
86  /** First, last, and front step of the scanner angular span. */
88  /** Standard motor speed, rpm. */
90  };
91 
92  private:
93  /** The first and last ranges to consider from the scan. */
95  /** The motor speed (default=600rpm) */
97  /** The sensor 6D pose: */
99  /** Auxiliary buffer for readings */
101 
102  /** The last sent measurement command (MDXXX), including the last 0x0A. */
104 
105  /** High sensitivity [HS] mode (default: false) */
108 
109  /** Enables the SCIP2.0 protocol (this must be called at the very
110  * begining!).
111  * \return false on any error
112  */
113  bool enableSCIP20();
114 
115  /** Passes to 115200bps bitrate.
116  * \return false on any error
117  */
118  bool setHighBaudrate();
119 
120  /** Switchs the laser on.
121  * \return false on any error
122  */
123  bool switchLaserOn();
124 
125  /** Switchs the laser off
126  * \return false on any error
127  */
128  bool switchLaserOff();
129 
130  /** Changes the motor speed in rpm's (default 600rpm)
131  * \return false on any error
132  */
133  bool setMotorSpeed(int motoSpeed_rpm);
134 
135  /** Ask to the device, and print to the debug stream, details about the
136  * firmware version,serial number,...
137  * \return false on any error
138  */
139  bool displayVersionInfo();
140 
141  /** Ask to the device, and print to the debug stream, details about the
142  * sensor model.
143  * It also optionally saves all the information in an user supplied data
144  * structure "out_data".
145  * \return false on any error
146  */
147  bool displaySensorInfo(CHokuyoURG::TSensorInfo* out_data = nullptr);
148 
149  /** Start the scanning mode, using parameters stored in the object (loaded
150  * from the .ini file)
151  * After this command the device will start to send scans until
152  * "switchLaserOff" is called.
153  * \return false on any error
154  */
155  bool startScanningMode();
156 
157  /** Turns the laser on */
158  void initialize();
159 
160  /** Waits for a response from the device.
161  * \return false on any error
162  */
163  bool receiveResponse(
164  const char* sentCmd_forEchoVerification, char& rcv_status0,
165  char& rcv_status1, char* rcv_data, int& rcv_dataLength);
166 
167  /** Assures a minimum number of bytes in the input buffer, reading from the
168  * serial port only if required.
169  * \return false if the number of bytes are not available, even after
170  * trying to fetch more data from the serial port.
171  */
172  bool assureBufferHasBytes(const size_t nDesiredBytes);
173 
174  public:
175  /** Constructor
176  */
177  CHokuyoURG();
178 
179  /** Destructor: turns the laser off */
180  virtual ~CHokuyoURG();
181 
182  /** Specific laser scanner "software drivers" must process here new data
183  * from the I/O stream, and, if a whole scan has arrived, return it.
184  * This method will be typically called in a different thread than other
185  * methods, and will be called in a timely fashion.
186  */
187  void doProcessSimple(
188  bool& outThereIsObservation,
189  mrpt::obs::CObservation2DRangeScan& outObservation,
190  bool& hardwareError);
191 
192  /** Enables the scanning mode (which may depend on the specific laser
193  * device); this must be called before asking for observations to assure
194  * that the protocol has been initializated.
195  * \return If everything works "true", or "false" if there is any error.
196  */
197  bool turnOn();
198 
199  /** Disables the scanning mode (this can be used to turn the device in low
200  * energy mode, if available)
201  * \return If everything works "true", or "false" if there is any error.
202  */
203  bool turnOff();
204 
205  /** Empties the RX buffers of the serial port */
206  void purgeBuffers();
207 
208  /** If set to non-empty, the serial port will be attempted to be opened
209  * automatically when this class is first used to request data from the
210  * laser. */
211  void setSerialPort(const std::string& port_name) { m_com_port = port_name; }
212  /** Set the ip direction and port to connect using Ethernet communication */
213  void setIPandPort(const std::string& ip, const unsigned int& port)
214  {
215  m_ip_dir = ip;
216  m_port_dir = port;
217  }
218 
219  /** Returns the currently set serial port \sa setSerialPort */
221  /** If called (before calling "turnOn"), the field of view of the laser is
222  * reduced to the given range (in radians), discarding the rest of measures.
223  * Call with "0" to disable this reduction again (the default).
224  */
225  void setReducedFOV(const double fov) { m_reduced_fov = fov; }
226  /** Changes the high sensitivity mode (HS) (default: false)
227  * \return false on any error
228  */
229  bool setHighSensitivityMode(bool enabled);
230 
231  /** If true scans will capture intensity. (default: false)
232  * Should not be called while scanning.
233  * \return false on any error
234  */
235  bool setIntensityMode(bool enabled);
236 
237  protected:
238  /** Returns true if there is a valid stream bound to the laser scanner,
239  * otherwise it first try to open the serial port "m_com_port"
240  */
241  bool checkCOMisOpen();
242 
243  /** Used to reduce artificially the interval of scan ranges. */
245 
246  /** If set to non-empty, the serial port will be attempted to be opened
247  * automatically when this class is first used to request data from the
248  * laser. */
250 
251  /** If set to non-empty and m_port_dir too, the program will try to connect
252  * to a Hokuyo using Ethernet communication */
254  /** If set to non-empty and m_ip_dir too, the program will try to connect to
255  * a Hokuyo using Ethernet communication */
256  unsigned int m_port_dir;
257 
258  /** The information gathered when the laser is first open */
260 
262 
263  /** Time of the first data packet, for synchronization purposes. */
265  /** Counter to discard to first few packets before setting the
266  * correspondence between device and computer timestamps. */
270  /** Get intensity from lidar scan (default: false) */
272 
273  /** See the class documentation at the top for expected parameters */
275  const mrpt::utils::CConfigFileBase& configSource,
276  const std::string& iniSection);
277 
278 }; // End of class
279 
280 } // End of namespace
281 
282 } // End of namespace
283 
284 #endif
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:32
const std::string getSerialPort()
Returns the currently set serial port.
Definition: CHokuyoURG.h:220
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:249
uint32_t m_timeStartUI
Time of the first data packet, for synchronization purposes.
Definition: CHokuyoURG.h:264
virtual ~CHokuyoURG()
Destructor: turns the laser off.
Definition: CHokuyoURG.cpp:57
int m_firstRange
The first and last ranges to consider from the scan.
Definition: CHokuyoURG.h:94
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:225
bool m_intensity
Get intensity from lidar scan (default: false)
Definition: CHokuyoURG.h:271
void loadConfig_sensorSpecific(const mrpt::utils::CConfigFileBase &configSource, const std::string &iniSection)
See the class documentation at the top for expected parameters.
Definition: CHokuyoURG.cpp:213
bool assureBufferHasBytes(const size_t nDesiredBytes)
Assures a minimum number of bytes in the input buffer, reading from the serial port only if required...
Definition: CHokuyoURG.cpp:431
bool switchLaserOn()
Switchs the laser on.
Definition: CHokuyoURG.cpp:646
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:256
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:103
mrpt::gui::CDisplayWindow3D::Ptr m_win
Definition: CHokuyoURG.h:107
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:211
bool displaySensorInfo(CHokuyoURG::TSensorInfo *out_data=nullptr)
Ask to the device, and print to the debug stream, details about the sensor model. ...
Definition: CHokuyoURG.cpp:879
Used in CHokuyoURG::displayVersionInfo.
Definition: CHokuyoURG.h:78
bool setIntensityMode(bool enabled)
If true scans will capture intensity.
Definition: CHokuyoURG.cpp:817
bool displayVersionInfo()
Ask to the device, and print to the debug stream, details about the firmware version,serial number,...
Definition: CHokuyoURG.cpp:826
std::shared_ptr< CDisplayWindow3D > Ptr
int m_timeStartSynchDelay
Counter to discard to first few packets before setting the correspondence between device and computer...
Definition: CHokuyoURG.h:267
bool enableSCIP20()
Enables the SCIP2.0 protocol (this must be called at the very begining!).
Definition: CHokuyoURG.cpp:605
mrpt::system::TTimeStamp m_timeStartTT
Definition: CHokuyoURG.h:268
GLsizei const GLchar ** string
Definition: glext.h:4101
bool switchLaserOff()
Switchs the laser off.
Definition: CHokuyoURG.cpp:687
int m_motorSpeed_rpm
The motor speed (default=600rpm)
Definition: CHokuyoURG.h:96
#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...
void purgeBuffers()
Empties the RX buffers of the serial port.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
int scan_first
First, last, and front step of the scanner angular span.
Definition: CHokuyoURG.h:87
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
bool startScanningMode()
Start the scanning mode, using parameters stored in the object (loaded from the .ini file) After this...
Definition: CHokuyoURG.cpp:998
bool checkCOMisOpen()
Returns true if there is a valid stream bound to the laser scanner, otherwise it first try to open th...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
void setIPandPort(const std::string &ip, const unsigned int &port)
Set the ip direction and port to connect using Ethernet communication.
Definition: CHokuyoURG.h:213
bool turnOn()
Enables the scanning mode (which may depend on the specific laser device); this must be called before...
Definition: CHokuyoURG.cpp:269
bool setMotorSpeed(int motoSpeed_rpm)
Changes the motor speed in rpm&#39;s (default 600rpm)
Definition: CHokuyoURG.cpp:727
double d_min
Min/Max ranges, in meters.
Definition: CHokuyoURG.h:83
This software driver implements the protocol SCIP-2.0 for interfacing HOKUYO URG/UTM/UXM/UST laser sc...
Definition: CHokuyoURG.h:73
void initialize()
Turns the laser on.
void doProcessSimple(bool &outThereIsObservation, mrpt::obs::CObservation2DRangeScan &outObservation, bool &hardwareError)
Specific laser scanner "software drivers" must process here new data from the I/O stream...
Definition: CHokuyoURG.cpp:74
bool setHighBaudrate()
Passes to 115200bps bitrate.
Definition: CHokuyoURG.cpp:390
poses::CPose3D m_sensorPose
The sensor 6D pose:
Definition: CHokuyoURG.h:98
TSensorInfo m_sensor_info
The information gathered when the laser is first open.
Definition: CHokuyoURG.h:259
bool m_highSensMode
High sensitivity [HS] mode (default: false)
Definition: CHokuyoURG.h:106
std::string model
The sensor model.
Definition: CHokuyoURG.h:81
double m_reduced_fov
Used to reduce artificially the interval of scan ranges.
Definition: CHokuyoURG.h:244
mrpt::utils::circular_buffer< uint8_t > m_rx_buffer
Auxiliary buffer for readings.
Definition: CHokuyoURG.h:100
int motor_speed_rpm
Standard motor speed, rpm.
Definition: CHokuyoURG.h:89
unsigned __int32 uint32_t
Definition: rptypes.h:47
bool turnOff()
Disables the scanning mode (this can be used to turn the device in low energy mode, if available)
Definition: CHokuyoURG.cpp:379
bool setHighSensitivityMode(bool enabled)
Changes the high sensitivity mode (HS) (default: false)
Definition: CHokuyoURG.cpp:775
bool receiveResponse(const char *sentCmd_forEchoVerification, char &rcv_status0, char &rcv_status1, char *rcv_data, int &rcv_dataLength)
Waits for a response from the device.
Definition: CHokuyoURG.cpp:474
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:253
int scans_per_360deg
Number of measuremens per 360 degrees.
Definition: CHokuyoURG.h:85



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019