Commit Graph

131 Commits

Author SHA1 Message Date
bresch b00d4a9237 mag fusion: improve on ground forced mag fusion logic
While a yaw test ration > 1 rejects the mag data in air, the fusion is
forced with a limited innovation on ground to fix gyro bias and local
magnetic effects problems pre-takeoff. However, the same logic is
applied after landing and immediately after the land detector detects
landing. In some cases, this can disturb the other EKF states which can
lead to a state change of the land detector.
To avoid such a loop, the start of this forced yaw fusion is delayed by
5 seconds after landing.
2021-02-18 10:11:51 +01:00
Paul Riseborough f666ebb995 EKF: Code format fix - replace 1E-x with 1e-x 2020-10-06 20:50:52 +11:00
Daniel Agar 4c2355a638 EKF: use GPS to lookup declination from WMM before full GPS checks pass 2020-09-28 08:43:32 +02:00
bresch 264c8c4e86 mag_fusion: mag heading and 3d modes are mutually exclusive
There is no need to check if 3d fusion is active when in mag heading
fusion mode since this is impossible
2020-08-27 15:48:40 +10:00
kamilritz 4fb4e0ca01 Clean euler321 and euler312 code and comment 2020-08-27 09:51:56 +10:00
Kamil Ritz 2be738e806 Add helper function to alter heading in rotation matrices 2020-08-27 09:51:56 +10:00
Kamil Ritz fdc86c247a add functions to compute yaw (321 and 312 sequence)
from quaternion and rotation matrix
2020-08-27 09:51:56 +10:00
Kamil Ritz 15afa8ae17 shouldUse321RotationSequence(const Dcmf& R) 2020-08-27 09:51:56 +10:00
Kamil Ritz 1f637af7de Add const modifier 2020-08-24 19:24:27 +10:00
kamilritz 644e903552 Apply measurementUpdate function 2020-08-24 18:04:57 +10:00
kamilritz f6252ff533 small cleanup in limitDeclination 2020-08-24 18:04:57 +10:00
Paul Riseborough f89c52e840 EKF: use ecl::powf for integer exponents 2020-08-15 08:40:59 +10:00
Paul Riseborough 21cc46edd7 EKF: Convert magnetic field observation methods to use SymPy generated code (#879)
* EKF: Add comparison test for mag field fusion generated code

* EKF: convert mag field fusion to use SymPy generated code

* EKF: Add test comparison program for yaw fusion equations

* Stop setting 0 to 0

* Reduce if/else statement to only if

* EKF: more accurate implementation for sequential fusion of magnetometer data

* test: update change indicator

* Use matrix::SparseVector<float, 24, ...> for observation jacobian

* Adapt the auto code generation to allow for different bracket styles

* Add auto generated code for mag fusion

* Add generic computation of KHP

* Apply generic computation of KHP to mag fusion

* tests: update change indicator

* tests: update change indicator

Co-authored-by: kamilritz <kritz@ethz.ch>
2020-08-11 18:57:22 +10:00
kamilritz 7eb2b08eed Yaw measurement jacobian to Vector4f 2020-08-04 09:57:00 +02:00
kamilritz 89bfcc2167 Introduce checkAndFixCovarianceUpdate(KHP) function 2020-07-16 18:25:06 +02:00
kamilritz 5c4a3d4576 Make observation jacobian a Vector24f when possible 2020-07-16 18:25:06 +02:00
kamilritz b5e1397c0f Add const modifier
const modifier


Add missing const modifier
2020-07-16 18:25:06 +02:00
kamilritz 796afd5f98 Rename yaw_use_inhibit -> is_yaw_fusion_inhibited
Temp
2020-07-16 18:25:06 +02:00
kamilritz 3d82d822ae Add const modifier 2020-07-16 18:25:06 +02:00
kamilritz 122f58b94d Bug: stop overwriting fault status of index 0 with index 1 2020-07-02 15:55:24 +02:00
kamilritz e5ddd912a4 Remove not needed else case 2020-07-02 15:55:24 +02:00
kamilritz 16a00eae0b Make Kfusion a Vector24f 2020-07-02 09:02:24 +02:00
kamilritz 356b2f6ffe Stop setting zero to zero 2020-07-02 09:02:24 +02:00
kamilritz 552bf824ea Add typedef for Matrix 24 types 2020-07-02 09:02:24 +02:00
kamilritz 48f0eb16da Remove uninformative comments 2020-06-26 08:26:26 +02:00
kamilritz 4a69b41015 Increase matrix library usage even more 2020-06-26 08:26:26 +02:00
kamilritz 22274b1d30 Add const modifier 2020-06-26 08:26:26 +02:00
kamilritz 61c139ea95 Remove unused variable 2020-06-26 08:26:26 +02:00
kamilritz afd4f3f86b Fix typo 2020-06-26 08:26:26 +02:00
kamilritz b8f937666a Make mag_innov/-var a Matrix::Vector3f 2020-06-26 08:26:26 +02:00
kamilritz ff8b5ec69d Extract general functions into utils 2020-06-23 08:18:34 +02:00
kritz 24f2e60b7e Reduce stored strings, to save flash space (#815) 2020-05-13 08:09:26 +02:00
Paul Riseborough 89b5c77d5d EKF: Enable GPS flight without magnetometer (#770)
* EKF: Enable GPS flight without magnetometer

Enables takeoff in a non-GPS flight mode with mag fusion type set to MAG_FUSE_TYPE_NONE. After sufficient movement the EKF will reset the yaw tot he EKF-GSF estimate. After that GPS fusion will commence.

* EKF: Fix unconstrained yaw and yaw variance growth when on ground

* EKF: Ensure first yaw alignment can't be blocked

* EKF: Increase yaw variance limit allowed for alignment

Flight test data indicates that an uncertainty value of 15 deg still provides a reliable yaw estimate and enables an earlier alignment/reset if required.

* EKF: Remove unexecutable code

* EKF: Restructure heading fusion

* EKF: parameterise quarter variance check and retune default value

* EKF: Pass by reference instead of pointer

* EKF: Clarify reset logic

* EKF: Remove incorrect setting of mag field alignment flag

* EKF: Non-functional tidy up

* EKF: Fix non-use of function argument

The updateQuaternion function was using the _heading_innovation class variable instead of setting it using the innovation argument.

* EKF: Fix undefined variable

* EKF: Use single precision atan2

* EKF: remove unnecessary timer reset and unwanted execution of reset function

* EKF: Don't declare a mag fault when non-use is user selected

Doing so produces unnecessary user alerts.
2020-03-30 20:05:38 +11: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
CarlOlsson b6420d0b79 ekf: add vehicle at rest to flags 2020-02-12 18:58:24 +01:00
Paul Riseborough a19c29e708 EKF: Rework yaw fusion to remove singularity at +-90 deg yaw 2020-01-23 09:23:56 +11:00
bresch d0fe1f032a mag_fusion: re-introduce delay between mag reset and fusion, this was
dropped during the mag fusion refactor PR #662
2020-01-15 14:40:06 +11:00
kamilritz 07e8e88e88 Support full vision variance 2020-01-08 14:36:03 +01:00
kamilritz 4ab3dd50c9 pass Vector by const reference 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
Paul Riseborough 0d0f46ec1c EKF: Don't run unnecessary makeRowColSymmetric operation
This operation is expensive when done to the whole covariance matrix and unnecessary after covariance prediction because we calculate the upper diagonal and copy across so it is already symmetric.
2020-01-02 19:26:57 +11:00
kamilritz 92ba618f57 Improve on flash memory usage 2020-01-02 19:26:57 +11:00
kamilritz 459b76f9fd Make covariance matrices of type matrix::SquareMatrix
and use functions from Matrix to reset covariances.
2020-01-02 19:26:57 +11:00
kamilritz 1bf09fd370 Remove EKF prefix from logged messages 2019-12-12 08:48:10 +01: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
Paul Riseborough 4d37065f1b EKF: Make use of inverse rotation function consistent with name
The quaternion to inverse rotation matrix function has been updated so that the rotation it produces is the inverse to that produced by the matrix library and the the inverse of the quaternion is uses. This function is now used to directly calculate an inverse rotation matrix rather than calculating the forward rotation and then transposing it.
2019-10-23 14:44:08 +03:00
Paul Riseborough eae6e8f19c EKF: Fix on ground yaw drift when using EKF2_MAG_TYPE = 4 2019-10-08 20:08:42 +11:00
RomanBapst 4e946d5bcb implemented synthesized magnetometer Z measurement
- calculate a theoretical value based on the knowledge of the direction
and strength of the magnetic field vector and X/Y sensor measurements
- needs knowledge about location on earth to work
2019-10-08 20:02:16 +11: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