Skip to content

Commit

Permalink
Merge pull request #2114 from mavlink/pr-fix-battery-voltage
Browse files Browse the repository at this point in the history
Fix battery voltage, included extended voltages
  • Loading branch information
JonasVautherin authored Aug 15, 2023
2 parents 9e06fc4 + a09f836 commit e7657c2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/mavsdk/plugins/telemetry/telemetry_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1221,11 +1221,20 @@ void TelemetryImpl::process_battery_status(const mavlink_message_t& message)
static_cast<float>(NAN) :
bat_status.temperature * 1e-2f; // cdegC to degC
new_battery.voltage_v = 0.0f;
for (int i = 0; i < 255; i++) {
if (bat_status.voltages[i] == std::numeric_limits<uint16_t>::max())
for (int i = 0; i < 10; ++i) {
if (bat_status.voltages[i] == std::numeric_limits<uint16_t>::max()) {
break;
}
new_battery.voltage_v += static_cast<float>(bat_status.voltages[i]) * 1e-3f;
}

for (int i = 0; i < 4; ++i) {
// A value of 1 means 0 mV.
if (bat_status.voltages_ext[i] > 1) {
new_battery.voltage_v += static_cast<float>(bat_status.voltages_ext[i]) * 1e-3f;
}
}

new_battery.remaining_percent = bat_status.battery_remaining;
new_battery.current_battery_a = (bat_status.current_battery == -1) ?
static_cast<float>(NAN) :
Expand Down

0 comments on commit e7657c2

Please sign in to comment.