|
|
|
@ -12,6 +12,18 @@
@@ -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,
@@ -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()
@@ -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; |
|
|
|
|
} |
|
|
|
|