Skip to content

Commit

Permalink
esc_battery: report temperature
Browse files Browse the repository at this point in the history
Co-authored-by: Jacob Dahl <37091262+dakejahl@users.noreply.github.com>
  • Loading branch information
AlexKlimaj and dakejahl authored Feb 12, 2025
1 parent b96b4fb commit 98cba19
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/modules/esc_battery/EscBattery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,25 @@ EscBattery::Run()
const uint8_t online_esc_count = math::countSetBits(esc_status.esc_online_flags);
float average_voltage_v = 0.0f;
float total_current_a = 0.0f;
float average_temperature_c = 0.0f;

for (unsigned i = 0; i < esc_status.esc_count; ++i) {
if ((1 << i) & esc_status.esc_online_flags) {
average_voltage_v += esc_status.esc[i].esc_voltage;
total_current_a += esc_status.esc[i].esc_current;

if (PX4_ISFINITE(esc_status.esc[i].esc_temperature)) {
average_temperature_c += esc_status.esc[i].esc_temperature;
}
}
}

average_voltage_v /= online_esc_count;
total_current_a /= online_esc_count;
average_temperature_c /= online_esc_count;

_battery.setConnected(true);
_battery.updateTemperature(average_temperature_c);
_battery.updateVoltage(average_voltage_v);
_battery.updateCurrent(total_current_a);
_battery.updateAndPublishBatteryStatus(esc_status.timestamp);
Expand Down

0 comments on commit 98cba19

Please # to comment.