Main MRPT website > C++ reference for MRPT 1.5.5
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 URG/UTM/UXM/UST 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 */
71  struct TSensorInfo
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 
88  bool m_highSensMode; //!< High sensitivity [HS] mode (default: false)
89  mrpt::gui::CDisplayWindow3DPtr m_win;
90 
91  /** Enables the SCIP2.0 protocol (this must be called at the very begining!).
92  * \return false on any error
93  */
94  bool enableSCIP20();
95 
96  /** Passes to 115200bps bitrate.
97  * \return false on any error
98  */
99  bool setHighBaudrate();
100 
101  /** Switchs the laser on.
102  * \return false on any error
103  */
104  bool switchLaserOn();
105 
106  /** Switchs the laser off
107  * \return false on any error
108  */
109  bool switchLaserOff();
110 
111  /** Changes the motor speed in rpm's (default 600rpm)
112  * \return false on any error
113  */
114  bool setMotorSpeed(int motoSpeed_rpm);
115 
116  /** Ask to the device, and print to the debug stream, details about the firmware version,serial number,...
117  * \return false on any error
118  */
119  bool displayVersionInfo( );
120 
121  /** Ask to the device, and print to the debug stream, details about the sensor model.
122  * It also optionally saves all the information in an user supplied data structure "out_data".
123  * \return false on any error
124  */
125  bool displaySensorInfo( CHokuyoURG::TSensorInfo * out_data = NULL );
126 
127  /** Start the scanning mode, using parameters stored in the object (loaded from the .ini file)
128  * After this command the device will start to send scans until "switchLaserOff" is called.
129  * \return false on any error
130  */
131  bool startScanningMode();
132 
133  /** Turns the laser on */
134  void initialize();
135 
136  /** Waits for a response from the device.
137  * \return false on any error
138  */
139  bool receiveResponse(
140  const char *sentCmd_forEchoVerification,
141  char &rcv_status0,
142  char &rcv_status1,
143  char *rcv_data,
144  int &rcv_dataLength);
145 
146 
147  /** Assures a minimum number of bytes in the input buffer, reading from the serial port only if required.
148  * \return false if the number of bytes are not available, even after trying to fetch more data from the serial port.
149  */
150  bool assureBufferHasBytes(const size_t nDesiredBytes);
151 
152  public:
153  /** Constructor
154  */
155  CHokuyoURG();
156 
157  /** Destructor: turns the laser off */
158  virtual ~CHokuyoURG();
159 
160  /** Specific laser scanner "software drivers" must process here new data from the I/O stream, and, if a whole scan has arrived, return it.
161  * This method will be typically called in a different thread than other methods, and will be called in a timely fashion.
162  */
163  void doProcessSimple(
164  bool &outThereIsObservation,
165  mrpt::obs::CObservation2DRangeScan &outObservation,
166  bool &hardwareError );
167 
168  /** 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.
169  * \return If everything works "true", or "false" if there is any error.
170  */
171  bool turnOn();
172 
173  /** Disables the scanning mode (this can be used to turn the device in low energy mode, if available)
174  * \return If everything works "true", or "false" if there is any error.
175  */
176  bool turnOff();
177 
178  /** Empties the RX buffers of the serial port */
179  void purgeBuffers();
180 
181  /** 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. */
182  void setSerialPort(const std::string &port_name) { m_com_port = port_name; }
183 
184  /** Set the ip direction and port to connect using Ethernet communication */
185  void setIPandPort(const std::string &ip, const unsigned int &port) { m_ip_dir = ip; m_port_dir = port; }
186 
187  /** Returns the currently set serial port \sa setSerialPort */
188  const std::string getSerialPort() { return m_com_port; }
189 
190  /** 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.
191  * Call with "0" to disable this reduction again (the default).
192  */
193  void setReducedFOV(const double fov) { m_reduced_fov = fov; }
194 
195  /** Changes the high sensitivity mode (HS) (default: false)
196  * \return false on any error
197  */
198  bool setHighSensitivityMode(bool enabled);
199 
200  /** If true scans will capture intensity. (default: false)
201  * Should not be called while scanning.
202  * \return false on any error
203  */
204  bool setIntensityMode(bool enabled);
205 
206  protected:
207  /** 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"
208  */
209  bool checkCOMisOpen();
210 
211  double m_reduced_fov; //!< Used to reduce artificially the interval of scan ranges.
212 
213  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.
214 
215  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
216  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
217 
218  /** The information gathered when the laser is first open */
220 
222 
223  uint32_t m_timeStartUI; //!< Time of the first data packet, for synchronization purposes.
224  int m_timeStartSynchDelay; //!< Counter to discard to first few packets before setting the correspondence between device and computer timestamps.
227  bool m_intensity; //!< Get intensity from lidar scan (default: false)
228 
229  /** See the class documentation at the top for expected parameters */
230  void loadConfig_sensorSpecific(
231  const mrpt::utils::CConfigFileBase &configSource,
232  const std::string &iniSection );
233 
234  }; // End of class
235 
236  } // End of namespace
237 
238 } // End of namespace
239 
240 #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
const std::string getSerialPort()
Returns the currently set serial port.
Definition: CHokuyoURG.h:188
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:213
uint32_t m_timeStartUI
Time of the first data packet, for synchronization purposes.
Definition: CHokuyoURG.h:223
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:193
bool m_intensity
Get intensity from lidar scan (default: false)
Definition: CHokuyoURG.h:227
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:216
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:86
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:182
mrpt::gui::CDisplayWindow3DPtr m_win
Definition: CHokuyoURG.h:89
Used in CHokuyoURG::displayVersionInfo.
Definition: CHokuyoURG.h:71
int m_timeStartSynchDelay
Counter to discard to first few packets before setting the correspondence between device and computer...
Definition: CHokuyoURG.h:224
mrpt::system::TTimeStamp m_timeStartTT
Definition: CHokuyoURG.h:225
GLsizei const GLchar ** string
Definition: glext.h:3919
int m_motorSpeed_rpm
The motor speed (default=600rpm)
Definition: CHokuyoURG.h:82
#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:72
void setIPandPort(const std::string &ip, const unsigned int &port)
Set the ip direction and port to connect using Ethernet communication.
Definition: CHokuyoURG.h:185
This software driver implements the protocol SCIP-2.0 for interfacing HOKUYO URG/UTM/UXM/UST laser sc...
Definition: CHokuyoURG.h:65
poses::CPose3D m_sensorPose
The sensor 6D pose:
Definition: CHokuyoURG.h:83
TSensorInfo m_sensor_info
The information gathered when the laser is first open.
Definition: CHokuyoURG.h:219
bool m_highSensMode
High sensitivity [HS] mode (default: false)
Definition: CHokuyoURG.h:88
std::string model
The sensor model.
Definition: CHokuyoURG.h:73
double m_reduced_fov
Used to reduce artificially the interval of scan ranges.
Definition: CHokuyoURG.h:211
mrpt::utils::circular_buffer< uint8_t > m_rx_buffer
Auxiliary buffer for readings.
Definition: CHokuyoURG.h:84
int motor_speed_rpm
Standard motor speed, rpm.
Definition: CHokuyoURG.h:77
unsigned __int32 uint32_t
Definition: rptypes.h:49
int m_lastRange
The first and last ranges to consider from the scan.
Definition: CHokuyoURG.h:81
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:215
int scans_per_360deg
Number of measuremens per 360 degrees.
Definition: CHokuyoURG.h:75



Page generated by Doxygen 1.8.14 for MRPT 1.5.5 Git: e06b63dbf Fri Dec 1 14:41:11 2017 +0100 at lun oct 28 01:31:35 CET 2019