Debian Codegraph @

3rdparty/rplidar_sdk/sdk/include/rplidar_driver.h

raw symbols SCIP
1 /*
2 * RPLIDAR SDK
3 *
4 * Copyright (c) 2009 - 2014 RoboPeak Team
5 * http://www.robopeak.com
6 * Copyright (c) 2014 - 2019 Shanghai Slamtec Co., Ltd.
7 * http://www.slamtec.com
8 *
9 */
10 /*
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 *
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 */
34
35 #pragma once
36 #include "sl_lidar_driver.h"
37
38 #ifndef __cplusplus
39 #error "The RPlidar SDK requires a C++ compiler to be built"
40 #endif
41
42
43 namespace rp { namespace standalone{ namespace rplidar {
44 using namespace sl;
45 typedef LidarScanMode RplidarScanMode;
46
47 enum {
48 DRIVER_TYPE_SERIALPORT = 0x0,
49 DRIVER_TYPE_TCP = 0x1,
50 DRIVER_TYPE_UDP = 0x2,
51 };
52
53 class RPlidarDriver {
54 public:
55 enum {
56 DEFAULT_TIMEOUT = 2000, //2000 ms
57 };
58
59 enum {
60 MAX_SCAN_NODES = 8192,
61 };
62
63 enum {
64 LEGACY_SAMPLE_DURATION = 476,
65 };
66
67 public:
68 /// Create an RPLIDAR Driver Instance
69 /// This interface should be invoked first before any other operations
70 ///
71 /// \param drivertype the connection type used by the driver.
72 static RPlidarDriver * CreateDriver(_u32 drivertype = CHANNEL_TYPE_SERIALPORT);
73
74
75 RPlidarDriver(sl_u32 channelType);
76
77 /// Dispose the RPLIDAR Driver Instance specified by the drv parameter
78 /// Applications should invoke this interface when the driver instance is no longer used in order to free memory
79 static void DisposeDriver(RPlidarDriver * drv);
80
81 /// Open the specified serial port and connect to a target RPLIDAR device
82 ///
83 /// \param port_path the device path of the serial port
84 /// e.g. on Windows, it may be com3 or \\.\com10
85 /// on Unix-Like OS, it may be /dev/ttyS1, /dev/ttyUSB2, etc
86 ///
87 /// \param baudrate the baudrate used
88 /// For most RPLIDAR models, the baudrate should be set to 115200
89 ///
90 /// \param flag other flags
91 /// Reserved for future use, always set to Zero
92 u_result connect(const char *path, _u32 portOrBaud, _u32 flag = 0);
93
94 /// Disconnect with the RPLIDAR and close the serial port
95 void disconnect();
96
97 /// Returns TRUE when the connection has been established
98 bool isConnected();
99
100 /// Ask the RPLIDAR core system to reset it self
101 /// The host system can use the Reset operation to help RPLIDAR escape the self-protection mode.
102 ///
103 /// \param timeout The operation timeout value (in millisecond) for the serial port communication
104 u_result reset(_u32 timeout = DEFAULT_TIMEOUT);
105
106 u_result clearNetSerialRxCache() {
107 return RESULT_OK;
108 }
109 // FW1.24
110 /// Get all scan modes that supported by lidar
111 u_result getAllSupportedScanModes(std::vector<RplidarScanMode>& outModes, _u32 timeoutInMs = DEFAULT_TIMEOUT);
112
113 /// Get typical scan mode of lidar
114 u_result getTypicalScanMode(_u16& outMode, _u32 timeoutInMs = DEFAULT_TIMEOUT);
115
116 /// Start scan
117 ///
118 /// \param force Force the core system to output scan data regardless whether the scanning motor is rotating or not.
119 /// \param useTypicalScan Use lidar's typical scan mode or use the compatibility mode (2k sps)
120 /// \param options Scan options (please use 0)
121 /// \param outUsedScanMode The scan mode selected by lidar
122 u_result startScan(bool force, bool useTypicalScan, _u32 options = 0, RplidarScanMode* outUsedScanMode = NULL);
123
124 /// Start scan in specific mode
125 ///
126 /// \param force Force the core system to output scan data regardless whether the scanning motor is rotating or not.
127 /// \param scanMode The scan mode id (use getAllSupportedScanModes to get supported modes)
128 /// \param options Scan options (please use 0)
129 /// \param outUsedScanMode The scan mode selected by lidar
130 u_result startScanExpress(bool force, _u16 scanMode, _u32 options = 0, RplidarScanMode* outUsedScanMode = NULL, _u32 timeout = DEFAULT_TIMEOUT);
131
132 /// Retrieve the health status of the RPLIDAR
133 /// The host system can use this operation to check whether RPLIDAR is in the self-protection mode.
134 ///
135 /// \param health The health status info returned from the RPLIDAR
136 ///
137 /// \param timeout The operation timeout value (in millisecond) for the serial port communication
138 u_result getHealth(rplidar_response_device_health_t & health, _u32 timeout = DEFAULT_TIMEOUT);
139
140 /// Get the device information of the RPLIDAR include the serial number, firmware version, device model etc.
141 ///
142 /// \param info The device information returned from the RPLIDAR
143 /// \param timeout The operation timeout value (in millisecond) for the serial port communication
144 u_result getDeviceInfo(rplidar_response_device_info_t & info, _u32 timeout = DEFAULT_TIMEOUT);
145
146 /// Set the RPLIDAR's motor pwm when using accessory board, currently valid for A2 only.
147 ///
148 /// \param pwm The motor pwm value would like to set
149 u_result setMotorPWM(_u16 pwm);
150
151 /// Start RPLIDAR's motor when using accessory board
152 u_result startMotor();
153
154 /// Stop RPLIDAR's motor when using accessory board
155 u_result stopMotor();
156
157 /// Check whether the device support motor control.
158 /// Note: this API will disable grab.
159 ///
160 /// \param support Return the result.
161 /// \param timeout The operation timeout value (in millisecond) for the serial port communication.
162 u_result checkMotorCtrlSupport(bool & support, _u32 timeout = DEFAULT_TIMEOUT);
163
164 ///Set LPX and S2E series lidar's static IP address
165 ///
166 /// \param conf Network parameter that LPX series lidar owned
167 /// \param timeout The operation timeout value (in millisecond) for the ethernet udp communication
168 u_result setLidarIpConf(const rplidar_ip_conf_t& conf, _u32 timeout = DEFAULT_TIMEOUT);
169
170 ///Get LPX and S2E series lidar's static IP address
171 ///
172 /// \param conf Network parameter that LPX series lidar owned
173 /// \param timeout The operation timeout value (in millisecond) for the ethernet udp communication
174 u_result getLidarIpConf(rplidar_ip_conf_t& conf, _u32 timeout = DEFAULT_TIMEOUT);
175
176 ///Get LPX and S2E series lidar's MAC address
177 ///
178 /// \param macAddrArray The device MAC information returned from the LPX series lidar
179 u_result getDeviceMacAddr(_u8* macAddrArray, _u32 timeoutInMs = DEFAULT_TIMEOUT);
180
181 /// Ask the RPLIDAR core system to stop the current scan operation and enter idle state. The background thread will be terminated
182 ///
183 /// \param timeout The operation timeout value (in millisecond) for the serial port communication
184 u_result stop(_u32 timeout = DEFAULT_TIMEOUT);
185
186 /// Wait and grab a complete 0-360 degree scan data previously received.
187 /// The grabbed scan data returned by this interface always has the following charactistics:
188 ///
189 /// 1) The first node of the grabbed data array (nodebuffer[0]) must be the first sample of a scan, i.e. the start_bit == 1
190 /// 2) All data nodes are belong to exactly ONE complete 360-degrees's scan
191 /// 3) Note, the angle data in one scan may not be ascending. You can use API ascendScanData to reorder the nodebuffer.
192 ///
193 /// \param nodebuffer Buffer provided by the caller application to store the scan data
194 ///
195 /// \param count The caller must initialize this parameter to set the max data count of the provided buffer (in unit of rplidar_response_measurement_node_t).
196 /// Once the interface returns, this parameter will store the actual received data count.
197 ///
198 /// \param timeout Max duration allowed to wait for a complete scan data, nothing will be stored to the nodebuffer if a complete 360-degrees' scan data cannot to be ready timely.
199 ///
200 /// The interface will return RESULT_OPERATION_TIMEOUT to indicate that no complete 360-degrees' scan can be retrieved withing the given timeout duration.
201 ///
202 /// \The caller application can set the timeout value to Zero(0) to make this interface always returns immediately to achieve non-block operation.
203 u_result grabScanDataHq(rplidar_response_measurement_node_hq_t * nodebuffer, size_t & count, _u32 timeout = DEFAULT_TIMEOUT);
204
205 /// Ascending the scan data according to the angle value in the scan.
206 ///
207 /// \param nodebuffer Buffer provided by the caller application to do the reorder. Should be retrived from the grabScanData
208 ///
209 /// \param count The caller must initialize this parameter to set the max data count of the provided buffer (in unit of rplidar_response_measurement_node_t).
210 /// Once the interface returns, this parameter will store the actual received data count.
211 /// The interface will return RESULT_OPERATION_FAIL when all the scan data is invalid.
212 u_result ascendScanData(rplidar_response_measurement_node_hq_t * nodebuffer, size_t count);
213
214 /// Return received scan points even if it's not complete scan
215 ///
216 /// \param nodebuffer Buffer provided by the caller application to store the scan data
217 ///
218 /// \param count Once the interface returns, this parameter will store the actual received data count.
219 ///
220 /// The interface will return RESULT_OPERATION_TIMEOUT to indicate that not even a single node can be retrieved since last call.
221 u_result getScanDataWithInterval(rplidar_response_measurement_node_t * nodebuffer, size_t & count);
222
223 /// Return received scan points even if it's not complete scan
224 ///
225 /// \param nodebuffer Buffer provided by the caller application to store the scan data
226 ///
227 /// \param count Once the interface returns, this parameter will store the actual received data count.
228 ///
229 /// The interface will return RESULT_OPERATION_TIMEOUT to indicate that not even a single node can be retrieved since last call.
230 u_result getScanDataWithIntervalHq(rplidar_response_measurement_node_hq_t * nodebuffer, size_t & count);
231
232
233 virtual ~RPlidarDriver();
234 protected:
235 RPlidarDriver();
236
237 private:
238 sl_u32 _channelType;
239 IChannel* _channel;
240 ILidarDriver* _lidarDrv;
241
242 };
243
244
245
246
247 }}}