Skip to content

Commit

Permalink
battery: report over voltage
Browse files Browse the repository at this point in the history
  • Loading branch information
MaEtUgR committed Nov 6, 2023
1 parent 54d26e0 commit ae888b7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/lib/battery/battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/lib/battery/battery.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class Battery : public ModuleParams
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);

Expand Down

0 comments on commit ae888b7

Please sign in to comment.