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-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
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  * # Sets decimation of scans directly at the Hokuyo scanner.
61  * # 0=means send all scans, 1=means send 50% of scans, etc.
62  * # scan_interval = 0
63  *
64  * #preview = true // Enable GUI visualization of captured data
65  *
66  * # Optional: Exclusion zones to avoid the robot seeing itself:
67  * #exclusionZone1_x = 0.20 0.30 0.30 0.20
68  * #exclusionZone1_y = 0.20 0.30 0.30 0.20
69  *
70  * # Optional: Exclusion zones to avoid the robot seeing itself:
71  * #exclusionAngles1_ini = 20 // Deg
72  * #exclusionAngles1_end = 25 // Deg
73  *
74  * \endcode
75  * \ingroup mrpt_hwdrivers_grp
76  */
78 {
80  public:
81  /** Used in CHokuyoURG::displayVersionInfo */
82  struct TSensorInfo
83  {
84  /** The sensor model */
86  /** Min/Max ranges, in meters. */
87  double d_min{0}, d_max{0};
88  /** Number of measuremens per 360 degrees. */
90  /** First, last, and front step of the scanner angular span. */
92  /** Standard motor speed, rpm. */
94  };
95 
96  private:
97  /** The first and last ranges to consider from the scan. */
99  /** The motor speed (default=600rpm) */
101  /** The sensor 6D pose: */
103  /** Auxiliary buffer for readings */
105 
106  /** The last sent measurement command (MDXXX), including the last 0x0A. */
108 
109  /** High sensitivity [HS] mode (default: false) */
112 
113  /** Enables the SCIP2.0 protocol (this must be called at the very
114  * begining!).
115  * \return false on any error
116  */
117  bool enableSCIP20();
118 
119  /** Passes to 115200bps bitrate.
120  * \return false on any error
121  */
122  bool setHighBaudrate();
123 
124  /** Switchs the laser on.
125  * \return false on any error
126  */
127  bool switchLaserOn();
128 
129  /** Switchs the laser off
130  * \return false on any error
131  */
132  bool switchLaserOff();
133 
134  /** Changes the motor speed in rpm's (default 600rpm)
135  * \return false on any error
136  */
137  bool setMotorSpeed(int motoSpeed_rpm);
138 
139  /** Ask to the device, and print to the debug stream, details about the
140  * firmware version,serial number,...
141  * \return false on any error
142  */
143  bool displayVersionInfo();
144 
145  /** Ask to the device, and print to the debug stream, details about the
146  * sensor model.
147  * It also optionally saves all the information in an user supplied data
148  * structure "out_data".
149  * \return false on any error
150  */
151  bool displaySensorInfo(CHokuyoURG::TSensorInfo* out_data = nullptr);
152 
153  /** Start the continuous scanning mode, using parameters stored in the
154  * object (loaded
155  * from the .ini file). Maps to SCIP2.0 commands MD (no intensity) or ME
156  * (intensity).
157  * After this command the device will start to send scans until
158  * switchLaserOff() is called.
159  * \return false on any error
160  */
161  bool startScanningMode();
162 
163  /** Turns the laser on */
164  void initialize();
165 
166  /** Waits for a response from the device. Packet is stored in m_rcv_data,
167  * and status codes in the reference parameters.
168  * \return false on any error
169  */
170  bool receiveResponse(char& rcv_status0, char& rcv_status1);
171 
172  /** Assures a minimum number of bytes in the input buffer, reading from the
173  * serial port only if required.
174  * \return false if the number of bytes are not available, even after
175  * trying to fetch more data from the serial port.
176  */
177  bool assureBufferHasBytes(const size_t nDesiredBytes);
178 
179  public:
180  /** Constructor
181  */
182  CHokuyoURG();
183 
184  /** Destructor: turns the laser off */
185  virtual ~CHokuyoURG();
186 
187  /** Specific laser scanner "software drivers" must process here new data
188  * from the I/O stream, and, if a whole scan has arrived, return it.
189  * This method will be typically called in a different thread than other
190  * methods, and will be called in a timely fashion.
191  */
192  void doProcessSimple(
193  bool& outThereIsObservation,
194  mrpt::obs::CObservation2DRangeScan& outObservation,
195  bool& hardwareError);
196 
197  /** Enables the scanning mode (which may depend on the specific laser
198  * device); this must be called before asking for observations to assure
199  * that the protocol has been initializated.
200  * \return If everything works "true", or "false" if there is any error.
201  */
202  bool turnOn();
203 
204  /** Disables the scanning mode (this can be used to turn the device in low
205  * energy mode, if available)
206  * \return If everything works "true", or "false" if there is any error.
207  */
208  bool turnOff();
209 
210  /** Empties the RX buffers of the serial port */
211  void purgeBuffers();
212 
213  /** If set to non-empty, the serial port will be attempted to be opened
214  * automatically when this class is first used to request data from the
215  * laser. */
216  void setSerialPort(const std::string& port_name) { m_com_port = port_name; }
217  /** Set the ip direction and port to connect using Ethernet communication */
218  void setIPandPort(const std::string& ip, const unsigned int& port)
219  {
220  m_ip_dir = ip;
221  m_port_dir = port;
222  }
223 
224  /** Returns the currently set serial port \sa setSerialPort */
226  /** If called (before calling "turnOn"), the field of view of the laser is
227  * reduced to the given range (in radians), discarding the rest of measures.
228  * Call with "0" to disable this reduction again (the default).
229  */
230  void setReducedFOV(const double fov) { m_reduced_fov = fov; }
231  /** Changes the high sensitivity mode (HS) (default: false)
232  * \return false on any error
233  */
234  bool setHighSensitivityMode(bool enabled);
235 
236  /** If true scans will capture intensity. (default: false)
237  * Should not be called while scanning.
238  * \return false on any error
239  */
240  bool setIntensityMode(bool enabled);
241 
242  /** Set the skip scan count (0 means send all scans).
243  * Must be set before initialize()
244  */
245  void setScanInterval(unsigned int skipScanCount);
246  unsigned int getScanInterval() const;
247 
248  void sendCmd(const char* str);
249 
250  protected:
251  /** temp buffer for incoming data packets */
253 
254  /** Returns true if there is a valid stream bound to the laser scanner,
255  * otherwise it first try to open the serial port "m_com_port"
256  */
257  bool ensureStreamIsOpen();
258 
259  /** Used to reduce artificially the interval of scan ranges. */
261 
262  /** If set to non-empty, the serial port will be attempted to be opened
263  * automatically when this class is first used to request data from the
264  * laser. */
266 
267  /** If set to non-empty and m_port_dir too, the program will try to connect
268  * to a Hokuyo using Ethernet communication */
270  /** If set to non-empty and m_ip_dir too, the program will try to connect to
271  * a Hokuyo using Ethernet communication */
272  unsigned int m_port_dir;
273 
274  /** The information gathered when the laser is first open */
276 
278 
279  /** Time of the first data packet, for synchronization purposes. */
281  /** Counter to discard to first few packets before setting the
282  * correspondence between device and computer timestamps. */
286  /** Get intensity from lidar scan (default: false) */
288  unsigned int m_scan_interval;
289 
290  /** See the class documentation at the top for expected parameters */
292  const mrpt::config::CConfigFileBase& configSource,
293  const std::string& iniSection);
294 
295 }; // End of class
296 
297 } // End of namespace
298 
299 } // End of namespace
300 
301 #endif
mrpt::hwdrivers::CHokuyoURG::initialize
void initialize()
Turns the laser on.
Definition: CHokuyoURG.cpp:1024
mrpt::hwdrivers::CHokuyoURG::m_I_am_owner_serial_port
bool m_I_am_owner_serial_port
Definition: CHokuyoURG.h:277
mrpt::hwdrivers::CHokuyoURG::m_rx_buffer
mrpt::containers::circular_buffer< uint8_t > m_rx_buffer
Auxiliary buffer for readings.
Definition: CHokuyoURG.h:104
mrpt::obs::CObservation2DRangeScan
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
Definition: CObservation2DRangeScan.h:56
mrpt::hwdrivers::CHokuyoURG::turnOff
bool turnOff()
Disables the scanning mode (this can be used to turn the device in low energy mode,...
Definition: CHokuyoURG.cpp:382
mrpt::hwdrivers::CHokuyoURG::TSensorInfo::scan_last
int scan_last
Definition: CHokuyoURG.h:91
mrpt::hwdrivers::CHokuyoURG::m_lastRange
int m_lastRange
Definition: CHokuyoURG.h:98
mrpt::containers::circular_buffer< uint8_t >
mrpt::hwdrivers::CHokuyoURG::m_timeStartUI
uint32_t m_timeStartUI
Time of the first data packet, for synchronization purposes.
Definition: CHokuyoURG.h:280
mrpt::hwdrivers::CHokuyoURG::TSensorInfo::d_max
double d_max
Definition: CHokuyoURG.h:87
mrpt::hwdrivers::CHokuyoURG::TSensorInfo
Used in CHokuyoURG::displayVersionInfo.
Definition: CHokuyoURG.h:82
mrpt::hwdrivers::CHokuyoURG::TSensorInfo::scan_front
int scan_front
Definition: CHokuyoURG.h:91
mrpt::hwdrivers::CHokuyoURG::m_timeStartSynchDelay
int m_timeStartSynchDelay
Counter to discard to first few packets before setting the correspondence between device and computer...
Definition: CHokuyoURG.h:283
mrpt::hwdrivers::CHokuyoURG::loadConfig_sensorSpecific
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:212
mrpt::hwdrivers::CHokuyoURG::m_firstRange
int m_firstRange
The first and last ranges to consider from the scan.
Definition: CHokuyoURG.h:98
mrpt::hwdrivers::CHokuyoURG::receiveResponse
bool receiveResponse(char &rcv_status0, char &rcv_status1)
Waits for a response from the device.
Definition: CHokuyoURG.cpp:456
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
DEFINE_GENERIC_SENSOR
#define DEFINE_GENERIC_SENSOR(class_name)
This declaration must be inserted in all CGenericSensor classes definition, within the class declarat...
Definition: CGenericSensor.h:314
mrpt::hwdrivers::CHokuyoURG::enableSCIP20
bool enableSCIP20()
Enables the SCIP2.0 protocol (this must be called at the very begining!).
Definition: CHokuyoURG.cpp:587
mrpt::hwdrivers::CHokuyoURG::TSensorInfo::d_min
double d_min
Min/Max ranges, in meters.
Definition: CHokuyoURG.h:87
mrpt::hwdrivers::CHokuyoURG::assureBufferHasBytes
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:416
mrpt::hwdrivers::CHokuyoURG::ensureStreamIsOpen
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:894
CDisplayWindow3D.h
mrpt::hwdrivers::CHokuyoURG::m_timeStartTT
mrpt::system::TTimeStamp m_timeStartTT
Definition: CHokuyoURG.h:284
mrpt::hwdrivers::CHokuyoURG::m_motorSpeed_rpm
int m_motorSpeed_rpm
The motor speed (default=600rpm)
Definition: CHokuyoURG.h:100
mrpt::system::TTimeStamp
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1,...
Definition: datetime.h:31
mrpt::hwdrivers::CHokuyoURG::getScanInterval
unsigned int getScanInterval() const
Definition: CHokuyoURG.cpp:660
mrpt::hwdrivers::CHokuyoURG::m_port_dir
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:272
mrpt::hwdrivers::CHokuyoURG::m_disable_firmware_timestamp
bool m_disable_firmware_timestamp
Definition: CHokuyoURG.h:285
mrpt::hwdrivers::C2DRangeFinderAbstract
This is the base, abstract class for "software drivers" interfaces to 2D scanners (laser range finder...
Definition: C2DRangeFinderAbstract.h:43
mrpt::hwdrivers::CHokuyoURG::switchLaserOn
bool switchLaserOn()
Switchs the laser on.
Definition: CHokuyoURG.cpp:610
mrpt::hwdrivers::CHokuyoURG::purgeBuffers
void purgeBuffers()
Empties the RX buffers of the serial port.
Definition: CHokuyoURG.cpp:1037
mrpt::hwdrivers::CHokuyoURG::setSerialPort
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:216
mrpt::config::CConfigFileBase
This class allows loading and storing values and vectors of different types from a configuration text...
Definition: config/CConfigFileBase.h:44
circular_buffer.h
mrpt::hwdrivers::CHokuyoURG::m_scan_interval
unsigned int m_scan_interval
Definition: CHokuyoURG.h:288
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
mrpt::hwdrivers::CHokuyoURG::m_lastSentMeasCmd
std::string m_lastSentMeasCmd
The last sent measurement command (MDXXX), including the last 0x0A.
Definition: CHokuyoURG.h:107
mrpt::hwdrivers::CHokuyoURG::m_win
mrpt::gui::CDisplayWindow3D::Ptr m_win
Definition: CHokuyoURG.h:111
mrpt::gui::CDisplayWindow3D::Ptr
std::shared_ptr< CDisplayWindow3D > Ptr
Definition: CDisplayWindow3D.h:120
mrpt::hwdrivers::CHokuyoURG::setIntensityMode
bool setIntensityMode(bool enabled)
If true scans will capture intensity.
Definition: CHokuyoURG.cpp:727
mrpt::hwdrivers::CHokuyoURG::m_reduced_fov
double m_reduced_fov
Used to reduce artificially the interval of scan ranges.
Definition: CHokuyoURG.h:260
mrpt::hwdrivers::CHokuyoURG::CHokuyoURG
CHokuyoURG()
Constructor.
Definition: CHokuyoURG.cpp:30
mrpt::hwdrivers::CHokuyoURG::displayVersionInfo
bool displayVersionInfo()
Ask to the device, and print to the debug stream, details about the firmware version,...
Definition: CHokuyoURG.cpp:733
mrpt::hwdrivers::CHokuyoURG::displaySensorInfo
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:772
mrpt::hwdrivers::CHokuyoURG::TSensorInfo::scan_first
int scan_first
First, last, and front step of the scanner angular span.
Definition: CHokuyoURG.h:91
mrpt::hwdrivers::CHokuyoURG::sendCmd
void sendCmd(const char *str)
Definition: CHokuyoURG.cpp:63
CPose3D.h
mrpt::hwdrivers::CHokuyoURG::setHighSensitivityMode
bool setHighSensitivityMode(bool enabled)
Changes the high sensitivity mode (HS) (default: false)
Definition: CHokuyoURG.cpp:698
mrpt::hwdrivers::CHokuyoURG::m_ip_dir
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:269
mrpt::hwdrivers::CHokuyoURG::getSerialPort
const std::string getSerialPort()
Returns the currently set serial port.
Definition: CHokuyoURG.h:225
mrpt::hwdrivers::CHokuyoURG::setReducedFOV
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:230
mrpt::hwdrivers::CHokuyoURG::TSensorInfo::scans_per_360deg
int scans_per_360deg
Number of measuremens per 360 degrees.
Definition: CHokuyoURG.h:89
mrpt::hwdrivers::CHokuyoURG
This software driver implements the protocol SCIP-2.0 for interfacing HOKUYO URG/UTM/UXM/UST laser sc...
Definition: CHokuyoURG.h:77
mrpt::hwdrivers::CHokuyoURG::m_com_port
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:265
mrpt::hwdrivers::CHokuyoURG::TSensorInfo::motor_speed_rpm
int motor_speed_rpm
Standard motor speed, rpm.
Definition: CHokuyoURG.h:93
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::hwdrivers::CHokuyoURG::switchLaserOff
bool switchLaserOff()
Switchs the laser off.
Definition: CHokuyoURG.cpp:633
mrpt::hwdrivers::CHokuyoURG::setIPandPort
void setIPandPort(const std::string &ip, const unsigned int &port)
Set the ip direction and port to connect using Ethernet communication.
Definition: CHokuyoURG.h:218
mrpt::hwdrivers::CHokuyoURG::TSensorInfo::model
std::string model
The sensor model.
Definition: CHokuyoURG.h:85
mrpt::hwdrivers::CHokuyoURG::m_rcv_data
std::string m_rcv_data
temp buffer for incoming data packets
Definition: CHokuyoURG.h:252
mrpt::hwdrivers::CHokuyoURG::~CHokuyoURG
virtual ~CHokuyoURG()
Destructor: turns the laser off.
Definition: CHokuyoURG.cpp:51
mrpt::hwdrivers::CHokuyoURG::setMotorSpeed
bool setMotorSpeed(int motoSpeed_rpm)
Changes the motor speed in rpm's (default 600rpm)
Definition: CHokuyoURG.cpp:661
mrpt::hwdrivers::CHokuyoURG::startScanningMode
bool startScanningMode()
Start the continuous scanning mode, using parameters stored in the object (loaded from the ....
Definition: CHokuyoURG.cpp:859
mrpt::hwdrivers::CHokuyoURG::doProcessSimple
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
mrpt::hwdrivers::CHokuyoURG::setScanInterval
void setScanInterval(unsigned int skipScanCount)
Set the skip scan count (0 means send all scans).
Definition: CHokuyoURG.cpp:656
mrpt::hwdrivers::CHokuyoURG::turnOn
bool turnOn()
Enables the scanning mode (which may depend on the specific laser device); this must be called before...
Definition: CHokuyoURG.cpp:271
uint32_t
unsigned __int32 uint32_t
Definition: rptypes.h:47
mrpt::hwdrivers::CHokuyoURG::m_sensor_info
TSensorInfo m_sensor_info
The information gathered when the laser is first open.
Definition: CHokuyoURG.h:275
mrpt::hwdrivers::CHokuyoURG::m_intensity
bool m_intensity
Get intensity from lidar scan (default: false)
Definition: CHokuyoURG.h:287
mrpt::hwdrivers::CHokuyoURG::setHighBaudrate
bool setHighBaudrate()
Passes to 115200bps bitrate.
Definition: CHokuyoURG.cpp:390
mrpt::hwdrivers::CHokuyoURG::m_highSensMode
bool m_highSensMode
High sensitivity [HS] mode (default: false)
Definition: CHokuyoURG.h:110
C2DRangeFinderAbstract.h
mrpt::hwdrivers::CHokuyoURG::m_sensorPose
poses::CPose3D m_sensorPose
The sensor 6D pose:
Definition: CHokuyoURG.h:102



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST