00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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
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 }}}