MRPT  1.9.9
rplidar_driver.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://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 
41 {
43 {
44  public:
45  enum
46  {
47  DEFAULT_TIMEOUT = 2000, // 2000 ms
48  };
49 
50  enum
51  {
53  };
54 
55  public:
56  /// Create an RPLIDAR Driver Instance
57  /// This interface should be invoked first before any other operations
58  ///
59  /// \param drivertype the connection type used by the driver.
61  _u32 drivertype = DRIVER_TYPE_SERIALPORT);
62 
63  /// Dispose the RPLIDAR Driver Instance specified by the drv parameter
64  /// Applications should invoke this interface when the driver instance is no
65  /// longer used in order to free memory
66  static void DisposeDriver(RPlidarDriver* drv);
67 
68  public:
69  /// Open the specified serial port and connect to a target RPLIDAR device
70  ///
71  /// \param port_path the device path of the serial port
72  /// e.g. on Windows, it may be com3 or \\.\com10
73  /// on Unix-Like OS, it may be /dev/ttyS1, /dev/ttyUSB2, etc
74  ///
75  /// \param baudrate the baudrate used
76  /// For most RPLIDAR models, the baudrate should be set to 115200
77  ///
78  /// \param flag other flags
79  /// Reserved for future use, always set to Zero
80  virtual u_result connect(
81  const char* port_path, _u32 baudrate, _u32 flag = 0) = 0;
82 
83  /// Disconnect with the RPLIDAR and close the serial port
84  virtual void disconnect() = 0;
85 
86  /// Returns TRUE when the connection has been established
87  virtual bool isConnected() = 0;
88 
89  /// Ask the RPLIDAR core system to reset it self
90  /// The host system can use the Reset operation to help RPLIDAR escape the
91  /// self-protection mode.
92  ///
93  // \param timeout The operation timeout value (in millisecond) for
94  // the serial port communication
95  virtual u_result reset(_u32 timeout = DEFAULT_TIMEOUT) = 0;
96 
97  /// Retrieve the health status of the RPLIDAR
98  /// The host system can use this operation to check whether RPLIDAR is in
99  /// the self-protection mode.
100  ///
101  /// \param health The health status info returned from the RPLIDAR
102  ///
103  /// \param timeout The operation timeout value (in millisecond) for
104  /// the serial port communication
105  virtual u_result getHealth(
106  rplidar_response_device_health_t& health,
107  _u32 timeout = DEFAULT_TIMEOUT) = 0;
108 
109  /// Get the device information of the RPLIDAR include the serial number,
110  /// firmware version, device model etc.
111  ///
112  /// \param info The device information returned from the RPLIDAR
113  ///
114  /// \param timeout The operation timeout value (in millisecond) for
115  /// the serial port communication
116  virtual u_result getDeviceInfo(
117  rplidar_response_device_info_t& info,
118  _u32 timeout = DEFAULT_TIMEOUT) = 0;
119 
120  /// Get the sample duration information of the RPLIDAR.
121  ///
122  /// \param rateInfo The sample duration information returned from the
123  /// RPLIDAR
124  ///
125  /// \param timeout The operation timeout value (in millisecond) for
126  /// the serial port communication
128  rplidar_response_sample_rate_t& rateInfo,
129  _u32 timeout = DEFAULT_TIMEOUT) = 0;
130 
131  /// Set the RPLIDAR's motor pwm when using accessory board, currently valid
132  /// for A2 only.
133  ///
134  /// \param pwm The motor pwm value would like to set
135  virtual u_result setMotorPWM(_u16 pwm) = 0;
136 
137  /// Start RPLIDAR's motor when using accessory board
138  virtual u_result startMotor() = 0;
139 
140  /// Stop RPLIDAR's motor when using accessory board
141  virtual u_result stopMotor() = 0;
142 
143  /// Check whether the device support motor control.
144  /// Note: this API will disable grab.
145  ///
146  /// \param support Return the result.
147  ///
148  /// \param timeout The operation timeout value (in millisecond) for
149  /// the serial port communication.
151  bool& support, _u32 timeout = DEFAULT_TIMEOUT) = 0;
152 
153  /// Calcuate RPLIDAR's current scanning frequency from the given scan data
154  /// Please refer to the application note doc for details
155  /// Remark: the calcuation will be incorrect if the specified scan data
156  /// doesn't contains enough data
157  ///
158  /// \param inExpressMode Indicate whether the RPLIDAR is in express mode
159  ///
160  /// \param count The number of sample nodes inside the given buffer
161  ///
162  /// \param frequency The scanning frequency (in HZ) calcuated by the
163  /// interface.
164  ///
165  /// \param is4kmode Return whether the RPLIDAR is working on 4k sample
166  /// rate mode.
167  virtual u_result getFrequency(
168  bool inExpressMode, size_t count, float& frequency, bool& is4kmode) = 0;
169 
170  /// Ask the RPLIDAR core system to enter the scan mode(Normal/Express,
171  /// Express mode is 4k mode)
172  /// A background thread will be created by the RPLIDAR driver to fetch the
173  /// scan data continuously.
174  /// User Application can use the grabScanData() interface to retrieved the
175  /// scan data cached previous by this background thread.
176  ///
177  /// \param force Force the core system to output scan data
178  /// regardless whether the scanning motor is rotating or not.
179  ///
180  /// \param autoExpressMode Force the core system to trying express mode
181  /// first, if the system does not support express mode, it will use normal
182  /// mode.
183  ///
184  /// \param timeout The operation timeout value (in millisecond) for
185  /// the serial port communication.
186  virtual u_result startScan(
187  bool force = false, bool autoExpressMode = true) = 0;
188  virtual u_result startScanNormal(
189  bool force, _u32 timeout = DEFAULT_TIMEOUT) = 0;
190  virtual u_result startScanExpress(
191  bool fixedAngle, _u32 timeout = DEFAULT_TIMEOUT) = 0;
192 
193  /// Check whether the device support express mode.
194  ///
195  /// \param support Return the result.
196  ///
197  /// \param timeout The operation timeout value (in millisecond) for
198  /// the serial port communication.
200  bool& support, _u32 timeout = DEFAULT_TIMEOUT) = 0;
201 
202  /// Ask the RPLIDAR core system to stop the current scan operation and enter
203  /// idle state. The background thread will be terminated
204  ///
205  /// \param timeout The operation timeout value (in millisecond) for
206  /// the serial port communication
207  virtual u_result stop(_u32 timeout = DEFAULT_TIMEOUT) = 0;
208 
209  /// Wait and grab a complete 0-360 degree scan data previously received.
210  /// The grabbed scan data returned by this interface always has the
211  /// following charactistics:
212  ///
213  /// 1) The first node of the grabbed data array (nodebuffer[0]) must be the
214  /// first sample of a scan, i.e. the start_bit == 1
215  /// 2) All data nodes are belong to exactly ONE complete 360-degrees's scan
216  /// 3) Note, the angle data in one scan may not be ascending. You can use
217  /// API ascendScanData to reorder the nodebuffer.
218  ///
219  /// \param nodebuffer Buffer provided by the caller application to store
220  /// the scan data
221  ///
222  /// \param count The caller must initialize this parameter to set
223  /// the max data count of the provided buffer (in unit of
224  /// rplidar_response_measurement_node_t).
225  /// Once the interface returns, this parameter will
226  /// store the actual received data count.
227  ///
228  /// \param timeout Max duration allowed to wait for a complete scan
229  /// data, nothing will be stored to the nodebuffer if a complete
230  /// 360-degrees' scan data cannot to be ready timely.
231  ///
232  /// The interface will return RESULT_OPERATION_TIMEOUT to indicate that no
233  /// complete 360-degrees' scan can be retrieved withing the given timeout
234  /// duration.
235  ///
236  /// \The caller application can set the timeout value to Zero(0) to make
237  /// this interface always returns immediately to achieve non-block
238  /// operation.
239  virtual u_result grabScanData(
240  rplidar_response_measurement_node_t* nodebuffer, size_t& count,
241  _u32 timeout = DEFAULT_TIMEOUT) = 0;
242 
243  /// Ascending the scan data according to the angle value in the scan.
244  ///
245  /// \param nodebuffer Buffer provided by the caller application to do
246  /// the reorder. Should be retrived from the grabScanData
247  ///
248  /// \param count The caller must initialize this parameter to set
249  /// the max data count of the provided buffer (in unit of
250  /// rplidar_response_measurement_node_t).
251  /// Once the interface returns, this parameter will
252  /// store the actual received data count.
253  /// The interface will return RESULT_OPERATION_FAIL when all the scan data
254  /// is invalid.
255  virtual u_result ascendScanData(
256  rplidar_response_measurement_node_t* nodebuffer, size_t count) = 0;
257 
258  protected:
259  RPlidarDriver() = default;
260  virtual ~RPlidarDriver() = default;
261 };
262 } // namespace rp::standalone::rplidar
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:3532
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:69
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:66
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:98



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019