rplidar_driver.h
Go to the documentation of this file.
00001 /*
00002  *  RPLIDAR SDK
00003  *
00004  *  Copyright (c) 2009 - 2014 RoboPeak Team
00005  *  http://www.robopeak.com
00006  *  Copyright (c) 2014 - 2019 Shanghai Slamtec Co., Ltd.
00007  *  http://www.slamtec.com
00008  *
00009  */
00010 /*
00011  * Redistribution and use in source and binary forms, with or without 
00012  * modification, are permitted provided that the following conditions are met:
00013  *
00014  * 1. Redistributions of source code must retain the above copyright notice, 
00015  *    this list of conditions and the following disclaimer.
00016  *
00017  * 2. Redistributions in binary form must reproduce the above copyright notice, 
00018  *    this list of conditions and the following disclaimer in the documentation 
00019  *    and/or other materials provided with the distribution.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00022  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
00023  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00024  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
00025  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00026  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00027  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00028  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00029  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00030  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
00031  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032  *
00033  */
00034 
00035 #pragma once
00036 
00037 
00038 #ifndef __cplusplus
00039 #error "The RPlidar SDK requires a C++ compiler to be built"
00040 #endif
00041 
00042 #ifndef DEPRECATED
00043     #ifdef __GNUC__
00044         #define DEPRECATED(func) func __attribute__ ((deprecated))
00045     #elif defined(_MSC_VER)
00046         #define DEPRECATED(func) __declspec(deprecated) func
00047     #else
00048         #pragma message("WARNING: You need to implement DEPRECATED for this compiler")
00049         #define DEPRECATED(func) func
00050     #endif
00051 #endif
00052 
00053 namespace rp { namespace standalone{ namespace rplidar {
00054 
00055 struct RplidarScanMode {
00056     _u16    id;
00057     float   us_per_sample;   // microseconds per sample
00058     float   max_distance;    // max distance
00059     _u8     ans_type;         // the answer type of the scam mode, its value should be RPLIDAR_ANS_TYPE_MEASUREMENT*
00060     char    scan_mode[64];    // name of scan mode, max 63 characters
00061 };
00062 
00063 enum {
00064     DRIVER_TYPE_SERIALPORT = 0x0,
00065     DRIVER_TYPE_TCP = 0x1,
00066 };
00067 
00068 class ChannelDevice
00069 {
00070 public:
00071     virtual bool bind(const char*, uint32_t ) = 0;
00072     virtual bool open() {return true;}
00073     virtual void close() = 0;
00074     virtual void flush() {return;}
00075     virtual bool waitfordata(size_t data_count,_u32 timeout = -1, size_t * returned_size = NULL) = 0;
00076     virtual int senddata(const _u8 * data, size_t size) = 0;
00077     virtual int recvdata(unsigned char * data, size_t size) = 0;
00078     virtual void setDTR() {return;}
00079     virtual void clearDTR() {return;}
00080     virtual void ReleaseRxTx() {return;}
00081 };
00082 
00083 class RPlidarDriver {
00084 public:
00085     enum {
00086         DEFAULT_TIMEOUT = 2000, //2000 ms
00087     };
00088 
00089     enum {
00090         MAX_SCAN_NODES = 8192,
00091     };
00092 
00093     enum {
00094         LEGACY_SAMPLE_DURATION = 476,
00095     };
00096 
00097 public:
00102     static RPlidarDriver * CreateDriver(_u32 drivertype = DRIVER_TYPE_SERIALPORT);
00103 
00106     static void DisposeDriver(RPlidarDriver * drv);
00107 
00108 
00120     virtual u_result connect(const char *, _u32, _u32 flag = 0) = 0;
00121 
00122 
00124     virtual void disconnect() = 0;
00125 
00127     virtual bool isConnected() = 0;
00128 
00133     virtual u_result reset(_u32 timeout = DEFAULT_TIMEOUT) = 0;
00134 
00135     virtual u_result clearNetSerialRxCache() = 0;
00136     // FW1.24
00138     virtual u_result getAllSupportedScanModes(std::vector<RplidarScanMode>& outModes, _u32 timeoutInMs = DEFAULT_TIMEOUT) = 0;
00139 
00141     virtual u_result getTypicalScanMode(_u16& outMode, _u32 timeoutInMs = DEFAULT_TIMEOUT) = 0;
00142 
00149     virtual u_result startScan(bool force, bool useTypicalScan, _u32 options = 0, RplidarScanMode* outUsedScanMode = NULL) = 0;
00150 
00157     virtual u_result startScanExpress(bool force, _u16 scanMode, _u32 options = 0, RplidarScanMode* outUsedScanMode = NULL, _u32 timeout = DEFAULT_TIMEOUT) = 0;
00158 
00165     virtual u_result getHealth(rplidar_response_device_health_t & health, _u32 timeout = DEFAULT_TIMEOUT) = 0;
00166 
00171     virtual u_result getDeviceInfo(rplidar_response_device_info_t & info, _u32 timeout = DEFAULT_TIMEOUT) = 0;
00172 
00178     DEPRECATED(virtual u_result getSampleDuration_uS(rplidar_response_sample_rate_t & rateInfo, _u32 timeout = DEFAULT_TIMEOUT)) = 0;
00179     
00183     virtual u_result setMotorPWM(_u16 pwm) = 0;
00184 
00186     virtual u_result startMotor() = 0;
00187 
00189     virtual u_result stopMotor() = 0;
00190 
00196     virtual u_result checkMotorCtrlSupport(bool & support, _u32 timeout = DEFAULT_TIMEOUT) = 0;
00197 
00208     DEPRECATED(virtual u_result getFrequency(bool inExpressMode, size_t count, float & frequency, bool & is4kmode)) = 0;
00209 
00216     virtual u_result getFrequency(const RplidarScanMode& scanMode, size_t count, float & frequency) = 0;
00217 
00224     virtual u_result startScanNormal(bool force, _u32 timeout = DEFAULT_TIMEOUT) = 0;
00225     
00231     DEPRECATED(virtual u_result checkExpressScanSupported(bool & support, _u32 timeout = DEFAULT_TIMEOUT)) = 0;
00232 
00236     virtual u_result stop(_u32 timeout = DEFAULT_TIMEOUT) = 0;
00237 
00238 
00257     DEPRECATED(virtual u_result grabScanData(rplidar_response_measurement_node_t * nodebuffer, size_t & count, _u32 timeout = DEFAULT_TIMEOUT)) = 0;
00258 
00276     virtual u_result grabScanDataHq(rplidar_response_measurement_node_hq_t * nodebuffer, size_t & count, _u32 timeout = DEFAULT_TIMEOUT) = 0;
00277 
00285     DEPRECATED(virtual u_result ascendScanData(rplidar_response_measurement_node_t * nodebuffer, size_t count)) = 0;
00286 
00294     virtual u_result ascendScanData(rplidar_response_measurement_node_hq_t * nodebuffer, size_t count) = 0;
00295 
00303     DEPRECATED(virtual u_result getScanDataWithInterval(rplidar_response_measurement_node_t * nodebuffer, size_t & count)) = 0;
00304 
00312     virtual u_result getScanDataWithIntervalHq(rplidar_response_measurement_node_hq_t * nodebuffer, size_t & count) = 0;
00313 
00314     virtual ~RPlidarDriver() {}
00315 protected:
00316     RPlidarDriver(){}
00317 
00318 public:
00319     ChannelDevice* _chanDev;
00320 };
00321 
00322 
00323 
00324 
00325 }}}


rplidar_ros
Author(s):
autogenerated on Mon Mar 18 2019 02:34:23