AP_BatteryMoniter: add mask param to sum battery backend.
This commit is contained in:
parent
d97baac926
commit
7d4f305f20
@ -322,7 +322,7 @@ AP_BattMonitor::init()
|
||||
if (drivers[instance] && state[instance].var_info) {
|
||||
Type type = get_type(instance);
|
||||
if((type == Type::ANALOG_VOLTAGE_AND_CURRENT) || (type == Type::ANALOG_VOLTAGE_ONLY) ||
|
||||
(type == Type::FuelFlow) || (type == Type::FuelLevel_PWM)) {
|
||||
(type == Type::FuelFlow) || (type == Type::FuelLevel_PWM) || (type == Type::Sum)) {
|
||||
backend_analog_var_info[instance] = state[instance].var_info;
|
||||
AP_Param::load_object_from_eeprom(drivers[instance], backend_analog_var_info[instance]);
|
||||
}
|
||||
|
@ -12,6 +12,18 @@
|
||||
*/
|
||||
extern const AP_HAL::HAL& hal;
|
||||
|
||||
const AP_Param::GroupInfo AP_BattMonitor_Sum::var_info[] = {
|
||||
|
||||
// @Param: SUM_MASK
|
||||
// @DisplayName: Battery Sum mask
|
||||
// @Description: 0: sum of remaining battery monitors, If none 0 sum of specified monitors. Current will be summed and voltages averaged.
|
||||
// @Bitmask: 0:monitor 1, 1:monitor 2, 2:monitor 3, 3:monitor 4, 4:monitor 5, 5:monitor 6, 6:monitor 7, 7:monitor 8, 8:monitor 9
|
||||
// @User: Standard
|
||||
AP_GROUPINFO("SUM_MASK", 1, AP_BattMonitor_Sum, _sum_mask, 0),
|
||||
|
||||
AP_GROUPEND
|
||||
};
|
||||
|
||||
/// Constructor
|
||||
AP_BattMonitor_Sum::AP_BattMonitor_Sum(AP_BattMonitor &mon,
|
||||
AP_BattMonitor::BattMonitor_State &mon_state,
|
||||
@ -20,6 +32,8 @@ AP_BattMonitor_Sum::AP_BattMonitor_Sum(AP_BattMonitor &mon,
|
||||
AP_BattMonitor_Backend(mon, mon_state, params),
|
||||
_instance(instance)
|
||||
{
|
||||
AP_Param::setup_object_defaults(this, var_info);
|
||||
_state.var_info = var_info;
|
||||
}
|
||||
|
||||
// read - read the voltage and current
|
||||
@ -31,7 +45,19 @@ AP_BattMonitor_Sum::read()
|
||||
float current_sum = 0;
|
||||
uint8_t current_count = 0;
|
||||
|
||||
for (uint8_t i=_instance+1; i<_mon.num_instances(); i++) {
|
||||
for (uint8_t i=0; i<_mon.num_instances(); i++) {
|
||||
if (i == _instance) {
|
||||
// never include self
|
||||
continue;
|
||||
}
|
||||
if ((_sum_mask == 0) && (i <= _instance)) {
|
||||
// sum of remaining, skip lower instances
|
||||
continue;
|
||||
}
|
||||
if ((_sum_mask != 0) && ((_sum_mask & 1U<<i) == 0)) {
|
||||
// mask param, skip if mask bit not set
|
||||
continue;
|
||||
}
|
||||
if (!_mon.healthy(i)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -21,7 +21,11 @@ public:
|
||||
|
||||
void init(void) override {}
|
||||
|
||||
static const struct AP_Param::GroupInfo var_info[];
|
||||
|
||||
private:
|
||||
|
||||
AP_Int16 _sum_mask;
|
||||
uint8_t _instance;
|
||||
bool _has_current;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user