rplidar_driver_impl.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 namespace rp { namespace standalone{ namespace rplidar {
00038     class RPlidarDriverImplCommon : public RPlidarDriver
00039 {
00040 public:
00041 
00042     virtual bool isConnected();     
00043     virtual u_result reset(_u32 timeout = DEFAULT_TIMEOUT);
00044     virtual u_result clearNetSerialRxCache();
00045     virtual u_result getAllSupportedScanModes(std::vector<RplidarScanMode>& outModes, _u32 timeoutInMs = DEFAULT_TIMEOUT);
00046     virtual u_result getTypicalScanMode(_u16& outMode, _u32 timeoutInMs = DEFAULT_TIMEOUT);
00047     virtual u_result checkSupportConfigCommands(bool& outSupport, _u32 timeoutInMs = DEFAULT_TIMEOUT);
00048 
00049     virtual u_result getScanModeCount(_u16& modeCount, _u32 timeoutInMs = DEFAULT_TIMEOUT);
00050     virtual u_result getLidarSampleDuration(float& sampleDurationRes, _u16 scanModeID, _u32 timeoutInMs = DEFAULT_TIMEOUT);
00051     virtual u_result getMaxDistance(float &maxDistance, _u16 scanModeID, _u32 timeoutInMs = DEFAULT_TIMEOUT);
00052     virtual u_result getScanModeAnsType(_u8 &ansType, _u16 scanModeID, _u32 timeoutInMs = DEFAULT_TIMEOUT);
00053     virtual u_result getScanModeName(char* modeName, _u16 scanModeID, _u32 timeoutInMs = DEFAULT_TIMEOUT);
00054     virtual u_result getLidarConf(_u32 type, std::vector<_u8> &outputBuf, const std::vector<_u8> &reserve = std::vector<_u8>(), _u32 timeout = DEFAULT_TIMEOUT);
00055 
00056     virtual u_result startScan(bool force, bool useTypicalScan, _u32 options = 0, RplidarScanMode* outUsedScanMode = NULL);
00057     virtual u_result startScanExpress(bool force, _u16 scanMode, _u32 options = 0, RplidarScanMode* outUsedScanMode = NULL, _u32 timeout = DEFAULT_TIMEOUT);
00058 
00059 
00060     virtual u_result getHealth(rplidar_response_device_health_t & health, _u32 timeout = DEFAULT_TIMEOUT);
00061     virtual u_result getDeviceInfo(rplidar_response_device_info_t & info, _u32 timeout = DEFAULT_TIMEOUT);
00062     virtual u_result getSampleDuration_uS(rplidar_response_sample_rate_t & rateInfo, _u32 timeout = DEFAULT_TIMEOUT);
00063     virtual u_result setMotorPWM(_u16 pwm);
00064     virtual u_result startMotor();
00065     virtual u_result stopMotor();
00066     virtual u_result checkMotorCtrlSupport(bool & support, _u32 timeout = DEFAULT_TIMEOUT);
00067     virtual u_result getFrequency(bool inExpressMode, size_t count, float & frequency, bool & is4kmode);
00068     virtual u_result getFrequency(const RplidarScanMode& scanMode, size_t count, float & frequency);
00069     virtual u_result startScanNormal(bool force, _u32 timeout = DEFAULT_TIMEOUT);
00070     virtual u_result checkExpressScanSupported(bool & support, _u32 timeout = DEFAULT_TIMEOUT);
00071     virtual u_result stop(_u32 timeout = DEFAULT_TIMEOUT);
00072     virtual u_result grabScanData(rplidar_response_measurement_node_t * nodebuffer, size_t & count, _u32 timeout = DEFAULT_TIMEOUT);
00073     virtual u_result grabScanDataHq(rplidar_response_measurement_node_hq_t * nodebuffer, size_t & count, _u32 timeout = DEFAULT_TIMEOUT);
00074     virtual u_result ascendScanData(rplidar_response_measurement_node_t * nodebuffer, size_t count);
00075     virtual u_result ascendScanData(rplidar_response_measurement_node_hq_t * nodebuffer, size_t count);
00076     virtual u_result getScanDataWithInterval(rplidar_response_measurement_node_t * nodebuffer, size_t & count);
00077     virtual u_result getScanDataWithIntervalHq(rplidar_response_measurement_node_hq_t * nodebuffer, size_t & count);
00078 
00079 protected:
00080 
00081     virtual u_result _sendCommand(_u8 cmd, const void * payload = NULL, size_t payloadsize = 0);
00082     void     _disableDataGrabbing();
00083 
00084     virtual u_result _waitResponseHeader(rplidar_ans_header_t * header, _u32 timeout = DEFAULT_TIMEOUT);
00085     virtual u_result _cacheScanData();
00086     virtual u_result _waitScanData(rplidar_response_measurement_node_t * nodebuffer, size_t & count, _u32 timeout = DEFAULT_TIMEOUT);
00087     virtual u_result _waitNode(rplidar_response_measurement_node_t * node, _u32 timeout = DEFAULT_TIMEOUT);
00088     virtual u_result  _cacheCapsuledScanData();
00089     virtual u_result _waitCapsuledNode(rplidar_response_capsule_measurement_nodes_t & node, _u32 timeout = DEFAULT_TIMEOUT);
00090     virtual void     _capsuleToNormal(const rplidar_response_capsule_measurement_nodes_t & capsule, rplidar_response_measurement_node_hq_t *nodebuffer, size_t &nodeCount);
00091     virtual void     _dense_capsuleToNormal(const rplidar_response_capsule_measurement_nodes_t & capsule, rplidar_response_measurement_node_hq_t *nodebuffer, size_t &nodeCount);
00092     
00093     //FW1.23
00094     virtual u_result  _cacheUltraCapsuledScanData();
00095     virtual u_result _waitUltraCapsuledNode(rplidar_response_ultra_capsule_measurement_nodes_t & node, _u32 timeout = DEFAULT_TIMEOUT);
00096     virtual void     _ultraCapsuleToNormal(const rplidar_response_ultra_capsule_measurement_nodes_t & capsule, rplidar_response_measurement_node_hq_t *nodebuffer, size_t &nodeCount);
00097 
00098     virtual u_result  _cacheHqScanData();
00099     virtual u_result _waitHqNode(rplidar_response_hq_capsule_measurement_nodes_t & node, _u32 timeout = DEFAULT_TIMEOUT);
00100     virtual void     _HqToNormal(const rplidar_response_hq_capsule_measurement_nodes_t & node_hq, rplidar_response_measurement_node_hq_t *nodebuffer, size_t &nodeCount);
00101 
00102     bool     _isConnected; 
00103     bool     _isScanning;
00104     bool     _isSupportingMotorCtrl;
00105 
00106     rplidar_response_measurement_node_hq_t   _cached_scan_node_hq_buf[8192];
00107     size_t                                   _cached_scan_node_hq_count;
00108 
00109     rplidar_response_measurement_node_hq_t   _cached_scan_node_hq_buf_for_interval_retrieve[8192];
00110     size_t                                   _cached_scan_node_hq_count_for_interval_retrieve;
00111 
00112     _u16                    _cached_sampleduration_std;
00113     _u16                    _cached_sampleduration_express;
00114     _u8                     _cached_express_flag;
00115 
00116     rplidar_response_capsule_measurement_nodes_t _cached_previous_capsuledata;
00117     rplidar_response_dense_capsule_measurement_nodes_t _cached_previous_dense_capsuledata;
00118     rplidar_response_ultra_capsule_measurement_nodes_t _cached_previous_ultracapsuledata;
00119     rplidar_response_hq_capsule_measurement_nodes_t _cached_previous_Hqdata;
00120     bool                                         _is_previous_capsuledataRdy;
00121     bool                                         _is_previous_HqdataRdy;
00122 
00123         
00124 
00125     rp::hal::Locker         _lock;
00126     rp::hal::Event          _dataEvt;
00127     rp::hal::Thread _cachethread;
00128 
00129 protected:
00130     RPlidarDriverImplCommon();
00131     virtual ~RPlidarDriverImplCommon() {}
00132 };
00133 }}}


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