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



Page generated by Doxygen 1.9.1 for MRPT 1.9.9 Git: 814d80880 Fri Aug 24 01:51:28 2018 +0200 at mar 26 may 2026 12:30:59 CEST