diff --git a/libraries/SITL/SIM_Battery.cpp b/libraries/SITL/SIM_Battery.cpp index 4517ee5d6a5..2ca27494b44 100644 --- a/libraries/SITL/SIM_Battery.cpp +++ b/libraries/SITL/SIM_Battery.cpp @@ -178,19 +178,17 @@ void Battery::consume_energy(float current_amp, uint64_t now_us) voltage_filter.apply(voltage, dt); - update_temperature(current_amp, now_us); + update_temperature(current_amp, dt); } -void Battery::update_temperature(float current_amp, uint64_t now_us) +void Battery::update_temperature(float current_amp, float dt) { - const uint64_t temperature_dt = now_us - temperature.last_update_us; - temperature.last_update_us = now_us; // thermal_capacity value chosen to match previous steady-state behavior at 28amps // (reminder: thermal_capacity = mass * specific_heat) constexpr float thermal_capacity = 2.8f; // watt*seconds/degC constexpr float inverse_of_thermal_capacity = 1 / thermal_capacity; // use inverse so we can multiply, not divide - const float temp_increase = (current_amp * current_amp) * resistance_ohm * inverse_of_thermal_capacity * (temperature_dt * 0.000001); + const float temp_increase = (current_amp * current_amp) * resistance_ohm * inverse_of_thermal_capacity * dt; // decay temperature at some %second towards ambient - const float temp_decrease = (temperature.kelvin - 273.15f) * 0.10 * temperature_dt * 0.000001; + const float temp_decrease = (temperature.kelvin - 273.15f) * 0.10 * dt; temperature.kelvin += (temp_increase - temp_decrease); } diff --git a/libraries/SITL/SIM_Battery.h b/libraries/SITL/SIM_Battery.h index 09e98cc546e..047a25e1d05 100644 --- a/libraries/SITL/SIM_Battery.h +++ b/libraries/SITL/SIM_Battery.h @@ -51,9 +51,8 @@ private: struct { float kelvin = 273; - uint64_t last_update_us; } temperature; - void update_temperature(float current_amp, uint64_t now_us); + void update_temperature(float current_amp, float dt); // 10Hz filter for battery voltage LowPassFilterFloat voltage_filter{10};