Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Battery compensation fix #8868

Merged
merged 3 commits into from
Feb 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/modules/systemlib/battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,21 @@ Battery::sumDischarged(hrt_abstime timestamp, float current_a)
void
Battery::estimateRemaining(float voltage_v, float current_a, float throttle_normalized, bool armed)
{


// remaining battery capacity based on voltage
float cell_voltage = voltage_v / _n_cells.get();

// correct battery voltage locally for load drop to avoid estimation fluctuations
if (_r_internal.get() >= 0.f) {
voltage_v += _r_internal.get() * current_a;
cell_voltage += _r_internal.get() * current_a;

} else {
// assume quadratic relation between throttle and current
// good assumption if throttle represents RPM
voltage_v += throttle_normalized * throttle_normalized * _v_load_drop.get();
cell_voltage += throttle_normalized * throttle_normalized * _v_load_drop.get();
}

// remaining battery capacity based on voltage
const float cell_voltage = voltage_v / _n_cells.get();
_remaining_voltage = math::gradual(cell_voltage, _v_empty.get(), _v_charged.get(), 0.f, 1.f);

// choose which quantity we're using for final reporting
Expand Down