84 Commits

Author SHA1 Message Date
Daniel Agar
54a32eb2f7
ekf2: EV overhaul yaw and position fusion (#20501)
- move EV yaw and EV position to new state machines
 - EV yaw and EV pos now configured via EKF2_EV_CTRL (migrated from EKF2_AID_MASK)
 - new EV position offset estimator to enable EV position while GPS position is active (no more EV pos delta fusion)
 - yaw_align now strictly means north (no more rotate external vision aid mask)
 - automatic switching between EV yaw, and yaw align north based on GPS quality
2022-12-20 10:23:56 -05:00
Daniel Agar
696eeb9a49
ekf2: update EV height state machine (small piece of EV overhaul)
- respect new EKF2_EV_CTRL parameter for VPOS usage
  - EV hgt rotate EV position before usage (there's often a small offset in frames)
  - EV hgt reset use proper EV velocity body frame
  - try to keep EV hgt and EV vel state machines consistent
  - small incremental piece of https://github.com/PX4/PX4-Autopilot/pull/19128
2022-12-13 13:29:18 -05:00
Daniel Agar
805ffa9d0b ekf2: push mag cal reset to delayed time horizon 2022-12-13 10:24:02 -05:00
Daniel Agar
8eb2a0a3ec ekf2: delete orientation_covariances_euler()
- usage replaced with now public calcRotVecVariances()
2022-12-07 12:41:27 -05:00
Daniel Agar
da82757bf6
ekf2: accumulate multiple vel/pos/orientation reset deltas per update
- if in a single EKF update there are multiple resets we need to track the accumulated delta so the change consumed by the controllers is correct
2022-11-15 13:20:54 -05:00
bresch
4dbdf23346 ekf2: update _R_to_earth when the state quat changed through fusion 2022-11-14 11:51:32 -05:00
bresch
9834c7917b ekf2: use yaw emergency estimator more aggressively
During the whole flight, if the difference between the yaw estimate from
EKF2 and the emergency estimator is large and that the GNSS velocity
fusion is failing continuously, immediately reset to the emergency yaw
estimate.
2022-11-14 10:45:23 -05:00
Daniel Agar
5239993c88 ekf2: move EV vel to new state machine, introduce EKF2_EV_CTRL param 2022-11-08 11:46:41 -05:00
Daniel Agar
6f861ba889 ekf2: pos/vel reset helpers pass new variance
- optical flow velocity reset use already computed _flow_vel_ne
2022-10-24 10:59:58 -04:00
Daniel Agar
ed558e199f ekf2: remove realignYawGPS() (replaced with yaw estimator) 2022-10-21 09:01:30 -04:00
Daniel Agar
fb3adc3faa
ekf2: move baro compensation to delayed time horizon and add validity check
- this removes an unnecessary virtual call and simplifies things a bit

Co-authored-by: bresch <brescianimathieu@gmail.com>
2022-10-20 09:17:55 -04:00
Daniel Agar
f9509b442c
ekf2: height aid source consistency (#20405)
- working towards keeping all height source (baro/ev/gnss/rng) handling as consistent as possible, possibly refactoring these out into separate classes later
2022-10-19 15:35:07 -04:00
Daniel Agar
535415a537 ekf2: add OF estimator aid src status 2022-10-18 14:19:16 -04:00
Daniel Agar
2de990fd4b estimator_aid_source split GNSS pos (3d) -> pos (2d) + hgt
- per estimator air source status only keep a single set of flags and
timestamp that applies to the entire source
2022-10-13 11:28:50 -04:00
bresch
5f54f6fcda ekf2: migrate sideslip fusion to SymForce
- split fusion into update (compute innov and innov_var) and actual fusion to the state vector
- use estimator_aid_source_1d struct to group the data
2022-10-12 09:55:35 -04:00
bresch
bb790c9bec ekf2: add vertical dead-reckoning timeout check for height validity 2022-09-29 14:16:36 -04:00
Daniel Agar
1f7080a710 ekf2: extend sensor bias stability requirement
- for accel/gyro/mag estimated bias only consider them stable (valid
for calibration updates) if the value isn't changing (10% of limit) over
the validity period
2022-09-28 10:40:52 -04:00
Charles Cross
cfdaba35cc Adds reset counter logic to EV height fusion 2022-09-26 11:48:18 +02:00
bresch
facf01d69d ekf2: report combined vertical position test ratio 2022-09-15 08:51:19 -04:00
bresch
a54fa7b9b1 ekf2: add fake height fusion logic
When there is no vertical aiding, fake height is started to constrain
the vertical channel of the EKF
2022-09-10 12:29:29 -04:00
Daniel Agar
d996af4647 ekf2: pass gpsSample around where required
- this minimizes potential misuse accessing _gps_sample_delayed and
makes the dependency clear
2022-09-05 10:27:19 -04:00
Daniel Agar
7bbdc220f5 ekf2: initialiseFilter() simplify mag heading init and resetQuatStateYaw
- most of resetQuatStateYaw doesn't apply to initial heading init, so
removing the special case keeps it simple
2022-09-02 08:46:10 -04:00
Daniel Agar
1948c5057a ekf2: handle all time on delayed horizon (except for newest sample checks)
- a growing number of samples come into the backend with the time
already delayed (sensor's interrupt setting timestamp sample)
 - if the incoming timestamp is already delayed then the new data checks
(relative to latest IMU) can be slightly wrong
 - handle almost all timestamps and checks on delayed time horizon,
except for explicit checks of new samples
 - isRecent() and isTimedOut() helpers use delayed time
 - add new isNewestSampleRecent() used for checking the incoming
timestamp of the incoming (adjusted) data
2022-08-31 08:52:30 -04:00
bresch
2d39097f60 ekf2: move rng height to file 2022-08-24 09:16:11 -04:00
bresch
28b4cd0579 ekf2: move GNSS hgt control to file 2022-08-24 09:16:11 -04:00
bresch
b6f76b5eaa ekf2: move ev control to file 2022-08-24 09:16:11 -04:00
bresch
d87feee5b0 ekf2: move baro control logic to file 2022-08-24 09:16:11 -04:00
bresch
12e25eba62 ekf2: add common height fusion timeout parameter 2022-08-24 09:16:11 -04:00
bresch
8962cf2d25 ekf2: GPS, baro and range finder control parameters
Also remove the legacy "range aid" than can be achieved by setting the
height reference to range finder and the range finder control parameter
to "conditional".

Conditional range aiding cal also be set when the height reference isn't
the range finder. This prevents the ratchetting effect due to switching
between references.
2022-08-24 09:16:11 -04:00
bresch
8fd79688c0 ekf2: enable multiple height sources fusion
Instead of having a single height source fused into the EKF and the
other ones "waiting" for a failure or the primary sensor, fuse all
sources in EKF2 at the same time. To prevent the sources from fighting against each
other, the "primary" source is set as reference and the other ones are
running a bias estimator in order to make all the secondary height
sources converge to the primary one.

If the reference isn't available, another one is automatically selected
from a priority list. This secondary reference keeps its current bias
estimate but stops updating it in order to be the new reference as close
as possible to the primary one.
2022-08-24 09:16:11 -04:00
Daniel Agar
66b55d9d0a ekf2: fix yaw estimator velocity accuracy
- additionally require GPS speed accuracy is within EKF2_REQ_SACC
2022-08-08 21:27:01 -04:00
Daniel Agar
dfdfbbfa9c
msg/vehicle_odometry.msg: simplify covariance handling and update all usage (#19966)
- replace float32[21] URT covariances with smaller dedicated position/velocity/orientation variances (the crossterms are unused, awkward, and relatively costly)
 - these are easier to casually inspect and more representative of what's actually being used currently and reduces the size of vehicle_odometry_s quite a bit
 - ekf2: add new helper to get roll/pitch/yaw covariances
 - mavlink: receiver ODOMETRY handle more frame types for both pose (MAV_FRAME_LOCAL_NED, MAV_FRAME_LOCAL_ENU, MAV_FRAME_LOCAL_FRD, MAV_FRAME_LOCAL_FLU) and velocity (MAV_FRAME_LOCAL_NED, MAV_FRAME_LOCAL_ENU, MAV_FRAME_LOCAL_FRD, MAV_FRAME_LOCAL_FLU, MAV_FRAME_BODY_FRD)
 - mavlink: delete unused ATT_POS_MOCAP stream (this is just a passthrough)

Co-authored-by: Mathieu Bresciani <brescianimathieu@gmail.com>
2022-08-04 12:55:21 -04:00
bresch
61f390b0dd ekf2_test: fix height offset compensation after origin reset 2022-08-04 16:50:31 +02:00
Daniel Agar
41d9c3dd2a ekf2: add AUX velocity aid src status
- also includes velocity and position helpers for using estimator aid
   source status messages that will later be used for GPS, EV, etc
2022-07-29 12:02:31 -04:00
Daniel Agar
a397c09e59 ekf2: use estimator_aid_src for all yaw sources (mag, gnss, ev) 2022-07-29 11:20:48 -04:00
Daniel Agar
70e95812e7 ekf2: reset mag_lpf (by zeroing _mag_counter) when resetting mag bias (or changing mags)
- so that there's new filtered data avaiable for reset
2022-07-21 09:24:28 -04:00
Daniel Agar
05133aed27 ekf2: clear test ratios, flags, etc when stopping mag fusion 2022-07-21 09:24:28 -04:00
Daniel Agar
a41a0e7e80 ekf2: resetMagHeading() split out simple init case 2022-07-21 09:24:28 -04:00
Daniel Agar
39453405a0 ekf2: cleanup zero innovation heading fusion
- refactor updateQuaternion() to compute the yaw jacobian directly (respecting  the rotation sequence determination)
 - fuseHeading()/fuseYaw321()/fuseYaw312() helpers are eliminated and now mag heading fusion and EV yaw fusion compute the innovation in place
 - clear up logic for performing zero innovation heading fusion when quaternion variance exceeds threshold (no more _is_yaw_fusion_inhibited flag manipulation)
 - when at rest continue fusing last static heading with very low variance even if other heading sources are active
2022-07-19 11:58:27 -04:00
bresch
2fd87c47e8 ekf2: use estimator_aid_source_1d message for airspeed fusion
split the fusion process into:
1. updateAirspeed: computes innov, innov_var, obs_var, ...
2. fuseAirspeed: uses data computed in 1. to generate K, H and fuse the
   observation
2022-07-07 09:42:54 -04:00
Daniel Agar
dc8ed97809 ekf2: optical flow control limits constrain speed using HAGL max 2022-06-21 12:52:25 -04:00
Daniel Agar
b81a5b3efa ekf2: request mag yaw reset after calibration or sensor change 2022-06-17 21:04:05 -04:00
Daniel Agar
1980b5c5e8
ekf2: setEkfGlobalOrigin() reset baro and hgt sensor offsets if necessary
- handle uninitalized _gps_alt_ref
 - add basic lat/lon/alt sanity checks
2022-06-16 00:59:54 -04:00
Daniel Agar
58ea6235fe ekf2: estimator aid source status (range height) 2022-05-25 09:25:12 -04:00
Daniel Agar
1e25aee6fa ekf2: estimator aid source status (baro height) 2022-05-25 09:25:12 -04:00
Daniel Agar
639222dd65 ekf2: estimator aid source status (GPS pos, GPS vel) 2022-05-23 16:21:49 -04:00
mcsauder
ea10eacb99 Replace EKF/common.h #defines with enums. 2022-05-18 09:25:19 -04:00
bresch
37cafe7dcd ekf rng kin: reduce minimum rng variance 2022-04-13 11:41:48 +02:00
bresch
064518f57a ekf: extract range finder noise computation 2022-04-13 11:41:48 +02:00
Daniel Agar
7ef38112d2 ekf2: return saved mag bias variance when not in 3d magnetometer fusion
- the estimated mag bias was requiring > 30 seconds of continuous 3d
mag fusion to be reported stable (and saved back to mag cal), this
restores the original intent requiring 30 seconds of accumulated valid
3d mag fusion
2022-03-14 21:03:41 -04:00