Battery: refactor current integration to be easier understandable

This commit is contained in:
Matthias Grob
2017-10-23 17:06:01 +02:00
committed by ChristophTobler
parent 9fbd6b912d
commit 823d423456
+4 -2
View File
@@ -156,9 +156,11 @@ Battery::sumDischarged(hrt_abstime timestamp, float current_a)
return;
}
// Ignore first update because we don't know dT.
// Ignore first update because we don't know dt.
if (_last_timestamp != 0) {
_discharged_mah += current_a * ((float)(timestamp - _last_timestamp)) / 1e3f / 3600.f;
const float dt = (timestamp - _last_timestamp) / 1e6;
// current[A] * 1000 = [mA]; dt[s] / 3600 = [h]
_discharged_mah += (current_a * 1e3f) * (dt / 3600.f);
}
_last_timestamp = timestamp;