mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-08 07:30:34 +08:00
Battery: refactor current integration to be easier understandable
This commit is contained in:
committed by
ChristophTobler
parent
9fbd6b912d
commit
823d423456
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user