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



Page generated by Doxygen 1.8.11 for MRPT 1.3.2 SVN: at Mon May 9 06:50:38 UTC 2016