245 Commits

Author SHA1 Message Date
Kamil Ritz
114516b784 Use new added matrix functions 2020-08-24 19:24:27 +10:00
kamilritz
3bd9415498 Make delayed output stayed not a member variable 2020-08-16 10:00:47 +10:00
kamilritz
da9bfe4316 Update interface of applyCorrectionsToOuputStates 2020-08-16 10:00:47 +10:00
kamilritz
b5e1397c0f Add const modifier
const modifier


Add missing const modifier
2020-07-16 18:25:06 +02:00
kamilritz
b0ad9f0226 Replace componentwise with matrix operation 2020-07-16 18:25:06 +02:00
kamilritz
b5765eb3b4 Move variable declaration to better place &
remove airspeed_innov_var_temp variable. setting to global variable even when fusion is aborted is okay
2020-07-16 18:25:06 +02:00
kamilritz
5ef18f8823 Style improvement 2020-07-16 18:25:06 +02:00
kamilritz
b0458fbded Refactor output buffer updates into separate functions 2020-07-16 18:25:06 +02:00
kamilritz
3d82d822ae Add const modifier 2020-07-16 18:25:06 +02:00
kamilritz
430497e2f7 Shift variable definition inside calculateOutputStates 2020-07-02 15:55:24 +02:00
kamilritz
f59343b343 Remove misplaced comment 2020-07-02 15:55:24 +02:00
kamilritz
673b309c45 Fix bug: pos gain used instead of vel gain 2020-07-02 15:55:24 +02:00
kamilritz
2af2696b63 Revert if-else condition to get rid of unnecessary indentation 2020-07-02 15:55:24 +02:00
kamilritz
fce4958d4f Random cleanup 2020-07-02 15:55:24 +02:00
RomanBapst
b7d54b5477 gps: fixed filter initialization bug around gps
- do not gps reference altitude to zero in case gps checks pass before the
filter initialized
- reset the filtered gps position and position derivative filters in case
we are in air or there is movement on the ground

