battery: report over voltage

This commit is contained in:
Matthias Grob 2021-12-06 18:46:11 +01:00
parent 54d26e084a
commit ae888b73d0
2 changed files with 15 additions and 0 deletions

View File

@ -166,6 +166,7 @@ battery_status_s Battery::getBatteryStatus()
battery_status.id = static_cast<uint8_t>(_index);
battery_status.warning = _warning;
battery_status.timestamp = hrt_absolute_time();
battery_status.faults = determineFaults();
return battery_status;
}
@ -267,6 +268,19 @@ uint8_t Battery::determineWarning(float state_of_charge)
}
}
uint16_t Battery::determineFaults()
{
uint16_t faults{0};
if ((_params.n_cells > 0)
&& (_voltage_v > (_params.n_cells * _params.v_charged * 1.05f))) {
// Reported as a "spike" since "over-voltage" does not exist in MAV_BATTERY_FAULT
faults |= (1 << battery_status_s::BATTERY_FAULT_SPIKES);
}
return faults;
}
void Battery::computeScale()
{
const float voltage_range = (_params.v_charged - _params.v_empty);

View File

@ -150,6 +150,7 @@ private:
float calculateStateOfChargeVoltageBased(const float voltage_v, const float current_a);
void estimateStateOfCharge();
uint8_t determineWarning(float state_of_charge);
uint16_t determineFaults();
void computeScale();
float computeRemainingTime(float current_a);