Commit Graph

1129 Commits

Author SHA1 Message Date
bresch 0e3bf2872c EKFGSF_yaw: cleanup initialization of member variables 2020-05-08 16:55:23 +02:00
Paul Riseborough cda7486897
EKF: Prevent yaw reset to GPS caused by loss of GPS data (#805) 2020-04-30 17:50:26 +10:00
kamilritz 8b6d665a13 Avoid subtraction of two uint 2020-04-27 10:17:01 +02:00
Kamil Ritz 050298f6c1 Improve matrix library usage 2020-04-25 10:11:01 +02:00
Kamil Ritz 5749273d19 refactor resetPosition 2020-04-25 10:11:01 +02:00
Paul Riseborough 8a9d961f0d
EKF: Improve covariance prediction stability (#795)
* EKF: Improve covariance prediction stability

Eliminates collapse of vertical velocity state variance due to rounding errors that can occur under some operating conditions.

* EKF: Fix typo

* test: Fix initialisation test cases

Provide sufficient time for variances to stabilise and fix calculation of reference quaternion for alignment.

* test: Allow for accumulated rounding error in IMU sampling test

* test: Allow sufficient time for quaternion variances to reduce after initial alignment

* test: Increase allowance for tilt alignment delay and inertial nav errors

* test: Increase allowance for tilt alignment delay and inertial nav errors

* adpat reset velocity test

* test: update change indication file

* test: Adjust tests to handle alignment time and prediction errors

* README.md: Add documentation for change indicator test
2020-04-23 14:38:09 +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
bresch 30d69aa45b Ekf: extract baro height offset computation 2020-04-19 12:38:13 +02:00
bresch 6b64cf0770 Ekf: centralize GPS height fusion startup 2020-04-19 12:38:13 +02:00
bresch 61763544b6 Ekf: centralize baro fusion startup 2020-04-19 12:38:13 +02:00
Kamil Ritz 1fa6870cd6 Perform geo.cpp's mathlib calls in double point precision 2020-04-13 20:34:41 +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
Daniel Agar 47624a0f02
EKF increase delta velocity process noise per axis if clipping (#663) 2020-04-08 08:51:51 +10:00
Kamil Ritz d6b6276cdc change naming from tiltOffset to pitchOffset 2020-04-04 12:48:52 +02:00
bresch 572ad2df0a SensorRangeFinder: add distBottom function to get the vertical distance 2020-04-03 11:01:23 +02:00
bresch a998da1781 terrain_estimator: initialize with valid delayed measurement 2020-04-03 11:01:23 +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
Paul Riseborough 544385fd8c
EKF: Simplify centripetal accel correction (#789) 2020-04-01 13:36:56 +11:00
kamilritz 2fa43419d2 Interface: output vector quantities by "return-by-value" 2020-03-30 13:07:00 +02:00
kamilritz 72d8f91b4d Innovation getters: Add const modifier 2020-03-30 13:07:00 +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
Mathieu Bresciani 3bd09fdcd3
EKF: fix range height sensor offset (#787)
The offset needs to be updated directly when switching to range height
2020-03-26 20:22:32 +11:00
TSC21 870ec380f1 elk_helper: use ISFINITE macro instead of isfinite() 2020-03-20 22:42:46 +01:00
bresch 20c3db69e4 Terrain Est: Add sensor aiding bitmask
This adds the ability to select range finder and/or optical flow fusion for
terrain estimate.
2020-03-19 17:53:30 +01:00
bresch f38388cdab YawEst: simplify AHRS accelerometer gain computation
Replace the multiple if-else statements by a generic equation.
- For a multicopter, the attenuation factor is 2 and symmetrical
- For a fixedwing, the attenuation factor is 1 if the acceleration is
positive and that centripetal correction is available and 2 otherwise.

Note that the function "sq" needs to be const in order to be used in a
const function.
2020-03-18 17:45:13 +01:00
CarlOlsson ee5e3c479b ekfgsf: fix formatting 2020-03-18 08:34:02 +01:00
Mathieu Bresciani f20fc08b7d
ekf2: centralize mag covariance reset (#693)
* ekf2: centralize mag covariance reset. A complete and clean reset of the
mag states covariances is now performed through the "resetMagCov"
function only. This avoid having slight differences of implementations
across the code.

* Ekf: reset quat cov with initial uncertainty instead of zero
2020-03-17 20:07:20 +11:00
kamilritz 975060d108 Add missing const modifier 2020-03-11 16:46:16 +01:00
kamilritz 7e20d9df14 Small style cleanup 2020-03-11 16:46:16 +01:00
Daniel Agar 580118e366
EKFGSF_yaw::updateEKF() R_prev copy safely (#775)
* EKFGSF_yaw::updateEKF() R_prev copy safely

* only copy required values (first 3)
2020-03-11 15:49:45 +01:00
bresch d09473da89 Ekf control: do not set hgt mode if already set
If we are in a certain height mode and that we do a reset to the
same mode, there is no need to set the mode again.
2020-03-09 20:22:57 +01:00
bresch 13a7d53295 Ekf: correct wrong indentation 2020-03-09 20:22:57 +01:00
bresch 684737eab1 Ekf control: replace individual by global check of baro/GPS health
Use _gps_data_intermittent and _baro_hgt_faulty to know is the sensors
provide fresh data
2020-03-09 20:22:57 +01:00
bresch 320a90d146 EKF control: extract checkVerticalAccelerationHealth logic
This is done to reduce the size of the controlHeightSensorTimeouts
function and to clarify the logic
2020-03-09 20:22:57 +01:00
CarlOlsson 93be6ea49a EKF: dont print wrong reset message on baro timeout
Signed-off-by: CarlOlsson <carlolsson.co@gmail.com>
2020-03-09 09:06:49 +01:00
kritz bcd3869ca2
CleanUp of the EKFGSF (#769)
* Add const modifiers

* Pass imu data as sampe

* Remove emergency reset request counter

* Improve matrix library usage

* Indentation fix

* Do not store innovation matrix for each model

* Make weights a separate vector

* EKF: Add missing alignment transfer to AHRS solutions

* EKF: Replace #define constants with static constexpr

* EKF: Move declaration for weights into GSF section

* EKF: Fix documentation error

Co-authored-by: Paul Riseborough <p_riseborough@live.com.au>
2020-03-06 19:37:35 +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
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
Mathieu Bresciani 230c865fa9
EKF: do not fuse multiple times the same height (#767)
* EKF: do not fuse multiple times the same height

The _fuse_height flag was never set to zero, hence the fusion was called
at each iteration, even if no new data is available.
The effects were: high CPU usage and virtually less measurement noise
due to multiple fusion of the same sample

Also remve unused variables
2020-03-04 10:31:22 +01: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
Daniel Agar 4fab6057a7 EKF control height fusion add switch statement for all dist sensor types 2020-03-03 11:29:07 +01:00
Carl Olsson 3fa5f501ae
EKF: dont check gps_check_fail_status in velocity reset (#761)
In a velocity reset we only used the GPS measurement if _gps_check_fail_status.value was equal to zero. The value of this flag is independent of EKF2_GPS_CHECK so checks can fail even if they are not configured to have any effect.
2020-02-27 11:59:38 +01:00
Daniel Agar 71d4d22ae4
EKF: covariances() helper return const reference and fix code style
- PX4 astyle puts the reference with the name.
2020-02-21 11:28:44 -05:00
bresch 8b918563a2 ekf: fix angle wrapping in realignYawGPS
To obtain the correct difference between two angles, we need to wrap
the result between -pi and pi. Otherwise, the difference between two
angles close to 180 degrees but with opposite signs will produce a large
error.
For example if a = -179 and b = 179, b - a = 258 instead of -2 degrees
2020-02-21 13:08:30 +01:00
Daniel Agar 00872fcaa3
EKF: ImuDownSampler pass imuSample as const reference
- inline ImuDownSampler::getDownSampledImuAndTriggerReset()
 - minor formatting and initialization cleanup
2020-02-18 13:20:52 -05:00
bresch 81c6d6655f ekf: clean uncorrelateQuatStates function
As the name can be ambiguous, it gets renamed
"uncorrelateQuatFromOtherStates".
Also replace the loops storing the values and reapplying them by simply
zeroing two slices (this also saves 130B of flash).
2020-02-13 14:33:32 +01:00
bresch 90ca012705 ekf_helper: restore oridinal quaternion decorrelation
The intent of the function "uncorrelateQuatStates()" is to uncorrelathe quaternions from the other states but not between each other as they are and should remain linked alltogether.
Clearing the quaternions to quaternion covariances introduced unstabilities in other states (especially accel biases).
2020-02-12 22:03:22 +01:00
CarlOlsson b6420d0b79 ekf: add vehicle at rest to flags 2020-02-12 18:58:24 +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 a3347b7e06 EKF: Use more conservative value for delta velocity bias process noise
Smaller values have resulted in bias estimation divergence under some conditions
2020-02-05 15:20:34 +01:00