Line data Source code
1 : /* 2 : This program is free software: you can redistribute it and/or modify 3 : it under the terms of the GNU General Public License as published by 4 : the Free Software Foundation, either version 3 of the License, or 5 : (at your option) any later version. 6 : This program is distributed in the hope that it will be useful, 7 : but WITHOUT ANY WARRANTY; without even the implied warranty of 8 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 : GNU General Public License for more details. 10 : You should have received a copy of the GNU General Public License 11 : along with this program. If not, see <http://www.gnu.org/licenses/>. 12 : */ 13 : 14 : /* 15 : * ArduPilot device driver for Inno-Maker LD06 LiDAR 16 : * 17 : * ALL INFORMATION REGARDING PROTOCOL WAS DERIVED FROM LD06 DATASHEET: 18 : * 19 : * http://wiki.inno-maker.com/display/HOMEPAGE/LD06?preview=/6949506/6949511/LDROBOT_LD06_Development%20manual_v1.0_en.pdf 20 : * 21 : * Author: Adithya Patil, Georgia Institute of Technology 22 : * Based on the SLAMTEC RPLiDAR code written by Steven Josefs, IAV GmbH 23 : * 24 : */ 25 : 26 : #pragma once 27 : #include "AP_Proximity_config.h" 28 : 29 : #if AP_PROXIMITY_LD06_ENABLED 30 : 31 : #include "AP_Proximity_Backend_Serial.h" 32 : #include <Filter/ModeFilter.h> 33 : 34 : #define MESSAGE_LENGTH_LD06 47 35 : 36 : // Minimum and maximum distance that the sensor can read in meters 37 : #define MAX_READ_DISTANCE_LD06 12.0f 38 : #define MIN_READ_DISTANCE_LD06 0.02f 39 : 40 : class AP_Proximity_LD06 : public AP_Proximity_Backend_Serial 41 : { 42 : public: 43 : 44 : using AP_Proximity_Backend_Serial::AP_Proximity_Backend_Serial; 45 : 46 : // Update the state of the sensor 47 : void update(void) override; 48 : 49 : // Get the max and min distances for the sensor being used 50 34651 : float distance_max_m() const override { return MAX_READ_DISTANCE_LD06; } 51 250755 : float distance_min_m() const override { return MIN_READ_DISTANCE_LD06; } 52 : 53 : private: 54 : 55 : // Get and parse the sensor data 56 : void parse_response_data(); 57 : void get_readings(); 58 : 59 : // Store and keep track of the bytes being read from the sensor 60 : uint8_t _response[MESSAGE_LENGTH_LD06]; 61 : uint16_t _byte_count; 62 : 63 : // Store for error-tracking purposes 64 : uint32_t _last_distance_received_ms; 65 : 66 : // distance filter applies to raw measurements 67 : ModeFilterUInt16_Size3 _dist_filt_mm {1}; 68 : 69 : // face related variables 70 : AP_Proximity_Boundary_3D::Face _last_face;///< last face requested 71 : float _last_angle_deg; ///< yaw angle (in degrees) of _last_distance_m 72 : float _last_distance_m; ///< shortest distance for _last_face 73 : bool _last_distance_valid; ///< true if _last_distance_m is valid 74 : 75 : // angle and distance for the latest 2 degree sector 76 : uint16_t _angle_2deg; 77 : float _dist_2deg_m; 78 : }; 79 : #endif // AP_PROXIMITY_LD06_ENABLED