Line data Source code
1 : #pragma once 2 : 3 : #include "AP_BattMonitor_Backend.h" 4 : 5 : #if AP_BATTERY_ANALOG_ENABLED 6 : 7 : #include "AP_BattMonitor.h" 8 : 9 : class AP_BattMonitor_Analog : public AP_BattMonitor_Backend 10 : { 11 : public: 12 : 13 : /// Constructor 14 : AP_BattMonitor_Analog(AP_BattMonitor &mon, AP_BattMonitor::BattMonitor_State &mon_state, AP_BattMonitor_Params ¶ms); 15 : 16 : /// Read the battery voltage and current. Should be called at 10hz 17 : virtual void read() override; 18 : 19 : /// returns true if battery monitor provides consumed energy info 20 864071 : virtual bool has_consumed_energy() const override { return has_current(); } 21 : 22 : /// returns true if battery monitor provides current info 23 : virtual bool has_current() const override; 24 : 25 1859 : virtual void init(void) override {} 26 : 27 : static const struct AP_Param::GroupInfo var_info[]; 28 : 29 : protected: 30 : 31 : AP_HAL::AnalogSource *_volt_pin_analog_source; 32 : AP_HAL::AnalogSource *_curr_pin_analog_source; 33 : 34 : // Parameters 35 : AP_Float _volt_multiplier; /// voltage on volt pin multiplied by this to calculate battery voltage 36 : AP_Float _curr_amp_per_volt; /// voltage on current pin multiplied by this to calculate current in amps 37 : AP_Float _curr_amp_offset; /// offset voltage that is subtracted from current pin before conversion to amps 38 : AP_Float _volt_offset; /// offset voltage that is subtracted from voltage pin before conversion 39 : AP_Int8 _volt_pin; /// board pin used to measure battery voltage 40 : AP_Int8 _curr_pin; /// board pin used to measure battery current 41 : }; 42 : 43 : #endif // AP_BATTERY_ANALOG_ENABLED