Main MRPT website > C++ reference for MRPT 1.4.0
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-2016, 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
17namespace 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 (USB or Ethernet)
22 * Refer to the example code [HOKUYO_laser_test](http://www.mrpt.org/tutorials/mrpt-examples/example_hokuyo_urgutm_laser_scanner/)
23 * and to example rawlog-grabber [config files](https://github.com/MRPT/mrpt/tree/master/share/mrpt/config_files/rawlog-grabber)
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 *
34 * # Uncomment serial port or IP address, depending on the Hokuyo model (serial/USB vs. Ethernet):
35 * COM_port_WIN = COM3 // Serial port name in Windows
36 * COM_port_LIN = ttyS0 // Serial port name in GNU/Linux
37 * #IP_DIR = 192.168.0.10 // Uncommented this and "PORT_DIR" if the used HOKUYO is connected by Ethernet instead of USB
38 * #PORT_DIR = 10940 // Default value: 10940
39 *
40 * pose_x=0.21 // Laser range scaner 3D position in the robot (meters)
41 * pose_y=0
42 * pose_z=0.34
43 * pose_yaw=0 // Angles in degrees
44 * pose_pitch=0
45 * pose_roll=0
46 *
47 * #disable_firmware_timestamp = true // Uncomment to use PC time instead of laser time
48 *
49 * # Optional: reduced FOV:
50 * # reduced_fov = 25 // Deg
51 *
52 * #preview = true // Enable GUI visualization of captured data
53 *
54 * # Optional: Exclusion zones to avoid the robot seeing itself:
55 * #exclusionZone1_x = 0.20 0.30 0.30 0.20
56 * #exclusionZone1_y = 0.20 0.30 0.30 0.20
57 *
58 * # Optional: Exclusion zones to avoid the robot seeing itself:
59 * #exclusionAngles1_ini = 20 // Deg
60 * #exclusionAngles1_end = 25 // Deg
61 *
62 * \endcode
63 * \ingroup mrpt_hwdrivers_grp
64 */
66 {
68 public:
69
70 /** Used in CHokuyoURG::displayVersionInfo */
72 {
73 std::string model; //!< The sensor model
74 double d_min,d_max; //!< Min/Max ranges, in meters.
75 int scans_per_360deg; //!< Number of measuremens per 360 degrees.
76 int scan_first,scan_last, scan_front; //!< First, last, and front step of the scanner angular span.
77 int motor_speed_rpm; //!< Standard motor speed, rpm.
78 };
79
80 private:
81 int m_firstRange,m_lastRange; //!< The first and last ranges to consider from the scan.
82 int m_motorSpeed_rpm; //!< The motor speed (default=600rpm)
83 poses::CPose3D m_sensorPose; //!< The sensor 6D pose:
84 mrpt::utils::circular_buffer<uint8_t> m_rx_buffer; //!< Auxiliary buffer for readings
85
86 std::string m_lastSentMeasCmd; //!< The last sent measurement command (MDXXX), including the last 0x0A.
87
89 bool m_highSensMode; //!< High sensitivity [HS] mode (default: false)
91
92 /** Enables the SCIP2.0 protocol (this must be called at the very begining!).
93 * \return false on any error
94 */
96
97 /** Passes to 115200bps bitrate.
98 * \return false on any error
99 */
101
102 /** Switchs the laser on.
103 * \return false on any error
104 */
106
107 /** Switchs the laser off
108 * \return false on any error
109 */
111
112 /** Changes the motor speed in rpm's (default 600rpm)
113 * \return false on any error
114 */
115 bool setMotorSpeed(int motoSpeed_rpm);
116
117 /** Ask to the device, and print to the debug stream, details about the firmware version,serial number,...
118 * \return false on any error
119 */
121
122 /** Ask to the device, and print to the debug stream, details about the sensor model.
123 * It also optionally saves all the information in an user supplied data structure "out_data".
124 * \return false on any error
125 */
127
128 /** Start the scanning mode, using parameters stored in the object (loaded from the .ini file)
129 * After this command the device will start to send scans until "switchLaserOff" is called.
130 * \return false on any error
131 */
133
134 /** Turns the laser on */
136
137 /** Waits for a response from the device.
138 * \return false on any error
139 */
141 const char *sentCmd_forEchoVerification,
142 char &rcv_status0,
143 char &rcv_status1,
144 char *rcv_data,
145 int &rcv_dataLength);
146
147
148 /** Assures a minimum number of bytes in the input buffer, reading from the serial port only if required.
149 * \return false if the number of bytes are not available, even after trying to fetch more data from the serial port.
150 */
151 bool assureBufferHasBytes(const size_t nDesiredBytes);
152
153 public:
154 /** Constructor
155 */
157
158 /** Destructor: turns the laser off */
159 virtual ~CHokuyoURG();
160
161 /** Specific laser scanner "software drivers" must process here new data from the I/O stream, and, if a whole scan has arrived, return it.
162 * This method will be typically called in a different thread than other methods, and will be called in a timely fashion.
163 */
165 bool &outThereIsObservation,
167 bool &hardwareError );
168
169 /** 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.
170 * \return If everything works "true", or "false" if there is any error.
171 */
172 bool turnOn();
173
174 /** Disables the scanning mode (this can be used to turn the device in low energy mode, if available)
175 * \return If everything works "true", or "false" if there is any error.
176 */
177 bool turnOff();
178
179 /** Empties the RX buffers of the serial port */
181
182 /** 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. */
183 void setSerialPort(const std::string &port_name) { m_com_port = port_name; }
184
185 /** Set the ip direction and port to connect using Ethernet communication */
186 void setIPandPort(const std::string &ip, const unsigned int &port) { m_ip_dir = ip; m_port_dir = port; }
187
188 /** Returns the currently set serial port \sa setSerialPort */
189 const std::string getSerialPort() { return m_com_port; }
190
191 /** 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.
192 * Call with "0" to disable this reduction again (the default).
193 */
194 void setReducedFOV(const double fov) { m_reduced_fov = fov; }
195
196 /** Changes the high sensitivity mode (HS) (default: false)
197 * \return false on any error
198 */
199 bool setHighSensitivityMode(bool enabled);
200
201 void setVerbose(bool enable = true) { m_verbose = enable; }
202
203
204 protected:
205 /** 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"
206 */
208
209 double m_reduced_fov; //!< Used to reduce artificially the interval of scan ranges.
210
211 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.
212
213 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
214 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
215
216 /** The information gathered when the laser is first open */
218
220
221 uint32_t m_timeStartUI; //!< Time of the first data packet, for synchronization purposes.
222 int m_timeStartSynchDelay; //!< Counter to discard to first few packets before setting the correspondence between device and computer timestamps.
225
226 /** See the class documentation at the top for expected parameters */
228 const mrpt::utils::CConfigFileBase &configSource,
229 const std::string &iniSection );
230
231 }; // End of class
232
233 } // End of namespace
234
235} // End of namespace
236
237#endif
#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 software driver implements the protocol SCIP-2.0 for interfacing HOKUYO URG, UTM and UXM laser s...
Definition: CHokuyoURG.h:66
TSensorInfo m_sensor_info
The information gathered when the laser is first open.
Definition: CHokuyoURG.h:217
mrpt::system::TTimeStamp m_timeStartTT
Definition: CHokuyoURG.h:223
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.
void purgeBuffers()
Empties the RX buffers of the serial port.
uint32_t m_timeStartUI
Time of the first data packet, for synchronization purposes.
Definition: CHokuyoURG.h:221
bool displayVersionInfo()
Ask to the device, and print to the debug stream, details about the firmware version,...
bool m_highSensMode
High sensitivity [HS] mode (default: false)
Definition: CHokuyoURG.h:89
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:214
bool setHighSensitivityMode(bool enabled)
Changes the high sensitivity mode (HS) (default: false)
bool displaySensorInfo(CHokuyoURG::TSensorInfo *out_data=NULL)
Ask to the device, and print to the debug stream, details about the sensor model.
bool setMotorSpeed(int motoSpeed_rpm)
Changes the motor speed in rpm's (default 600rpm)
void setIPandPort(const std::string &ip, const unsigned int &port)
Set the ip direction and port to connect using Ethernet communication.
Definition: CHokuyoURG.h:186
bool setHighBaudrate()
Passes to 115200bps bitrate.
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:211
const std::string getSerialPort()
Returns the currently set serial port.
Definition: CHokuyoURG.h:189
bool assureBufferHasBytes(const size_t nDesiredBytes)
Assures a minimum number of bytes in the input buffer, reading from the serial port only if required.
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:183
virtual ~CHokuyoURG()
Destructor: turns the laser off.
mrpt::utils::circular_buffer< uint8_t > m_rx_buffer
Auxiliary buffer for readings.
Definition: CHokuyoURG.h:84
double m_reduced_fov
Used to reduce artificially the interval of scan ranges.
Definition: CHokuyoURG.h:209
poses::CPose3D m_sensorPose
The sensor 6D pose:
Definition: CHokuyoURG.h:83
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:194
bool checkCOMisOpen()
Returns true if there is a valid stream bound to the laser scanner, otherwise it first try to open th...
void initialize()
Turns the laser on.
mrpt::gui::CDisplayWindow3DPtr m_win
Definition: CHokuyoURG.h:90
bool enableSCIP20()
Enables the SCIP2.0 protocol (this must be called at the very begining!).
bool switchLaserOff()
Switchs the laser off.
void loadConfig_sensorSpecific(const mrpt::utils::CConfigFileBase &configSource, const std::string &iniSection)
See the class documentation at the top for expected parameters.
void setVerbose(bool enable=true)
Definition: CHokuyoURG.h:201
bool turnOn()
Enables the scanning mode (which may depend on the specific laser device); this must be called before...
bool startScanningMode()
Start the scanning mode, using parameters stored in the object (loaded from the .ini file) After this...
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:213
bool turnOff()
Disables the scanning mode (this can be used to turn the device in low energy mode,...
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,...
int m_timeStartSynchDelay
Counter to discard to first few packets before setting the correspondence between device and computer...
Definition: CHokuyoURG.h:222
std::string m_lastSentMeasCmd
The last sent measurement command (MDXXX), including the last 0x0A.
Definition: CHokuyoURG.h:86
bool switchLaserOn()
Switchs the laser on.
int m_motorSpeed_rpm
The motor speed (default=600rpm)
Definition: CHokuyoURG.h:82
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:73
This class allows loading and storing values and vectors of different types from a configuration text...
A circular buffer of fixed size (defined at construction-time), implemented with a std::vector as the...
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1,...
Definition: datetime.h:30
#define HWDRIVERS_IMPEXP
struct GUI_IMPEXP CDisplayWindow3DPtr
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
unsigned long uint32_t
Definition: pstdint.h:216
Used in CHokuyoURG::displayVersionInfo.
Definition: CHokuyoURG.h:72
std::string model
The sensor model.
Definition: CHokuyoURG.h:73
int scans_per_360deg
Number of measuremens per 360 degrees.
Definition: CHokuyoURG.h:75
double d_max
Min/Max ranges, in meters.
Definition: CHokuyoURG.h:74
int motor_speed_rpm
Standard motor speed, rpm.
Definition: CHokuyoURG.h:77



Page generated by Doxygen 1.9.5 for MRPT 1.4.0 SVN: at Sun Nov 27 02:56:59 UTC 2022