44 #include <mathlib/mathlib.h> 58 if ((angle_err_var_vec(0) + angle_err_var_vec(1)) <
sq(
math::radians(3.0
f))) {
222 Eulerf euler_init(q_init);
228 euler_init(2) = euler_obs(2);
373 vel_aligned -= vel_offset_earth;
429 const bool motion_is_excessive = ((accel_norm > (
CONSTANTS_ONE_G * 1.5f))
434 if (motion_is_excessive) {
454 float gps_err_norm_lim;
456 gps_err_norm_lim = 0.7f;
458 gps_err_norm_lim = 1.0f;
471 if ((preflight_motion_not_ok || flight_motion_not_ok) && !flow_required) {
478 if (preflight_motion_ok || flight_motion_ok || flow_required) {
776 (_vel_pos_innov[2] > 0.0f) &&
781 if (bad_vert_accel) {
804 if (hgt_fusion_timeout || continuous_bad_accel_hgt) {
806 bool reset_height =
false;
827 bool reset_to_baro = !reset_to_gps && baro_hgt_available;
840 }
else if (reset_to_baro) {
854 reset_height =
false;
872 bool reset_to_baro = baro_data_consistent && baro_data_fresh && !
_baro_hgt_faulty && !gps_hgt_accurate;
891 }
else if (reset_to_gps) {
901 reset_height =
false;
925 }
else if (reset_to_baro) {
938 reset_height =
false;
954 bool reset_to_baro = !ev_data_available && baro_data_available;
957 bool reset_to_ev = ev_data_available;
970 }
else if (reset_to_ev) {
980 reset_height =
false;
1176 && horz_vel_valid) {
1369 if (data_ready && primary_aiding) {
float ev_pos_innov_gate
vision position fusion innovation consistency gate size (STD)
constexpr _Tp constrain(_Tp val, _Tp min_val, _Tp max_val)
float _cos_tilt_rng
cosine of the range finder tilt rotation about the Y body axis
struct estimator::filter_control_status_u::@60 flags
#define VDIST_SENSOR_RANGE
Use range finder height.
uint64_t _time_bad_vert_accel
last time a bad vertical accel was detected (uSec)
void setControlBaroHeight()
float _posInnovGateNE
Number of standard deviations used for the NE position fusion innovation consistency check...
bool pop_first_older_than(const uint64_t ×tamp, data_type *sample)
uint64_t _time_last_ext_vision
Vector3f delta_ang
delta angle in body frame (integrated gyro measurements) (rad)
float ev_vel_innov_gate
vision velocity fusion innovation consistency gate size (STD)
float switch_on_gyro_bias
1-sigma gyro bias uncertainty at switch on (rad/sec)
bool _fuse_height
true when baro height data should be fused
float hgt
gps height measurement (m)
uint32_t gps_yaw
22 - true when yaw (not ground course) data from a GPS receiver is being fused
stateSample _state
state struct of the ekf running at the delayed time horizon
float _vel_pos_innov_var[6]
NED velocity and position innovation variances: 0-2 vel ((m/sec)**2), 3-5 pos (m**2) ...
#define VDIST_SENSOR_GPS
Use GPS height.
uint32_t yaw_align
1 - true if the filter yaw alignment is complete
RingBuffer< outputSample > _output_buffer
void setControlGPSHeight()
bool resetMagHeading(const Vector3f &mag_init, bool increase_yaw_var=true, bool update_buffer=true)
RingBuffer< extVisionSample > _ext_vision_buffer
float _vel_pos_innov[6]
NED velocity and position innovations: 0-2 vel (m/sec), 3-5 pos (m)
Vector3f ev_pos_body
xyz position of VI-sensor focal point in body frame (m)
float range_cos_max_tilt
cosine of the maximum tilt angle from the vertical that permits use of range finder and flow data ...
const data_type & get_newest()
dragSample _drag_sample_delayed
Vector2f _hpos_pred_prev
previous value of NE position state used by odometry fusion (m)
float _gps_alt_ref
WGS-84 height (m)
float gps_vel_innov_gate
GPS velocity innovation consistency gate size (STD)
void controlHeightSensorTimeouts()
uint32_t fuse_aspd
19 - true when airspeed measurements are being fused
Vector2f pos
NE earth frame gps horizontal position measurement (m)
uint32_t fixed_wing
17 - true when the vehicle is operating as a fixed wing vehicle
Quatf quat
quaternion defining rotation from body to earth frame
Vector3f _imu_del_ang_of
bias corrected delta angle measurements accumulated across the same time frame as the optical flow ra...
void controlOpticalFlowFusion()
#define EV_MAX_INTERVAL
Maximum allowable time interval between external vision system measurements (uSec) ...
#define MASK_USE_EVYAW
set to true to use external vision quaternion data for yaw
bool _flow_for_terrain_data_ready
bool _ev_rot_mat_initialised
_ev_rot_mat should only be initialised once in the beginning through the reset function ...
uint64_t _last_gps_pass_us
last system time in usec that the GPS passed it's checks
float _hgt_sensor_offset
set as necessary if desired to maintain the same height after a height reset (m)
float gps_pos_noise
minimum allowed observation noise for gps position fusion (m)
uint32_t rng_hgt
10 - true when range finder height is being fused as a primary height reference
bool _fuse_hpos_as_odom
true when the NE position data is being fused using an odometry assumption
Vector3f cross_product(const Vector3f &vecIn1, const Vector3f &vecIn2)
uint64_t time_us
timestamp of the measurement (uSec)
airspeedSample _airspeed_sample_delayed
uint32_t baro_hgt
9 - true when baro height is being fused as a primary height reference
float _mag_inclination_gps
uint64_t _last_gps_fail_us
last system time in usec that the GPS failed it's checks
bool _fuse_vert_vel
true when gps vertical velocity measurement should be fused
rangeSample _range_sample_delayed
void checkRangeAidSuitability()
float vacc
1-std vertical position error (m)
Vector3f gyroXYZ
measured delta angle of the inertial frame about the body axes obtained from rate gyro measurements (...
float range_aid_innov_gate
gate size used for innovation consistency checks for range aid fusion
float _flow_max_rate
maximum angular flow rate that the optical flow sensor can measure (rad/s)
float gps_vel_noise
minimum allowed observation noise for gps velocity fusion (m/sec)
int32_t fusion_mode
bitmasked integer that selects which aiding sources will be used
uint8_t _imu_buffer_length
int32_t vdist_sensor_type
selects the primary source for height data
bool _range_aid_mode_selected
true when range finder is being used as the height reference instead of the primary height sensor ...
float dt
amount of integration time (sec)
float P[_k_num_states][_k_num_states]
state covariance matrix
uint64_t _time_good_vert_accel
last time a good vertical accel was detected (uSec)
uint64_t _time_bad_motion_us
last system time that on-ground motion exceeded limits (uSec)
Vector3f pos
XYZ position in earth frame (m) - Z must be aligned with down axis.
static constexpr float CONSTANTS_ONE_G
auxVelSample _auxvel_sample_delayed
bool _mag_inhibit_yaw_reset_req
true when magnetometer inhibit has been active for long enough to require a yaw reset when conditions...
uint64_t _time_last_gnd_effect_on
const T & getState() const
float max_vel_for_range_aid
maximum ground velocity for which we allow to use the range finder as height source (if range_aid == ...
float rng
range (distance to ground) measurement (m)
#define GPS_MAX_INTERVAL
Maximum allowable time interval between GPS measurements (uSec)
float _terrain_vpos
estimated vertical position of the terrain underneath the vehicle in local NED frame (m) ...
Vector2f velVarNE
estimated error variance of the NE velocity (m/sec)**2
bool _NED_origin_initialised
uint64_t _time_last_of_fuse
time the last fusion of optical flow measurements were performed (uSec)
float yaw
yaw angle. NaN if not set (used for dual antenna GPS), (rad, [-PI, PI])
uint64_t _time_last_hgt_fuse
time the last fusion of height measurements was performed (uSec)
float _hagl_innov_var
innovation variance for the last height above terrain measurement (m**2)
#define MASK_USE_GEO_DECL
set to true to use the declination from the geo library when the GPS position becomes available...
float sacc
1-std speed error (m/sec)
#define BARO_MAX_INTERVAL
Maximum allowable time interval between pressure altitude measurements (uSec)
RingBuffer< gpsSample > _gps_buffer
bool _baro_data_ready
true when new baro height data has fallen behind the fusion time horizon and is available to be fused...
void controlFusionModes()
uint32_t synthetic_mag_z
25 - true when we are using a synthesized measurement for the magnetometer Z component ...
bool _fuse_hor_vel
true when gps horizontal velocity measurement should be fused
AlphaFilterVector3f _mag_lpf
filtered magnetometer measurement (Gauss)
Dcmf _R_to_earth
transformation matrix from body frame to earth frame from last EKF prediction
float _hvelInnovGate
Number of standard deviations used for the horizontal velocity fusion innovation consistency check...
uint32_t ev_vel
24 - true when local earth frame velocity data from external vision measurements are being fused ...
Vector3f rng_pos_body
xyz position of range sensor in body frame (m)
void controlExternalVisionFusion()
uint64_t time_us
timestamp of the measurement (uSec)
float calculate_synthetic_mag_z_measurement(Vector3f mag_meas, Vector3f mag_earth_predicted)
#define RNG_MAX_INTERVAL
Maximum allowable time interval between range finder measurements (uSec)
void update_deadreckoning_status()
float baro_noise
observation noise for barometric height fusion (m)
bool _inhibit_flow_use
true when use of optical flow and range finder is being inhibited
void controlHeightFusion()
int32_t mag_declination_source
bitmask used to control the handling of declination data
bool _ev_data_ready
true when new external vision system data has fallen behind the fusion time horizon and is available ...
uint64_t _time_last_pos_fuse
time the last fusion of horizontal position measurements was performed (uSec)
float posErr
1-Sigma horizontal position accuracy (m)
uint32_t gnd_effect
20 - true when protection from ground effect induced static pressure rise is active ...
Vector3f calcRotVecVariances()
baroSample _baro_sample_delayed
Vector3f vel
NED earth frame gps velocity measurement (m/sec)
float auxvel_gate
velocity fusion innovation consistency gate size (STD)
Vector2f _flowRadXYcomp
measured delta angle of the image about the X and Y body axes after removal of body rotation (rad)...
int bad_acc_reset_delay_us
Continuous time that the vertical position and velocity innovation test must fail before the states a...
bool canResetMagHeading() const
uint64_t time_us
timestamp of the measurement (uSec)
bool _baro_hgt_faulty
true if valid baro data is unavailable for use
int32_t range_aid
allow switching primary height source to range finder if certain conditions are met ...
bool _flow_data_ready
true when the leading edge of the optical flow integration period has fallen behind the fusion time h...
#define VDIST_SENSOR_EV
Use external vision.
Vector3f gps_pos_body
xyz position of the GPS antenna in body frame (m)
constexpr T radians(T degrees)
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
float rng_gnd_clearance
minimum valid value for range when on ground (m)
RingBuffer< dragSample > _drag_buffer
float req_vacc
maximum acceptable vertical position error (m)
#define MASK_USE_OF
set to true to use optical flow data
uint8_t quality
quality indicator between 0 and 255
filter_control_status_u _control_status
RingBuffer< baroSample > _baro_buffer
Vector3f vel
NED velocity in earth frame in m/s.
float _mag_declination_gps
void setDiag(float(&cov_mat)[_k_num_states][_k_num_states], uint8_t first, uint8_t last, float variance)
float _aux_vel_innov[2]
NE auxiliary velocity innovations: (m/sec)
uint32_t ev_hgt
14 - true when height data from external vision measurements is being fused
Vector2f flowRadXY
measured delta angle of the image about the X and Y body axes (rad), RH rotation is positive ...
static constexpr float sq(float var)
bool _tas_data_ready
true when new true airspeed data has fallen behind the fusion time horizon and is available to be fus...
RingBuffer< magSample > _mag_buffer
uint32_t ev_yaw
13 - true when yaw data from external vision measurements is being fused
#define BADACC_PROBATION
Period of time that accel data declared bad must continuously pass checks to be declared good again (...
float baro_innov_gate
barometric and GPS height innovation consistency gate size (STD)
float _delta_time_of
time in sec that _imu_del_ang_of was accumulated over (sec)
bool _velpos_reset_request
true when a large yaw error has been fixed and a velocity and position state reset is required ...
uint64_t _time_last_fake_gps
same flag as "_flow_data_ready" but used for separate terrain estimator
float hgt
pressure altitude above sea level (m)
void increaseQuatYawErrVariance(float yaw_variance)
gpsSample _gps_sample_delayed
float _posObsNoiseNE
1-STD observation noise used for the fusion of NE position data (m)
void controlAuxVelFusion()
bool _hpos_prev_available
true when previous values of the estimate and measurement are available for use
#define MASK_USE_EVPOS
set to true to use external vision position data
RingBuffer< auxVelSample > _auxvel_buffer
Vector2f velNE
measured NE velocity relative to the local origin (m/sec)
Dcmf _ev_rot_mat
transformation matrix that rotates observations from the EV to the EKF navigation frame...
uint32_t mag_aligned_in_flight
23 - true when the in-flight mag field alignment has been completed
imuSample _imu_sample_delayed
#define ECL_WARN_TIMESTAMPED
#define MASK_USE_GPS
set to true to use GPS data
bool _rng_hgt_valid
true if range finder sample retrieved from buffer is valid
void setControlRangeHeight()
Quatf quat_nominal
quaternion defining the rotation from body to earth frame
void setControlEVHeight()
filter_control_status_u _control_status_prev
void resetWindCovariance()
float max_hagl_for_range_aid
maximum height above ground for which we allow to use the range finder as height source (if range_aid...
Vector3f pos
NED position in earth frame in m.
static int do_reset(const char *excludes[], int num_excludes)
uint32_t mag_dec
6 - true if synthetic magnetic declination measurements are being fused
#define MASK_USE_DRAG
set to true to use the multi-rotor drag model to estimate wind
Vector3< float > Vector3f
float beta_avg_ft_us
The average time between synthetic sideslip measurements (uSec)
extVisionSample _ev_sample_delayed
uint32_t opt_flow
3 - true if optical flow measurements are being fused
float _R_rng_to_earth_2_2
2,2 element of the rotation matrix from sensor frame to earth frame
float _hagl_innov
innovation of the last height above terrain measurement (m)
float _vvelInnovGate
Number of standard deviations used for the vertical velocity fusion innovation consistency check...
#define VDIST_SENSOR_BARO
Use baro height.
uint64_t _time_last_arsp_fuse
time the last fusion of airspeed measurements were performed (uSec)
bool _gps_hgt_intermittent
true if gps height into the buffer is intermittent
float vert_innov_test_lim
Number of standard deviations allowed before the combined vertical velocity and position test is decl...
float _sin_tilt_rng
sine of the range finder tilt rotation about the Y body axis
#define MASK_ROTATE_EV
set to true to if the EV observations are in a non NED reference frame and need to be rotated before ...
uint64_t time_us
timestamp of the measurement (uSec)
Quaternion< float > Quatf
void controlVelPosFusion()
uint32_t in_air
7 - true when the vehicle is airborne
struct Ekf::@62 _state_reset_status
reset event monitoring structure containing velocity, position, height and yaw reset information ...
RingBuffer< rangeSample > _range_buffer
uint64_t _time_good_motion_us
last system time that on-ground motion was within limits (uSec)
flowSample _flow_sample_delayed
Vector3f _pos_meas_prev
previous value of NED position measurement fused using odometry assumption (m)
bool _fuse_pos
true when gps position data should be fused
Vector2f _last_known_posNE
last known local NE position vector (m)
Vector3f _velObsVarNED
1-STD observation noise variance used for the fusion of NED velocity data (m/sec)**2 ...
uint32_t wind
8 - true when wind velocity is being estimated
uint64_t _time_last_delpos_fuse
time the last fusion of incremental horizontal position measurements was performed (uSec) ...
uint32_t ev_pos
12 - true when local position data from external vision is being fused
RingBuffer< airspeedSample > _airspeed_buffer
Vector3f imu_pos_body
xyz position of IMU in body frame (m)
uint32_t fuse_beta
15 - true when synthetic sideslip measurements are being fused
float hacc
1-std horizontal position error (m)
uint64_t _delta_time_baro_us
delta time between two consecutive delayed baro samples from the buffer (uSec)
Vector3f vel
XYZ velocity in earth frame (m/sec) - Z must be aligned with down axis.
uint32_t gps_hgt
11 - true when GPS height is being fused as a primary height reference
float angErr
1-Sigma angular error (rad)
uint64_t _time_last_vel_fuse
time the last fusion of velocity measurements was performed (uSec)
float _ang_rate_mag_filt
angular rate magnitude after application of a decaying envelope filter (rad/sec)
bool isRangeAidSuitable()
int32_t flow_qual_min
minimum acceptable quality integer from the flow sensor
float _baro_hgt_offset
baro height reading at the local NED origin (m)
uint32_t gps
2 - true if GPS measurements are being fused
float pos_noaid_noise
observation noise for non-aiding position fusion (m)
uint32_t tilt_align
0 - true if the filter tilt alignment is complete
void controlAirDataFusion()
static constexpr float FILTER_UPDATE_PERIOD_S
bool _bad_vert_accel_detected
true when bad vertical accelerometer data has been detected
void uncorrelateQuatStates()
RingBuffer< flowSample > _flow_buffer
#define GNDEFFECT_TIMEOUT
Maximum period of time that ground effect protection will be active after it was last turned on (uSec...
float velErr
1-Sigma velocity accuracy (m/sec)
Vector3f mag
NED magnetometer body frame measurements (Gauss)
void updateRangeDataValidity()
uint64_t _time_last_beta_fuse
time the last fusion of synthetic sideslip measurements were performed (uSec)
Vector3f _accel_vec_filt
acceleration vector after application of a low pass filter (m/sec**2)
uint64_t _time_last_hagl_fuse
last system time that the hagl measurement failed it's checks (uSec)
Vector3f gyro_bias
delta angle bias estimate in rad
#define MASK_USE_GPSYAW
set to true to use GPS yaw data if available
Quatf quat_nominal
nominal quaternion describing vehicle attitude
bool _gps_data_ready
true when new GPS data has fallen behind the fusion time horizon and is available to be fused ...
bool calcOptFlowBodyRateComp()
float delta_ang_dt
delta angle integration period (sec)
Class for core functions for ekf attitude and position estimator.
uint64_t time_us
timestamp of the integration period leading edge (uSec)
bool isTerrainEstimateValid() const override
uint64_t time_us
timestamp of the measurement (uSec)
unsigned reset_timeout_max
maximum time we allow horizontal inertial dead reckoning before attempting to reset the states to the...
float gps_pos_innov_gate
GPS horizontal position innovation consistency gate size (STD)
#define ECL_INFO_TIMESTAMPED
bool _using_synthetic_position
true if we are using a synthetic position to constrain drift
bool _mag_data_ready
true when new magnetometer data has fallen behind the fusion time horizon and is available to be fuse...
float _gps_error_norm
normalised gps error
#define MASK_USE_EVVEL
sset to true to use external vision velocity data
bool _range_data_ready
true when new range finder data has fallen behind the fusion time horizon and is available to be fuse...
uint8_t get_length() const
bool _fuse_hor_vel_aux
true when auxiliary horizontal velocity measurement should be fused
uint8_t _obs_buffer_length
bool _is_range_aid_suitable
true when range finder can be used in flight as the height reference instead of the primary height se...
magSample _mag_sample_delayed