Main MRPT website > C++ reference for MRPT 1.5.7
rplidar_driver.h
Go to the documentation of this file.
1 /*
2  * RPLIDAR SDK
3  *
4  * Copyright (c) 2009 - 2014 RoboPeak Team
5  * http://www.robopeak.com
6  * Copyright (c) 2014 - 2016 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 
37 
38 #ifndef __cplusplus
39 #error "The RPlidar SDK requires a C++ compiler to be built"
40 #endif
41 
42 namespace rp { namespace standalone{ namespace rplidar {
43 
45 public:
46  enum {
47  DEFAULT_TIMEOUT = 2000, //2000 ms
48  };
49 
50  enum {
52  };
53 public:
54  /// Create an RPLIDAR Driver Instance
55  /// This interface should be invoked first before any other operations
56  ///
57  /// \param drivertype the connection type used by the driver.
59 
60  /// Dispose the RPLIDAR Driver Instance specified by the drv parameter
61  /// Applications should invoke this interface when the driver instance is no longer used in order to free memory
62  static void DisposeDriver(RPlidarDriver * drv);
63 
64 
65 public:
66  /// Open the specified serial port and connect to a target RPLIDAR device
67  ///
68  /// \param port_path the device path of the serial port
69  /// e.g. on Windows, it may be com3 or \\.\com10
70  /// on Unix-Like OS, it may be /dev/ttyS1, /dev/ttyUSB2, etc
71  ///
72  /// \param baudrate the baudrate used
73  /// For most RPLIDAR models, the baudrate should be set to 115200
74  ///
75  /// \param flag other flags
76  /// Reserved for future use, always set to Zero
77  virtual u_result connect(const char * port_path, _u32 baudrate, _u32 flag = 0) = 0;
78 
79 
80  /// Disconnect with the RPLIDAR and close the serial port
81  virtual void disconnect() = 0;
82 
83  /// Returns TRUE when the connection has been established
84  virtual bool isConnected() = 0;
85 
86  /// Ask the RPLIDAR core system to reset it self
87  /// The host system can use the Reset operation to help RPLIDAR escape the self-protection mode.
88  ///
89  // \param timeout The operation timeout value (in millisecond) for the serial port communication
90  virtual u_result reset(_u32 timeout = DEFAULT_TIMEOUT) = 0;
91 
92  /// Retrieve the health status of the RPLIDAR
93  /// The host system can use this operation to check whether RPLIDAR is in the self-protection mode.
94  ///
95  /// \param health The health status info returned from the RPLIDAR
96  ///
97  /// \param timeout The operation timeout value (in millisecond) for the serial port communication
98  virtual u_result getHealth(rplidar_response_device_health_t & health, _u32 timeout = DEFAULT_TIMEOUT) = 0;
99 
100  /// Get the device information of the RPLIDAR include the serial number, firmware version, device model etc.
101  ///
102  /// \param info The device information returned from the RPLIDAR
103  ///
104  /// \param timeout The operation timeout value (in millisecond) for the serial port communication
105  virtual u_result getDeviceInfo(rplidar_response_device_info_t & info, _u32 timeout = DEFAULT_TIMEOUT) = 0;
106 
107  /// Get the sample duration information of the RPLIDAR.
108  ///
109  /// \param rateInfo The sample duration information returned from the RPLIDAR
110  ///
111  /// \param timeout The operation timeout value (in millisecond) for the serial port communication
112  virtual u_result getSampleDuration_uS(rplidar_response_sample_rate_t & rateInfo, _u32 timeout = DEFAULT_TIMEOUT) = 0;
113 
114  /// Set the RPLIDAR's motor pwm when using accessory board, currently valid for A2 only.
115  ///
116  /// \param pwm The motor pwm value would like to set
117  virtual u_result setMotorPWM(_u16 pwm) = 0;
118 
119  /// Start RPLIDAR's motor when using accessory board
120  virtual u_result startMotor() = 0;
121 
122  /// Stop RPLIDAR's motor when using accessory board
123  virtual u_result stopMotor() = 0;
124 
125  /// Check whether the device support motor control.
126  /// Note: this API will disable grab.
127  ///
128  /// \param support Return the result.
129  ///
130  /// \param timeout The operation timeout value (in millisecond) for the serial port communication.
131  virtual u_result checkMotorCtrlSupport(bool & support, _u32 timeout = DEFAULT_TIMEOUT) = 0;
132 
133  /// Calcuate RPLIDAR's current scanning frequency from the given scan data
134  /// Please refer to the application note doc for details
135  /// Remark: the calcuation will be incorrect if the specified scan data doesn't contains enough data
136  ///
137  /// \param inExpressMode Indicate whether the RPLIDAR is in express mode
138  ///
139  /// \param count The number of sample nodes inside the given buffer
140  ///
141  /// \param frequency The scanning frequency (in HZ) calcuated by the interface.
142  ///
143  /// \param is4kmode Return whether the RPLIDAR is working on 4k sample rate mode.
144  virtual u_result getFrequency(bool inExpressMode, size_t count, float & frequency, bool & is4kmode) = 0;
145 
146  /// Ask the RPLIDAR core system to enter the scan mode(Normal/Express, Express mode is 4k mode)
147  /// A background thread will be created by the RPLIDAR driver to fetch the scan data continuously.
148  /// User Application can use the grabScanData() interface to retrieved the scan data cached previous by this background thread.
149  ///
150  /// \param force Force the core system to output scan data regardless whether the scanning motor is rotating or not.
151  ///
152  /// \param autoExpressMode Force the core system to trying express mode first, if the system does not support express mode, it will use normal mode.
153  ///
154  /// \param timeout The operation timeout value (in millisecond) for the serial port communication.
155  virtual u_result startScan(bool force = false, bool autoExpressMode = true) = 0;
156  virtual u_result startScanNormal(bool force, _u32 timeout = DEFAULT_TIMEOUT) = 0;
157  virtual u_result startScanExpress(bool fixedAngle, _u32 timeout = DEFAULT_TIMEOUT) = 0;
158 
159  /// Check whether the device support express mode.
160  ///
161  /// \param support Return the result.
162  ///
163  /// \param timeout The operation timeout value (in millisecond) for the serial port communication.
164  virtual u_result checkExpressScanSupported(bool & support, _u32 timeout = DEFAULT_TIMEOUT) = 0;
165 
166  /// Ask the RPLIDAR core system to stop the current scan operation and enter idle state. The background thread will be terminated
167  ///
168  /// \param timeout The operation timeout value (in millisecond) for the serial port communication
169  virtual u_result stop(_u32 timeout = DEFAULT_TIMEOUT) = 0;
170 
171 
172  /// Wait and grab a complete 0-360 degree scan data previously received.
173  /// The grabbed scan data returned by this interface always has the following charactistics:
174  ///
175  /// 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
176  /// 2) All data nodes are belong to exactly ONE complete 360-degrees's scan
177  /// 3) Note, the angle data in one scan may not be ascending. You can use API ascendScanData to reorder the nodebuffer.
178  ///
179  /// \param nodebuffer Buffer provided by the caller application to store the scan data
180  ///
181  /// \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).
182  /// Once the interface returns, this parameter will store the actual received data count.
183  ///
184  /// \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.
185  ///
186  /// The interface will return RESULT_OPERATION_TIMEOUT to indicate that no complete 360-degrees' scan can be retrieved withing the given timeout duration.
187  ///
188  /// \The caller application can set the timeout value to Zero(0) to make this interface always returns immediately to achieve non-block operation.
189  virtual u_result grabScanData(rplidar_response_measurement_node_t * nodebuffer, size_t & count, _u32 timeout = DEFAULT_TIMEOUT) = 0;
190 
191  /// Ascending the scan data according to the angle value in the scan.
192  ///
193  /// \param nodebuffer Buffer provided by the caller application to do the reorder. Should be retrived from the grabScanData
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  /// The interface will return RESULT_OPERATION_FAIL when all the scan data is invalid.
198  virtual u_result ascendScanData(rplidar_response_measurement_node_t * nodebuffer, size_t count) = 0;
199 
200 protected:
202  virtual ~RPlidarDriver() {}
203 };
204 
205 
206 }}}
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:3512
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.
backing_store_ptr info
Definition: jmemsys.h:170
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:100



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019