83 Commits

Author SHA1 Message Date
Daniel Agar
298cc61e07 ekf2: push fuse beta config into backend 2022-11-02 10:09:26 -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
b71fc63162 ekf2: fix sideslip timeout (typo) 2022-10-18 18:38:25 -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
bresch
ae1e12a6b5 ekf2: remove baro accumulation from initializeFilter 2022-09-10 12:29:29 -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
bresch
aa716936bf ekf2: move synthetic_position flag to control_status.flags.fake_pos 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
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
f555281c94 ekf2: move height control-related function 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
578e1339ca ekf2: re-implement range aid
range aid simply forces the range finder to be the height reference when
starting
2022-08-24 09:16:11 -04:00
bresch
f9188b2a14 ekf2: refactor vertical acceleration check for multiple height sources 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
bce4237963 move ekf2 Matrix helper utilities to mathlib 2022-08-05 09:58:07 -04: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
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
de74f45e2d ekf2: do not run rng kinematic consistency check for fixed-wings
As they are always moving horizontally, the check doesn't make sense
for fixed-wings.
Also don't run the check while on ground to prevent getting a failed
check during pre-takeoff manipulation.
2022-07-12 13:45:59 -04:00
bresch
2f486c37fc ekf2: start airspeed fusion when test ratio is passing only
When wind is already estimated, we don't reset the states using airspeed
data, so it could be that the fusion fails if the airspeed isn't
consistent with the filter (test ratio > 1). In this case, don't start
the fusion.

When wind isn't already estimated, the wind states are reset using
airspeed so the fusion can start regardless of the current test ratio.
2022-07-07 17:39:06 -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
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
db0274e19b ekf: robustify bad_acc_vertical check
when the vertical pos or vel innov ratio is above the threshold, the
other one needs to be significant too and not just positive to trigger
the failure
2022-04-25 12:58:18 -04:00
bresch
4c03f0bc50 ekf: make range finder kin consistency gate tunable by parameter 2022-04-13 11:41:48 +02:00
bresch
079a5e92ba ekf: run rng consistency check only when not horizontally moving
The check assumes a non-moving terrain height
2022-04-13 11:41:48 +02:00
bresch
d903613c9c ekf: add logging for rng kinematic consistency check 2022-04-13 11:41:48 +02:00
bresch
baf9cc9597 ekf: use uint64_t for time variables 2022-04-13 11:41:48 +02:00
bresch
f96287b80a ekf: access member variable without getter 2022-04-13 11:41:48 +02:00
bresch
904bf8ef9f ekf: add range finder kinematic consistency check
At each new valid range measurement, the time derivative of the distance
to the ground is computed and compared with the estimated velocity.
The average of a normalized innovation squared statistic check is used
to detect a bias in the derivative of distance measurement,
indicating that the distance measurements are kinematically inconsistent
with the filter.
2022-04-13 11:41:48 +02:00
Daniel Agar
a430f0ccae
ekf2: add simple zero velocity update when vehicle at rest (#19149)
- further decreases initial tilt alignment time (now down to 2.5 seconds if still) and improves initial bias estimates
2022-03-12 12:56:31 -05:00
Daniel Agar
b7e0f17c6a ekf2: minor position/velocity reset cleanup
- try to use avoid resetVelocity() call where possible
 - reset timeouts centrally
2022-03-08 11:16:35 -05:00
Daniel Agar
c10ea97967 ekf2: fusion helpers return success/fail and set pos/vel update timestamps centrally (if healthy) 2022-03-08 11:16:35 -05:00
Daniel Agar
d6d529539d ekf2: consolidate and simplify gnd effect logic 2022-02-22 16:59:10 -05:00
Daniel Agar
1d7791dad6 commander: monitor GPS validity and EKF2 dead reckoning
- ekf2: expose dead reckoning as control status flags
 - commander:
    - add GPS validity check
    - in AUTO MISSION if dependent on GPS then a loss of GPS will
2022-02-22 09:46:21 -05:00
bresch
edabfd2f0e ekf_hgt: call specific height reset function instead of generic one
- Also use the delayed current data instead of newest that might not be
available (gps buffer is sometimes empty if the dt between samples is
larger than the delayed horizon).

- Separate "baro fault" from "baro intermittent": intermittent is a
  temporary failure and should prevent from switching to baro right now,
  but "fault" means that it should never be used anymore

- In case of height timeout, check for metrics but not for consistency
  as the filter is likely to have diverged already.
2022-02-22 11:49:25 +01:00
bresch
cba73585e1 use recorded last sensor timestamp for intermittent check 2022-02-22 11:49:25 +01:00
Daniel Agar
5370733d62 ekf2: publish flow vel only if compensated flow is available
- fix a few publication timestamp_samples
2022-02-14 10:55:10 -05:00
bresch
2fb7b35a8b ekf2_terr: refactor terrain estimator - flow aiding 2022-02-11 10:57:45 -05:00
bresch
3077f27821 ekf: use float instead of Vector2f for innov gate in pos/vel fusion
We always use the same innovation gate for X and Y anyway
2022-02-02 17:43:25 -05:00