Signed-off-by: RomanBapst <bapstroman@gmail.com>
2020-06-08 16:19:38 +02:00
Matthias Grob
65a4ca9d65 AlphaFilter: merge with PX4 implementation
I made a separate implementation of the same filter for PX4. Now
that I know it's duplicate I merge the two into one and reuse it.
2020-04-20 09:30:07 +02:00
kritz
fa5a00d871
Refactor velocity reset (#788)
* Refactor velocity reset

* Add unit tests for velocity resets

* Expand updates to vertical buffer to velocity resets outside of resetHeight

* Improve matrix library usage

* Improve naming of vertical output samples

* Fix update of output_vert_new during reset

* Improve naming of vertical output samples 2
2020-04-08 16:39:15 +02:00
Kamil Ritz
d6b6276cdc change naming from tiltOffset to pitchOffset 2020-04-04 12:48:52 +02:00
Mathieu Bresciani
0623b2b02d
Range check cleanup (#782)
* EKF: centralize range finder tilt check

* Ekf-control: do not double check for terrain estimate validity

isRangeAidSuitable can only return true if the terrain estimate is valid
so there is no need for an additional check

* range_finder_checks: restructure the checks to avoid early returns

There is now only one clear path that can lead to the validity being
true.
Furthermore, if the _rng_hgt_valid is true, we can trust it and we don't
need for additional checks such as tilt.

The case where we need to provide fake measurements because the drone is
on the ground and the range finder data is bad is already handled
in "controlHeightFusion" so there is no need to hack the range finder
checks with that.

* Add Sensor and SensorRangeFinder classes

The purpose is to encapsulate the checks for each sensor in a dedicated
class with the same interface

* SensorRangeFinder: encapsulate in estimator::sensor namespace

* EKF: rename _sensor_rng to _range_sensor

* Range checks: include limits in valid range

* RangeChecks: update comment in the continuity checks

* RangeChecks: move more low-level checks in functions

Also move setTilt out of the terrain estimator, this is anyway protected internally
to not compute cos/sin if the parameter did not change.

* Sensor: remove unused virtual functions

Those are not required yet but can still be added later

* SensorRangeFinder: re-organise member variables

Also rename getRangeToEarth to getCosTilt

* SensorRangeFinder: split setSensorTilt and setCosMaxTilt functions

* SensorRangeFinder: Add a few unit tests

- good data
- tilt exceeded
- max range exceeded

* SensorRangeFinder: set hysteresis in us instead of ms

* SensorRangeFinder: Add more tests

* SensorRangeFinder: update continuity, hysteresis and stuck tests

* SensorRangeFinder: rename variables

* SensorRangeFinder: get rid of "delayed" specification

From the SensorRangeFinder class point of view, it's not relevant to
know if the data is delayed or not

* SensorRangeFinder: move time_last_valid out of stuck check

* SensorRangeFinder: rename file names to sensor_range_finder

* SensorRangeFinder: address Kamil's comments

* SensorRangeFinder: Add more tilt tests

* SensorRangeFinder: store current tilt offset

This is to avoid recomputing cos/sin functions at each loop
2020-04-03 08:28:07 +02:00
kamilritz
2fa43419d2 Interface: output vector quantities by "return-by-value" 2020-03-30 13:07:00 +02:00
Paul Riseborough
4669aa6312
EKF: Add Emergency yaw recovery using EKF-GSF estimator (#766)
* EKF: Use common rate vector calculation for offset corrections

* EKF: Remove duplicate matrix entry calculations

* EKF: Create a EKF-GSF yaw estimator class

* EKF: add emergency yaw reset functionality

* EKF: remove un-used function

* EKF: Ensure required constants are defined for all builds

* EKF: Fix CI build error

* Revert "EKF: remove un-used function"

This reverts commit 93005309c7f3794414ad99c86218b3062e00bbd3.

* EKF: Replace in-lined Tait-Bryan 312 conversions with function call

Also remove unnecessary operations

* EKF: Remove unnecessary update of external vision rotation matrix

* EKF: Use const

* EKF: use const

* EKF: don't use class variable as a temporary variable

* EKF: update comments

* EKF: Improve efficiency of yaw reset

Use conversion from rotation matrix to Euler angles instead of quaternion to euler angles.

* EKF: use const

* EKF: remove un-used struct element

* EKF: more descriptive function name

* EKF: use existing matrix row operator

* EKF: remove unnecessary rotation matrix update

* EKF: Use square matrix type

* EKF: Improve protection for bad innovation covariance

* EKF: Use matrix library operations

* EKF: Replace memcpy with better alternative

memcpy bypasses compiler sanity checks and is unnecessary in this instance.

* EKF: Split EKF-GSF yaw reset function

Adds a common function to support yaw reset that can be used elsewhere.

* EKF: Use common function for quaternion state and covariance yaw reset

* EKF: Replace inlined matrix operation

* EKF: Use const

* EKF: Change accessor function name

* EKF: Use const

* EKF: Don't create unnecessary duplicate variable locations

* EKF: Remove duplicate covariance innovation inverse

* EKF: Don't create unnecessary duplicate variable locations

* EKF: Rely on geo library to provide gravity

* EKF: Improve protection from bad updates

* EKF: Reduce effect of vibration on yaw estimator AHRS

* EKF: Improve yaw estimator AHRS accuracy during manoeuvre transients
2020-03-05 21:50:52 +11:00
Paul Riseborough
8ce285cdfa
EKF: Don't allow tilt alignment if vehicle is moving excessively (#768)
Also remove unnecessary update of the _accel_lpf after alignment.
2020-03-05 21:42:45 +11:00
Paul Riseborough
b4ecfb7723
EKF: Fix sign error in earth rotation rate correction (#763)
* EKF: Fix sign error in earth rotation rate correction

Addresses issue https://github.com/PX4/ecl/issues/759

* Update change indication output

Co-authored-by: kritz <kritz@ethz.ch>
2020-03-03 20:16:49 +01:00
Paul Riseborough
89bcebd631 EKF: Prevent covariance initialisation overwriting yaw variance
Also typo fix
2020-02-05 15:20:34 +01:00
Paul Riseborough
21054a4236 EKF: Fix bug causing incorrect covariance initialisation
The covariance initialisation should not be performed before the quaternion states are initialised.
2020-02-05 15:20:34 +01:00
kamilritz
be11516dd6 Refactor IMU downsampling into its own class 2020-01-09 19:43:29 +11:00
kamilritz
3daf25763e Remove unnecessary comments 2020-01-08 09:00:31 +01:00
kamilritz
48787c0160 Improve Matrix library usage 2020-01-08 09:00:31 +01:00
kamilritz
9e6d27fafb Add missing const qualifier 2020-01-08 09:00:31 +01:00
kamilritz
f99dbd8ca3 Improve naming and brackets 2020-01-07 08:14:59 +11:00
kamilritz
1c68709949 Rename mag ambiguous mag abbreviations with magnitude 2020-01-07 08:14:59 +11:00
kamilritz
a24aaad861 CleanUp GPS drift checks 2020-01-07 08:14:59 +11:00
kamilritz
c6e3f389d2 Replace calculation of earth NED rotation vector 2020-01-07 08:14:59 +11:00
kamilritz
a6bbafc7b0 Remove unnecessary initialiseCovariance
It is already called in reset()
2019-12-18 09:46:32 +01:00
kritz
01495ede97 Clean initialiseFilter function (#687)
* Clean initialiseFilter

* Add const qualifiers
2019-12-17 13:36:28 +01:00
kritz
6c25ac5731 Tilt Initialisation: Average Filter -> LowPass Filter (#686)
* Tilt Initialisation: Average Filter -> LowPass Filter

* Add _is_first_imu_sample variable

* Remove not needed comments
2019-12-17 11:01:25 +01:00
Daniel Agar
98a1aae494 EKF: use Matrix cross product 2019-12-17 09:35:08 +01:00
kamilritz
85e0e6e89c Remove resetStates(AndCovariances) function 2019-12-13 16:50:56 +01:00
kamilritz
042d9b6615 Remove dangerous _primary_hgt_source variable 2019-12-11 17:23:45 +02:00
kamilritz
66f707ede0 Remove non enterable if statement 2019-12-11 17:23:45 +02:00
kamilritz
cd030e7cd2 Remove switch to ev hgt during filter initialization 2019-12-11 17:23:45 +02:00
kamilritz
4bc6ae69ae Remove if statement that can not be entered 2019-12-11 17:23:45 +02:00
kamilritz
6941777e17 Remove obsolete vision sample counter during initialization 2019-12-11 17:23:45 +02:00
kamilritz
07e804676c Rename IMU biases 2019-12-05 20:09:34 +11:00
kamilritz
dae8c2f8dc Group velocity and position as a 3d vector 2019-12-05 20:09:34 +11:00
Mathieu Bresciani
c7bdf25663
[ekf] controlMagFusion refactor and mag field strength check (#662)
* ekf_control: Inhibit mag fusion when field magnitude is large
Move mag inhibition check in separate function

* ekf_control: pull out of functionalities out of controlMagFusion
- yaw abd mag bias observability checks
- mag 3D conditions
- load mag covariances
- set and clear mag control modes

* ekf_control: refactor mag heading/3D start/stop.
Move mag declination, mag 3d and mag heading fusion out of the main function

* ekf_control: extract mag yaw reset and mag declination fusion requirements

* ekf_control: use WMM in isStronMagneticField for mag fusion inhibition
- Correct units of WMM strength table

* ekf_control: extract mag_state_only functionality of AUTOFW (VTOL custom)
Also split inAirYawReset from onGroundYawReset

* ekf_control: extract mag automatic selection
- transform if-else into switch-case for parameter fusion type selection

* ekf_control: extract run3DMagAndDeclFusion, reorganize functions, fix
flag naming in Test script

* ekf_control: do not run mag fusion if tilt is not aligned.
Reset some variables on ground even if mag fusion is not running yet. It
could be that it runs later so we need to make sure that those variables
are properly set.

* ekf_control: move controlMagFusion and related functions to mag_control.cpp

* ekf control: check for validity of mag strength from WMM and falls back
to average earth mag field with larger gate if not valid

* ekf control: remove evyaw check for mag inhibition

* ekf control: change nested ternary operator into if-else if

* Ekf: create AlphaFilter template class for simple low-pass filtering
0.1/0.9 type low-pass filters are commonly used to smooth data, this
class is meant to abstract the computation of this filter

* ekf control: reset heading using mag_lpf data to avoid resetting on an outlier
fixes ecl issue #525

* ekf control: replace mag_states_only flag with mag_field_disturbed and
add parameter to enable or disable mag field strength check

* ekf control: remove AUTOFW mag fusion type as not needed This was implemented for VTOL but did not solve the problem and should not be used anymore

* ekf control: use start/stop mag functions everywhere instead of setting the flag

* ekf control: Run mag fusion depending on yaw_align instead of tilt_align
as there is no reason to fuse mag when the ekf isn't aligned

* AlphaFilter: add test for float and Vector3f
2019-11-08 16:02:59 +01:00
bresch
a6840655e8 ekf: Extract resetState from main reset and reinitialize
the covariances in the init function
2019-11-05 09:07:25 +01:00
bresch
bf48004fb9 ekf: move "reset" part of the init function into a separate function
add getter for the vehicle at rest flag
2019-11-05 09:07:25 +01:00
Paul Riseborough
36de2b3dc1 EKF: Use matrix library for quaternion to rotation matrix conversion 2019-10-23 14:44:08 +03:00
kritz
4a38f5a2f6 Add timestamp to ECL print statements, (#644)
which is helpful for EKF replay debugging.
2019-09-25 11:24:42 +02:00