Line data Source code
1 : /* 2 : * Copyright (C) 2025 Shubham Jolapara <[email protected]> 3 : * 4 : * This file is free software: you can redistribute it and/or modify it 5 : * under the terms of the GNU General Public License as published by the 6 : * Free Software Foundation, either version 3 of the License, or 7 : * (at your option) any later version. 8 : * 9 : * This file is distributed in the hope that it will be useful, but 10 : * WITHOUT ANY WARRANTY; without even the implied warranty of 11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 : * See the GNU General Public License for more details. 13 : * 14 : * You should have received a copy of the GNU General Public License along 15 : * with this program. If not, see <http://www.gnu.org/licenses/>. 16 : * 17 : * 18 : * 19 : * Benewake TFS20L I2C Rangefinder Driver 20 : * 21 : * Range: 0.01m to 20m 22 : * Datasheet: https://altronics.cl/uploads/benewake/TFS20-L-User-Manual.pdf 23 : */ 24 : #pragma once 25 : 26 : #include "AP_RangeFinder_config.h" 27 : 28 : #if AP_RANGEFINDER_BENEWAKE_TFS20L_ENABLED 29 : 30 : #include "AP_RangeFinder.h" 31 : #include "AP_RangeFinder_Backend_I2C.h" 32 : #define TFS20L_ADDR_DEFAULT 0x10 // TFS20L default device id 33 : 34 : // Forward declaration 35 : namespace AP_HAL { 36 : class I2CDevice; 37 : } 38 : 39 : class AP_RangeFinder_Benewake_TFS20L : public AP_RangeFinder_Backend_I2C 40 : { 41 : 42 : public: 43 : // static detection function 44 1 : static AP_RangeFinder_Backend *detect(RangeFinder::RangeFinder_State &_state, 45 : AP_RangeFinder_Params &_params, 46 : AP_HAL::I2CDevice &dev) { 47 : // this will free the object if configuration fails: 48 1 : return configure(NEW_NOTHROW AP_RangeFinder_Benewake_TFS20L(_state, _params, dev)); 49 : } 50 : 51 : // update state 52 : void update(void) override; 53 : 54 : protected: 55 : 56 335 : virtual MAV_DISTANCE_SENSOR _get_mav_distance_sensor_type() const override { 57 335 : return MAV_DISTANCE_SENSOR_LASER; 58 : } 59 : 60 : private: 61 : using AP_RangeFinder_Backend_I2C::AP_RangeFinder_Backend_I2C; 62 : 63 : bool init() override; 64 : void timer(); 65 : 66 : struct { 67 : uint32_t sum; 68 : uint32_t count; 69 : uint32_t out_of_range_count; 70 : } accum; 71 : 72 : }; 73 : 74 : #endif