AP_BattMonitor: Sum: report average temperature

This commit is contained in:
Iampete1 2024-07-27 15:02:04 +01:00 committed by Andrew Tridgell
parent 45647718cb
commit 600d9eb7a8
2 changed files with 18 additions and 0 deletions

View File

@ -54,6 +54,9 @@ AP_BattMonitor_Sum::read()
float current_sum = 0;
uint8_t current_count = 0;
float temperature_sum = 0.0;
uint8_t temperature_count = 0;
for (uint8_t i=0; i<_mon.num_instances(); i++) {
if (i == _instance) {
// never include self
@ -77,6 +80,12 @@ AP_BattMonitor_Sum::read()
current_sum += current;
current_count++;
}
float temperature;
if (_mon.get_temperature(temperature, i)) {
temperature_sum += temperature;
temperature_count++;
}
}
const uint32_t tnow_us = AP_HAL::micros();
const uint32_t dt_us = tnow_us - _state.last_time_micros;
@ -87,10 +96,15 @@ AP_BattMonitor_Sum::read()
if (current_count > 0) {
_state.current_amps = current_sum;
}
if (temperature_count > 0) {
_state.temperature = temperature_sum / temperature_count;
_state.temperature_time = AP_HAL::millis();
}
update_consumed(_state, dt_us);
_has_current = (current_count > 0);
_has_temperature = (temperature_count > 0);
_state.healthy = (voltage_count > 0);
if (_state.healthy) {

View File

@ -22,6 +22,9 @@ public:
/// returns true if battery monitor provides current info
bool has_current() const override { return _has_current; }
/// returns true if battery monitor provides temperature info
bool has_temperature() const override { return _has_temperature; }
void init(void) override {}
static const struct AP_Param::GroupInfo var_info[];
@ -31,6 +34,7 @@ private:
AP_Int16 _sum_mask;
uint8_t _instance;
bool _has_current;
bool _has_temperature;
};
#endif // AP_BATTERY_SUM_ENABLED