Line data Source code
1 : /* 2 : * This file is free software: you can redistribute it and/or modify it 3 : * under the terms of the GNU General Public License as published by the 4 : * Free Software Foundation, either version 3 of the License, or 5 : * (at your option) any later version. 6 : * 7 : * This file is distributed in the hope that it will be useful, but 8 : * WITHOUT ANY WARRANTY; without even the implied warranty of 9 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 : * See the GNU General Public License for more details. 11 : * 12 : * You should have received a copy of the GNU General Public License along 13 : * with this program. If not, see <http://www.gnu.org/licenses/>. 14 : * 15 : * Code by Charlie Johnson 16 : */ 17 : 18 : #pragma once 19 : 20 : #include "AP_BattMonitor_Backend.h" 21 : 22 : #if AP_BATTERY_FUELLEVEL_ANALOG_ENABLED 23 : 24 : #include <Filter/LowPassFilter.h> 25 : #include "AP_BattMonitor.h" 26 : #include <Filter/Filter.h> // Filter library 27 : 28 : class AP_BattMonitor_FuelLevel_Analog : public AP_BattMonitor_Backend 29 : { 30 : public: 31 : 32 : // Constructor 33 : AP_BattMonitor_FuelLevel_Analog(AP_BattMonitor &mon, AP_BattMonitor::BattMonitor_State &mon_state, AP_BattMonitor_Params ¶ms); 34 : 35 : static const struct AP_Param::GroupInfo var_info[]; 36 : 37 : // Read the battery voltage and current. Should be called at 10hz 38 : void read() override; 39 : 40 : // returns true if battery monitor provides consumed energy info 41 0 : bool has_consumed_energy() const override { return true; } 42 : 43 : // returns true if battery monitor provides current info (or capacity) 44 0 : bool has_current() const override { return true; } 45 : 46 0 : void init(void) override {} 47 : 48 : private: 49 : 50 : AP_Float _fuel_level_empty_voltage; 51 : AP_Float _fuel_level_voltage_mult; 52 : AP_Float _fuel_level_filter_frequency; 53 : AP_Int8 _pin; 54 : AP_Float _fuel_fit_first_order_coeff; 55 : AP_Float _fuel_fit_second_order_coeff; 56 : AP_Float _fuel_fit_third_order_coeff; 57 : AP_Float _fuel_fit_offset; 58 : AP_HAL::AnalogSource *_analog_source; 59 : 60 : LowPassFilterFloat _voltage_filter; 61 : 62 : }; 63 : 64 : #endif // AP_BATTERY_FUELLEVEL_ANALOG_ENABLED