Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
rplidar.h
00001 /* 00002 * RPLIDAR SDK for Mbed 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 #include "mbed.h" 00037 #include "rplidar.h" 00038 #include "inc/rptypes.h" 00039 #include "inc/rplidar_cmd.h" 00040 #include "rplidar_driver.h" 00041 #include <vector> 00042 00043 struct RPLidarMeasurement 00044 { 00045 float distance; 00046 float angle; 00047 uint8_t quality; 00048 bool startBit; 00049 }; 00050 00051 class RPLidar 00052 { 00053 public: 00054 enum { 00055 RPLIDAR_SERIAL_BAUDRATE = 115200, 00056 DEFAULT_TIMEOUT = 500, 00057 }; 00058 00059 RPLidar(); 00060 ~RPLidar(); 00061 00062 // open the given serial interface and try to connect to the RPLIDAR 00063 //bool begin(BufferedSerial &serialobj); 00064 void begin(RawSerial& serialobj); 00065 // close the currently opened serial interface 00066 void end(); 00067 00068 // check whether the serial interface is opened 00069 // bool isOpen(); 00070 virtual u_result checkSupportConfigCommands(bool& outSupport, uint32_t timeoutInMs = DEFAULT_TIMEOUT); 00071 virtual u_result getLidarSampleDuration(float& sampleDurationRes, uint16_t scanModeID, uint32_t timeoutInMs = DEFAULT_TIMEOUT); 00072 virtual u_result getMaxDistance(float &maxDistance, uint16_t scanModeID, uint32_t timeoutInMs = DEFAULT_TIMEOUT); 00073 virtual u_result getScanModeAnsType(uint8_t &ansType, uint16_t scanModeID, uint32_t timeoutInMs = DEFAULT_TIMEOUT); 00074 virtual u_result getScanModeName(char* modeName, uint16_t scanModeID, uint32_t timeoutInMs = DEFAULT_TIMEOUT); 00075 virtual u_result getSampleDuration_uS(rplidar_response_sample_rate_t & rateInfo, uint32_t timeout = DEFAULT_TIMEOUT); 00076 virtual u_result getLidarConf(uint32_t type, std::vector<uint8_t> &outputBuf, const std::vector<uint8_t> &reserve = std::vector<uint8_t>(), uint32_t timeout = DEFAULT_TIMEOUT); 00077 virtual u_result getAllSupportedScanModes(std::vector<RplidarScanMode>& outModes, uint32_t timeoutInMs = DEFAULT_TIMEOUT); 00078 virtual u_result getScanModeCount(uint16_t& modeCount, uint32_t timeoutInMs = DEFAULT_TIMEOUT); 00079 virtual u_result checkExpressScanSupported(bool & support, uint32_t timeout = DEFAULT_TIMEOUT); 00080 // ask the RPLIDAR for its health info 00081 u_result getHealth(rplidar_response_device_health_t& healthinfo, uint32_t timeout = DEFAULT_TIMEOUT); 00082 00083 // ask the RPLIDAR for its device info like the serial number 00084 u_result getDeviceInfo(rplidar_response_device_info_t& info, uint32_t timeout = DEFAULT_TIMEOUT); 00085 00086 // stop the measurement operation 00087 u_result stop(); 00088 00089 // start the measurement operation 00090 u_result startScanNormal(bool force = true, uint32_t timeout = DEFAULT_TIMEOUT * 2); 00091 u_result startScanExpress(bool force, uint16_t scanMode, uint32_t options = 0, RplidarScanMode* outUsedScanMode = NULL, uint32_t timeout = DEFAULT_TIMEOUT); 00092 /// Start scan in specific mode 00093 /// 00094 /// \param force Force the core system to output scan data regardless whether the scanning motor is rotating or not. 00095 /// \param scanMode The scan mode id (use getAllSupportedScanModes to get supported modes) 00096 /// \param options Scan options (please use 0) 00097 /// \param outUsedScanMode The scan mode selected by lidar 00098 // u_result startScanExpress(bool force, uint16_t scanMode, uint32_t options = 0, uint32_t timeout = DEFAULT_TIMEOUT) = 0;//RplidarScanMode* outUsedScanMode = NULL, 00099 00100 // wait for one sample point to arrive 00101 u_result waitPoint(uint32_t timeout = DEFAULT_TIMEOUT); 00102 u_result _sendCommand(uint8_t cmd, const void* payload, size_t payloadsize); 00103 // retrieve currently received sample point 00104 //float Data[360]; 00105 RPLidarMeasurement Data[360]; 00106 int ang; 00107 int angMin, angMax; 00108 void setAngle(int min, int max); 00109 void setLidar(); 00110 const RPLidarMeasurement& getCurrentPoint() 00111 { 00112 return _currentMeasurement; 00113 } 00114 00115 protected: 00116 // u_result _sendCommand(uint8_t cmd, const void * payload, size_t payloadsize); 00117 u_result _waitResponseHeader(rplidar_ans_header_t* header, uint32_t timeout); 00118 bool _isConnected; 00119 bool _isScanning; 00120 bool _isSupportingMotorCtrl; 00121 void _disableDataGrabbing(); 00122 00123 00124 uint16_t _cached_sampleduration_std; 00125 uint16_t _cached_sampleduration_express; 00126 uint8_t _cached_express_flag; 00127 00128 00129 protected: 00130 RawSerial* _binded_serialdev; 00131 RPLidarMeasurement _currentMeasurement; 00132 00133 // <THREAD> 00134 /*private: 00135 //RPLidar* _lidar; 00136 static int count; 00137 public: 00138 void getDataThread(void){ 00139 while(1){ 00140 this->Data[] getData() 00141 } 00142 } 00143 */ 00144 // </THREAD> 00145 00146 }; 00147
Generated on Wed Jul 27 2022 05:22:14 by
1.7.2