multicopter: minimize dt jitter by using estimate timestamp_sample

This commit is contained in:
Daniel Agar 2021-12-15 10:30:17 -05:00
parent dcf69144cb
commit 019eaf7038
3 changed files with 4 additions and 4 deletions

View File

@ -99,7 +99,7 @@ void FlightModeManager::Run()
vehicle_local_position_s vehicle_local_position;
if (_vehicle_local_position_sub.update(&vehicle_local_position)) {
const hrt_abstime time_stamp_now = hrt_absolute_time();
const hrt_abstime time_stamp_now = vehicle_local_position.timestamp_sample;
// Guard against too small (< 0.2ms) and too large (> 100ms) dt's.
const float dt = math::constrain(((time_stamp_now - _time_stamp_last_loop) / 1e6f), 0.0002f, 0.1f);
_time_stamp_last_loop = time_stamp_now;

View File

@ -263,8 +263,8 @@ MulticopterAttitudeControl::Run()
}
// Guard against too small (< 0.2ms) and too large (> 20ms) dt's.
const float dt = math::constrain(((v_att.timestamp - _last_run) * 1e-6f), 0.0002f, 0.02f);
_last_run = v_att.timestamp;
const float dt = math::constrain(((v_att.timestamp_sample - _last_run) * 1e-6f), 0.0002f, 0.02f);
_last_run = v_att.timestamp_sample;
/* check for updates in other topics */
_manual_control_setpoint_sub.update(&_manual_control_setpoint);

View File

@ -291,7 +291,7 @@ void MulticopterPositionControl::Run()
vehicle_local_position_s local_pos;
if (_local_pos_sub.update(&local_pos)) {
const hrt_abstime time_stamp_now = local_pos.timestamp;
const hrt_abstime time_stamp_now = local_pos.timestamp_sample;
const float dt = math::constrain(((time_stamp_now - _time_stamp_last_loop) * 1e-6f), 0.002f, 0.04f);
_time_stamp_last_loop = time_stamp_now;