mirror of https://github.com/ArduPilot/ardupilot
AP_BattMonitor: add option minimum volt option
This commit is contained in:
parent
52169f25da
commit
11014cae06
|
@ -154,7 +154,7 @@ const AP_Param::GroupInfo AP_BattMonitor_Params::var_info[] = {
|
||||||
// @Param: OPTIONS
|
// @Param: OPTIONS
|
||||||
// @DisplayName: Battery monitor options
|
// @DisplayName: Battery monitor options
|
||||||
// @Description: This sets options to change the behaviour of the battery monitor
|
// @Description: This sets options to change the behaviour of the battery monitor
|
||||||
// @Bitmask: 0:Ignore DroneCAN SoC, 1:MPPT reports input voltage and current, 2:MPPT Powered off when disarmed, 3:MPPT Powered on when armed, 4:MPPT Powered off at boot, 5:MPPT Powered on at boot, 6:Send resistance compensated voltage to GCS, 7:Allow DroneCAN InfoAux to be from a different CAN node
|
// @Bitmask: 0:Ignore DroneCAN SoC, 1:MPPT reports input voltage and current, 2:MPPT Powered off when disarmed, 3:MPPT Powered on when armed, 4:MPPT Powered off at boot, 5:MPPT Powered on at boot, 6:Send resistance compensated voltage to GCS, 7:Allow DroneCAN InfoAux to be from a different CAN node, 9:Sum monitor measures minimum voltage instead of average
|
||||||
// @User: Advanced
|
// @User: Advanced
|
||||||
AP_GROUPINFO("OPTIONS", 21, AP_BattMonitor_Params, _options, 0),
|
AP_GROUPINFO("OPTIONS", 21, AP_BattMonitor_Params, _options, 0),
|
||||||
#endif // HAL_BUILD_AP_PERIPH
|
#endif // HAL_BUILD_AP_PERIPH
|
||||||
|
|
|
@ -27,6 +27,7 @@ public:
|
||||||
GCS_Resting_Voltage = (1U<<6), // send resistance resting voltage to GCS
|
GCS_Resting_Voltage = (1U<<6), // send resistance resting voltage to GCS
|
||||||
AllowSplitAuxInfo = (1U<<7), // allow different node to provide aux info for DroneCAN
|
AllowSplitAuxInfo = (1U<<7), // allow different node to provide aux info for DroneCAN
|
||||||
InternalUseOnly = (1U<<8), // for use internally to ArduPilot, not to be (eg.) sent via MAVLink BATTERY_STATUS
|
InternalUseOnly = (1U<<8), // for use internally to ArduPilot, not to be (eg.) sent via MAVLink BATTERY_STATUS
|
||||||
|
Minimum_Voltage = (1U<<9), // sum monitor measures minimum voltage rather than average
|
||||||
};
|
};
|
||||||
|
|
||||||
BattMonitor_LowVoltage_Source failsafe_voltage_source(void) const { return (enum BattMonitor_LowVoltage_Source)_failsafe_voltage_source.get(); }
|
BattMonitor_LowVoltage_Source failsafe_voltage_source(void) const { return (enum BattMonitor_LowVoltage_Source)_failsafe_voltage_source.get(); }
|
||||||
|
|
|
@ -50,6 +50,7 @@ void
|
||||||
AP_BattMonitor_Sum::read()
|
AP_BattMonitor_Sum::read()
|
||||||
{
|
{
|
||||||
float voltage_sum = 0;
|
float voltage_sum = 0;
|
||||||
|
float voltage_min = 0;
|
||||||
uint8_t voltage_count = 0;
|
uint8_t voltage_count = 0;
|
||||||
float current_sum = 0;
|
float current_sum = 0;
|
||||||
uint8_t current_count = 0;
|
uint8_t current_count = 0;
|
||||||
|
@ -57,6 +58,9 @@ AP_BattMonitor_Sum::read()
|
||||||
float temperature_sum = 0.0;
|
float temperature_sum = 0.0;
|
||||||
uint8_t temperature_count = 0;
|
uint8_t temperature_count = 0;
|
||||||
|
|
||||||
|
float consumed_mah_sum = 0;
|
||||||
|
float consumed_wh_sum = 0;
|
||||||
|
|
||||||
for (uint8_t i=0; i<_mon.num_instances(); i++) {
|
for (uint8_t i=0; i<_mon.num_instances(); i++) {
|
||||||
if (i == _instance) {
|
if (i == _instance) {
|
||||||
// never include self
|
// never include self
|
||||||
|
@ -73,7 +77,11 @@ AP_BattMonitor_Sum::read()
|
||||||
if (!_mon.healthy(i)) {
|
if (!_mon.healthy(i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
voltage_sum += _mon.voltage(i);
|
const float voltage = _mon.voltage(i);
|
||||||
|
if (voltage_count == 0 || voltage < voltage_min) {
|
||||||
|
voltage_min = voltage;
|
||||||
|
}
|
||||||
|
voltage_sum += voltage;
|
||||||
voltage_count++;
|
voltage_count++;
|
||||||
float current;
|
float current;
|
||||||
if (_mon.current_amps(current, i)) {
|
if (_mon.current_amps(current, i)) {
|
||||||
|
@ -86,23 +94,36 @@ AP_BattMonitor_Sum::read()
|
||||||
temperature_sum += temperature;
|
temperature_sum += temperature;
|
||||||
temperature_count++;
|
temperature_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float consumed_mah;
|
||||||
|
if (_mon.consumed_mah(consumed_mah, i)) {
|
||||||
|
consumed_mah_sum += consumed_mah;
|
||||||
|
}
|
||||||
|
|
||||||
|
float consumed_wh;
|
||||||
|
if (_mon.consumed_wh(consumed_wh, i)) {
|
||||||
|
consumed_wh_sum += consumed_wh;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const uint32_t tnow_us = AP_HAL::micros();
|
const uint32_t tnow_us = AP_HAL::micros();
|
||||||
const uint32_t dt_us = tnow_us - _state.last_time_micros;
|
|
||||||
|
|
||||||
if (voltage_count > 0) {
|
if (voltage_count > 0) {
|
||||||
_state.voltage = voltage_sum / voltage_count;
|
if (option_is_set(AP_BattMonitor_Params::Options::Minimum_Voltage)) {
|
||||||
|
_state.voltage = voltage_min;
|
||||||
|
} else {
|
||||||
|
_state.voltage = voltage_sum / voltage_count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (current_count > 0) {
|
if (current_count > 0) {
|
||||||
_state.current_amps = current_sum;
|
_state.current_amps = current_sum;
|
||||||
|
_state.consumed_mah = consumed_mah_sum;
|
||||||
|
_state.consumed_wh = consumed_wh_sum;
|
||||||
}
|
}
|
||||||
if (temperature_count > 0) {
|
if (temperature_count > 0) {
|
||||||
_state.temperature = temperature_sum / temperature_count;
|
_state.temperature = temperature_sum / temperature_count;
|
||||||
_state.temperature_time = AP_HAL::millis();
|
_state.temperature_time = AP_HAL::millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
update_consumed(_state, dt_us);
|
|
||||||
|
|
||||||
_has_current = (current_count > 0);
|
_has_current = (current_count > 0);
|
||||||
_has_temperature = (temperature_count > 0);
|
_has_temperature = (temperature_count > 0);
|
||||||
_state.healthy = (voltage_count > 0);
|
_state.healthy = (voltage_count > 0);
|
||||||
|
|
Loading…
Reference in New Issue