@@ -246,7 +246,7 @@ void Ekf::resetHeight()
246
246
// initialize vertical position with newest baro measurement
247
247
const baroSample &baro_newest = _baro_buffer.get_newest ();
248
248
249
- if (_time_last_imu - baro_newest.time_us < 2 * BARO_MAX_INTERVAL) {
249
+ if (isRecent ( baro_newest.time_us , 2 * BARO_MAX_INTERVAL) ) {
250
250
_state.pos (2 ) = _hgt_sensor_offset - baro_newest.hgt + _baro_hgt_offset;
251
251
252
252
// the state variance is the same as the observation
@@ -260,7 +260,7 @@ void Ekf::resetHeight()
260
260
261
261
} else if (_control_status.flags .gps_hgt ) {
262
262
// initialize vertical position and velocity with newest gps measurement
263
- if (_time_last_imu - gps_newest.time_us < 2 * GPS_MAX_INTERVAL) {
263
+ if (isRecent ( gps_newest.time_us , 2 * GPS_MAX_INTERVAL) ) {
264
264
_state.pos (2 ) = _hgt_sensor_offset - gps_newest.hgt + _gps_alt_ref;
265
265
266
266
// the state variance is the same as the observation
@@ -296,7 +296,7 @@ void Ekf::resetHeight()
296
296
}
297
297
298
298
// reset the vertical velocity state
299
- if (_control_status.flags .gps && (_time_last_imu - gps_newest.time_us < 2 * GPS_MAX_INTERVAL)) {
299
+ if (_control_status.flags .gps && isRecent ( gps_newest.time_us , 2 * GPS_MAX_INTERVAL)) {
300
300
// If we are using GPS, then use it to reset the vertical velocity
301
301
_state.vel (2 ) = gps_newest.vel (2 );
302
302
@@ -1386,22 +1386,23 @@ bool Ekf::global_position_is_valid()
1386
1386
void Ekf::update_deadreckoning_status ()
1387
1387
{
1388
1388
bool velPosAiding = (_control_status.flags .gps || _control_status.flags .ev_pos || _control_status.flags .ev_vel )
1389
- && (((_time_last_imu - _time_last_hor_pos_fuse) <= _params.no_aid_timeout_max )
1390
- || ((_time_last_imu - _time_last_hor_vel_fuse) <= _params.no_aid_timeout_max )
1391
- || ((_time_last_imu - _time_last_delpos_fuse) <= _params.no_aid_timeout_max ));
1392
- bool optFlowAiding = _control_status.flags .opt_flow && ((_time_last_imu - _time_last_of_fuse) <= _params.no_aid_timeout_max );
1393
- bool airDataAiding = _control_status.flags .wind && ((_time_last_imu - _time_last_arsp_fuse) <= _params.no_aid_timeout_max ) && ((_time_last_imu - _time_last_beta_fuse) <= _params.no_aid_timeout_max );
1389
+ && (isRecent (_time_last_hor_pos_fuse, _params.no_aid_timeout_max )
1390
+ || isRecent (_time_last_hor_vel_fuse, _params.no_aid_timeout_max )
1391
+ || isRecent (_time_last_delpos_fuse, _params.no_aid_timeout_max ));
1392
+ bool optFlowAiding = _control_status.flags .opt_flow && isRecent (_time_last_of_fuse, _params.no_aid_timeout_max );
1393
+ bool airDataAiding = _control_status.flags .wind &&
1394
+ isRecent (_time_last_arsp_fuse, _params.no_aid_timeout_max ) &&
1395
+ isRecent (_time_last_beta_fuse, _params.no_aid_timeout_max );
1394
1396
1395
1397
_is_wind_dead_reckoning = !velPosAiding && !optFlowAiding && airDataAiding;
1396
1398
_is_dead_reckoning = !velPosAiding && !optFlowAiding && !airDataAiding;
1397
1399
1398
- // record the time we start inertial dead reckoning
1399
1400
if (!_is_dead_reckoning) {
1400
- _time_ins_deadreckon_start = _time_last_imu - _params.no_aid_timeout_max ;
1401
+ _time_last_aiding = _time_last_imu - _params.no_aid_timeout_max ;
1401
1402
}
1402
1403
1403
1404
// report if we have been deadreckoning for too long
1404
- _deadreckon_time_exceeded = ((_time_last_imu - _time_ins_deadreckon_start) > ( unsigned )_params.valid_timeout_max );
1405
+ _deadreckon_time_exceeded = isTimedOut (_time_last_aiding, ( uint64_t )_params.valid_timeout_max );
1405
1406
}
1406
1407
1407
1408
// calculate the inverse rotation matrix from a quaternion rotation
@@ -1748,7 +1749,6 @@ float Ekf::kahanSummation(float sum_previous, float input, float &accumulator) c
1748
1749
return t;
1749
1750
}
1750
1751
1751
-
1752
1752
void Ekf::stopGpsFusion ()
1753
1753
{
1754
1754
stopGpsPosFusion ();
0 commit comments