APM:Libraries
AP_BattMonitor_Backend.h
Go to the documentation of this file.
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 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program. If not, see <http://www.gnu.org/licenses/>.
14  */
15 #pragma once
16 
17 #include <AP_Common/AP_Common.h>
18 #include <AP_HAL/AP_HAL.h>
19 #include "AP_BattMonitor.h"
20 
22 {
23 public:
24  // constructor. This incorporates initialisation as well.
26 
27  // we declare a virtual destructor so that BattMonitor driver can
28  // override with a custom destructor if need be
29  virtual ~AP_BattMonitor_Backend(void) {}
30 
31  // initialise
32  virtual void init() = 0;
33 
34  // read the latest battery voltage
35  virtual void read() = 0;
36 
38  virtual bool has_consumed_energy() const { return false; }
39 
41  virtual bool has_current() const = 0;
42 
43  // returns true if battery monitor provides individual cell voltages
44  virtual bool has_cell_voltages() const { return false; }
45 
47  uint8_t capacity_remaining_pct() const;
48 
49  // update battery resistance estimate and voltage_resting_estimate
51 
52  // callback for UAVCAN messages
53  virtual void handle_bi_msg(float voltage, float current,
54  float temperature) {}
55 
56 protected:
57  AP_BattMonitor &_mon; // reference to front-end
58  AP_BattMonitor::BattMonitor_State &_state; // reference to this instances state (held in the front-end)
59  AP_BattMonitor_Params &_params; // reference to this instances parameters (held in the front-end)
60 
61 private:
62  // resistance estimate
63  uint32_t _resistance_timer_ms; // system time of last resistance estimate update
64  float _voltage_filt; // filtered voltage
65  float _current_max_amps; // maximum current since start-up
66  float _current_filt_amps; // filtered current
67  float _resistance_voltage_ref; // voltage used for maximum resistance calculation
68  float _resistance_current_ref; // current used for maximum resistance calculation
69 };
AP_BattMonitor_Backend(AP_BattMonitor &mon, AP_BattMonitor::BattMonitor_State &mon_state, AP_BattMonitor_Params &params)
AP_BattMonitor_Params & _params
float temperature
Definition: Airspeed.cpp:32
virtual bool has_current() const =0
returns true if battery monitor instance provides current info
uint8_t capacity_remaining_pct() const
capacity_remaining_pct - returns the % battery capacity remaining (0 ~ 100)
Common definitions and utility routines for the ArduPilot libraries.
virtual void handle_bi_msg(float voltage, float current, float temperature)
virtual bool has_consumed_energy() const
returns true if battery monitor instance provides consumed energy info
AP_BattMonitor::BattMonitor_State & _state
float voltage
virtual void init()=0
virtual void read()=0
virtual bool has_cell_voltages() const