Main MRPT website > C++ reference for MRPT 1.9.9
rplidar_driver.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 /*
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright notice,
17  * this list of conditions and the following disclaimer in the documentation
18  * and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
33 
34 #pragma once
35 
36 #ifndef __cplusplus
37 #error "The RPlidar SDK requires a C++ compiler to be built"
38 #endif
39 
40 namespace rp
41 {
42 namespace standalone
43 {
44 namespace rplidar
45 {
47 {
48  public:
49  enum
50  {
51  DEFAULT_TIMEOUT = 2000, // 2000 ms
52  };
53 
54  enum
55  {
57  };
58 
59  public:
60  /// Create an RPLIDAR Driver Instance
61  /// This interface should be invoked first before any other operations
62  ///
63  /// \param drivertype the connection type used by the driver.
65  _u32 drivertype = DRIVER_TYPE_SERIALPORT);
66 
67  /// Dispose the RPLIDAR Driver Instance specified by the drv parameter
68  /// Applications should invoke this interface when the driver instance is no
69  /// longer used in order to free memory
70  static void DisposeDriver(RPlidarDriver* drv);
71 
72  public:
73  /// Open the specified serial port and connect to a target RPLIDAR device
74  ///
75  /// \param port_path the device path of the serial port
76  /// e.g. on Windows, it may be com3 or \\.\com10
77  /// on Unix-Like OS, it may be /dev/ttyS1, /dev/ttyUSB2, etc
78  ///
79  /// \param baudrate the baudrate used
80  /// For most RPLIDAR models, the baudrate should be set to 115200
81  ///
82  /// \param flag other flags
83  /// Reserved for future use, always set to Zero
84  virtual u_result connect(
85  const char* port_path, _u32 baudrate, _u32 flag = 0) = 0;
86 
87  /// Disconnect with the RPLIDAR and close the serial port
88  virtual void disconnect() = 0;
89 
90  /// Returns TRUE when the connection has been established
91  virtual bool isConnected() = 0;
92 
93  /// Ask the RPLIDAR core system to reset it self
94  /// The host system can use the Reset operation to help RPLIDAR escape the
95  /// self-protection mode.
96  ///
97  // \param timeout The operation timeout value (in millisecond) for
98  // the serial port communication
99  virtual u_result reset(_u32 timeout = DEFAULT_TIMEOUT) = 0;
100 
101  /// Retrieve the health status of the RPLIDAR
102  /// The host system can use this operation to check whether RPLIDAR is in
103  /// the self-protection mode.
104  ///
105  /// \param health The health status info returned from the RPLIDAR
106  ///
107  /// \param timeout The operation timeout value (in millisecond) for
108  /// the serial port communication
109  virtual u_result getHealth(
110  rplidar_response_device_health_t& health,
111  _u32 timeout = DEFAULT_TIMEOUT) = 0;
112 
113  /// Get the device information of the RPLIDAR include the serial number,
114  /// firmware version, device model etc.
115  ///
116  /// \param info The device information returned from the RPLIDAR
117  ///
118  /// \param timeout The operation timeout value (in millisecond) for
119  /// the serial port communication
120  virtual u_result getDeviceInfo(
121  rplidar_response_device_info_t& info,
122  _u32 timeout = DEFAULT_TIMEOUT) = 0;
123 
124  /// Get the sample duration information of the RPLIDAR.
125  ///
126  /// \param rateInfo The sample duration information returned from the
127  /// RPLIDAR
128  ///
129  /// \param timeout The operation timeout value (in millisecond) for
130  /// the serial port communication
132  rplidar_response_sample_rate_t& rateInfo,
133  _u32 timeout = DEFAULT_TIMEOUT) = 0;
134 
135  /// Set the RPLIDAR's motor pwm when using accessory board, currently valid
136  /// for A2 only.
137  ///
138  /// \param pwm The motor pwm value would like to set
139  virtual u_result setMotorPWM(_u16 pwm) = 0;
140 
141  /// Start RPLIDAR's motor when using accessory board
142  virtual u_result startMotor() = 0;
143 
144  /// Stop RPLIDAR's motor when using accessory board
145  virtual u_result stopMotor() = 0;
146 
147  /// Check whether the device support motor control.
148  /// Note: this API will disable grab.
149  ///
150  /// \param support Return the result.
151  ///
152  /// \param timeout The operation timeout value (in millisecond) for
153  /// the serial port communication.
155  bool& support, _u32 timeout = DEFAULT_TIMEOUT) = 0;
156 
157  /// Calcuate RPLIDAR's current scanning frequency from the given scan data
158  /// Please refer to the application note doc for details
159  /// Remark: the calcuation will be incorrect if the specified scan data
160  /// doesn't contains enough data
161  ///
162  /// \param inExpressMode Indicate whether the RPLIDAR is in express mode
163  ///
164  /// \param count The number of sample nodes inside the given buffer
165  ///
166  /// \param frequency The scanning frequency (in HZ) calcuated by the
167  /// interface.
168  ///
169  /// \param is4kmode Return whether the RPLIDAR is working on 4k sample
170  /// rate mode.
171  virtual u_result getFrequency(
172  bool inExpressMode, size_t count, float& frequency, bool& is4kmode) = 0;
173 
174  /// Ask the RPLIDAR core system to enter the scan mode(Normal/Express,
175  /// Express mode is 4k mode)
176  /// A background thread will be created by the RPLIDAR driver to fetch the
177  /// scan data continuously.
178  /// User Application can use the grabScanData() interface to retrieved the
179  /// scan data cached previous by this background thread.
180  ///
181  /// \param force Force the core system to output scan data
182  /// regardless whether the scanning motor is rotating or not.
183  ///
184  /// \param autoExpressMode Force the core system to trying express mode
185  /// first, if the system does not support express mode, it will use normal
186  /// mode.
187  ///
188  /// \param timeout The operation timeout value (in millisecond) for
189  /// the serial port communication.
190  virtual u_result startScan(
191  bool force = false, bool autoExpressMode = true) = 0;
192  virtual u_result startScanNormal(
193  bool force, _u32 timeout = DEFAULT_TIMEOUT) = 0;
194  virtual u_result startScanExpress(
195  bool fixedAngle, _u32 timeout = DEFAULT_TIMEOUT) = 0;
196 
197  /// Check whether the device support express mode.
198  ///
199  /// \param support Return the result.
200  ///
201  /// \param timeout The operation timeout value (in millisecond) for
202  /// the serial port communication.
204  bool& support, _u32 timeout = DEFAULT_TIMEOUT) = 0;
205 
206  /// Ask the RPLIDAR core system to stop the current scan operation and enter
207  /// idle state. The background thread will be terminated
208  ///
209  /// \param timeout The operation timeout value (in millisecond) for
210  /// the serial port communication
211  virtual u_result stop(_u32 timeout = DEFAULT_TIMEOUT) = 0;
212 
213  /// Wait and grab a complete 0-360 degree scan data previously received.
214  /// The grabbed scan data returned by this interface always has the
215  /// following charactistics:
216  ///
217  /// 1) The first node of the grabbed data array (nodebuffer[0]) must be the
218  /// first sample of a scan, i.e. the start_bit == 1
219  /// 2) All data nodes are belong to exactly ONE complete 360-degrees's scan
220  /// 3) Note, the angle data in one scan may not be ascending. You can use
221  /// API ascendScanData to reorder the nodebuffer.
222  ///
223  /// \param nodebuffer Buffer provided by the caller application to store
224  /// the scan data
225  ///
226  /// \param count The caller must initialize this parameter to set
227  /// the max data count of the provided buffer (in unit of
228  /// rplidar_response_measurement_node_t).
229  /// Once the interface returns, this parameter will
230  /// store the actual received data count.
231  ///
232  /// \param timeout Max duration allowed to wait for a complete scan
233  /// data, nothing will be stored to the nodebuffer if a complete
234  /// 360-degrees' scan data cannot to be ready timely.
235  ///
236  /// The interface will return RESULT_OPERATION_TIMEOUT to indicate that no
237  /// complete 360-degrees' scan can be retrieved withing the given timeout
238  /// duration.
239  ///
240  /// \The caller application can set the timeout value to Zero(0) to make
241  /// this interface always returns immediately to achieve non-block
242  /// operation.
243  virtual u_result grabScanData(
244  rplidar_response_measurement_node_t* nodebuffer, size_t& count,
245  _u32 timeout = DEFAULT_TIMEOUT) = 0;
246 
247  /// Ascending the scan data according to the angle value in the scan.
248  ///
249  /// \param nodebuffer Buffer provided by the caller application to do
250  /// the reorder. Should be retrived from the grabScanData
251  ///
252  /// \param count The caller must initialize this parameter to set
253  /// the max data count of the provided buffer (in unit of
254  /// rplidar_response_measurement_node_t).
255  /// Once the interface returns, this parameter will
256  /// store the actual received data count.
257  /// The interface will return RESULT_OPERATION_FAIL when all the scan data
258  /// is invalid.
259  virtual u_result ascendScanData(
260  rplidar_response_measurement_node_t* nodebuffer, size_t count) = 0;
261 
262  protected:
264  virtual ~RPlidarDriver() {}
265 };
266 }
267 }
268 }
virtual u_result getHealth(rplidar_response_device_health_t &health, _u32 timeout=DEFAULT_TIMEOUT)=0
Retrieve the health status of the RPLIDAR The host system can use this operation to check whether RPL...
virtual u_result connect(const char *port_path, _u32 baudrate, _u32 flag=0)=0
Open the specified serial port and connect to a target RPLIDAR device.
GLuint GLuint GLsizei count
Definition: glext.h:3528
virtual u_result startScan(bool force=false, bool autoExpressMode=true)=0
Ask the RPLIDAR core system to enter the scan mode(Normal/Express, Express mode is 4k mode) A backgro...
virtual u_result startScanExpress(bool fixedAngle, _u32 timeout=DEFAULT_TIMEOUT)=0
virtual u_result reset(_u32 timeout=DEFAULT_TIMEOUT)=0
Ask the RPLIDAR core system to reset it self The host system can use the Reset operation to help RPLI...
virtual u_result grabScanData(rplidar_response_measurement_node_t *nodebuffer, size_t &count, _u32 timeout=DEFAULT_TIMEOUT)=0
Wait and grab a complete 0-360 degree scan data previously received.
virtual u_result startScanNormal(bool force, _u32 timeout=DEFAULT_TIMEOUT)=0
virtual u_result setMotorPWM(_u16 pwm)=0
Set the RPLIDAR's motor pwm when using accessory board, currently valid for A2 only.
virtual u_result stop(_u32 timeout=DEFAULT_TIMEOUT)=0
Ask the RPLIDAR core system to stop the current scan operation and enter idle state.
virtual u_result checkMotorCtrlSupport(bool &support, _u32 timeout=DEFAULT_TIMEOUT)=0
Check whether the device support motor control.
virtual u_result stopMotor()=0
Stop RPLIDAR's motor when using accessory board.
virtual u_result getFrequency(bool inExpressMode, size_t count, float &frequency, bool &is4kmode)=0
Calcuate RPLIDAR's current scanning frequency from the given scan data Please refer to the applicatio...
virtual bool isConnected()=0
Returns TRUE when the connection has been established.
virtual u_result checkExpressScanSupported(bool &support, _u32 timeout=DEFAULT_TIMEOUT)=0
Check whether the device support express mode.
virtual u_result startMotor()=0
Start RPLIDAR's motor when using accessory board.
uint32_t _u32
Definition: rptypes.h:66
virtual u_result ascendScanData(rplidar_response_measurement_node_t *nodebuffer, size_t count)=0
Ascending the scan data according to the angle value in the scan.
uint16_t _u16
Definition: rptypes.h:63
static RPlidarDriver * CreateDriver(_u32 drivertype=DRIVER_TYPE_SERIALPORT)
Create an RPLIDAR Driver Instance This interface should be invoked first before any other operations...
virtual void disconnect()=0
Disconnect with the RPLIDAR and close the serial port.
virtual u_result getSampleDuration_uS(rplidar_response_sample_rate_t &rateInfo, _u32 timeout=DEFAULT_TIMEOUT)=0
Get the sample duration information of the RPLIDAR.
static void DisposeDriver(RPlidarDriver *drv)
Dispose the RPLIDAR Driver Instance specified by the drv parameter Applications should invoke this in...
virtual u_result getDeviceInfo(rplidar_response_device_info_t &info, _u32 timeout=DEFAULT_TIMEOUT)=0
Get the device information of the RPLIDAR include the serial number, firmware version, device model etc.
uint32_t u_result
Definition: rptypes.h:95



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019