86 Commits

Author SHA1 Message Date
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
Daniel Agar
f62662ee46 update change_indication for newer WMM tables 2020-08-21 16:54:45 -04:00
PX4 BuildBot
802a6d99a0 Update geo_lookup WMM to latest Fri Aug 21 11:48:14 UTC 2020 2020-08-21 16:54:45 -04:00
kamilritz
bd0c5fbb97 Update change indication for ekf gsf 2020-08-20 22:16:28 +02:00
kamilritz
3ae934544f Add change indication for ekf_gsf_reset 2020-08-18 17:13:46 +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
ec93490890 geo test change to arc length 2020-08-10 22:15:43 +02:00
kamilritz
98dec6afa6 add tests for waypoint_from_line_and_distance() 2020-08-10 22:15:43 +02:00
kamilritz
9d7d502c56 std::sin -> sin 2020-08-09 15:28:35 -04:00
Julian Kent
9ea3468091 Negative distances go in the opposite direction 2020-08-09 11:36:36 -04:00
kamilritz
b7e49f20e4 Update change indication 2020-08-09 11:08:59 -04:00
Paul Riseborough
77b11129fa
EKF: replacement of covariance prediction autocode with sympy generated output (#870)
* added python script with ekf derivation (WIP)

Signed-off-by: RomanBapst <bapstroman@gmail.com>

* worked on c code auto-generation

Signed-off-by: RomanBapst <bapstroman@gmail.com>

* save before variable name change

Signed-off-by: RomanBapst <bapstroman@gmail.com>

* changed symbol names

Signed-off-by: RomanBapst <bapstroman@gmail.com>

* added codegeneration class

Signed-off-by: RomanBapst <bapstroman@gmail.com>

* improve 3D mag fusion derivation

Signed-off-by: RomanBapst <bapstroman@gmail.com>

* EKF: Extend ekf sympy derivation to include all observation types

* EKF: Add custom ecl::powf function for integer powers

* EKF: Convert ekf covariance prediction to use sympy output

* EKF: Add test program to compare sympy and matlab covariance prediction

Also tests ecl::powf(x,exp) function

* EKF: simplify ecl::powf function

* Generate code to subfolder generated/

* Add printouts for showing code generation progress

* Move generated covariance code to generated folder

* Upgrade code generation to python3

* main.py: Remove unused create_symbols function

& making code more compact

* main.py: move main part into function

* Code generation: fix passing wrong rotation matrix to yaw_observation ()

* EKF: Amend generated code filename for consistency

* Move ecl::powf function test to unit tests

* EKF: Use updated ecl:powf functionality in test program

* Move ecl::powf to utils.hpp

* Update ecl::powf test

* Update output change indication

* test: update expected output for change indicator

* test: update expected output for change indicator again

Co-authored-by: RomanBapst <bapstroman@gmail.com>
Co-authored-by: kamilritz <kritz@ethz.ch>
2020-07-30 12:44:08 +10:00
Daniel Agar
185f22b094
geo_lookup: copyright header consistency and minor update
Minor consistency fixes for the copyright header and update the tables to current. PX4Buildbot will periodically update the tables automatically from this point.
2020-07-20 13:01:56 -04:00
Daniel Agar
9aa7991654
geo_lookup: upgrade table size (2 bytes per element) and add testing
- updated table to 2 bytes (int16) per element and scaled the inclination/declination/strength tables to use most of the range without being too awkward
 - tables have been extended to include the full latitude range
 - expanded the API slightly to offer declination/inclination in both degrees/radians and the magnetic strength in Gauss and Tesla
 - generated some simple testing that verifies interpolation between points
2020-07-19 18:53:47 -04:00
bresch
7f4fedde6a GPS Yaw: fix heading initialisation and add unit tests
When the antennas are not parallel to the x body axis, the GPS message
contains the angular offset but the data is already corrected in the
driver. EKF2 should then not add this offset during the initialisation.
2020-07-02 13:35:13 +02:00
kamilritz
16a00eae0b Make Kfusion a Vector24f 2020-07-02 09:02:24 +02:00
bresch
2bafe9df08 GPS Yaw: wait to fuse at yaw at least once before declaring it faulty
This fixes the cases where the yaw message from the GNSS receiver would
take more time than the vel/pos. The estimator should wait and not
immediately fall back to an other aiding source after 5sec.
If it never comes, it will never fall back, but this is ok since the
user wants to fly with GPS aiding an not with something else.
2020-06-23 08:43:48 +02:00
bresch
51cd63d626 GPS Yaw: fall back to other yaw aiding source in case of bad data
If the user selects GPS yaw fusion but that there is no GPS yaw data in
the GPS message or if the fusion is rejected for some time, the GPS yaw
data is declared faulty and the fusion is stopped to allow an other
source of yaw aiding to start.
2020-06-23 08:43:48 +02:00
bresch
3c6790f5d5 GPS Yaw: Always reset Yaw when GPS Yaw fusion is starting
Also avoid fusing fake mag data when an other source of yaw aiding
is active, even if in MAG_TYPE_NONE mode.
2020-06-23 08:43:48 +02:00
Matthias Grob
a296fe7d8c Move AlphaFilter out of EKF 2020-06-15 13:07:51 -04:00
bresch
821e1fa8fc terrain_estimator: add unit tests 2020-06-05 20:44:30 +02:00
bresch
5d6a72e383 sensor_simulator: add possibility to set GPS position rate
one can set the position rate = velocity to obtain consistent gps data
2020-06-05 20:44:30 +02:00
bresch
62e15cbacf sensor_simulator: set IMU rate to 200Hz as this is the new value
used in the Firmware
2020-06-03 17:09:20 +02:00
bresch
6126c190b2 sensor_simulator: update EKF at IMU rate
This is how it is also done in ekf2_main. Otherwise, this leads to
multiple integration of the same IMU data due to asynchronous sensor
updates triggering a prediction step between IMU updates.

Fix unit tests that broke because of this fix
2020-06-03 17:09:20 +02:00
Mathieu Bresciani
b024cdd282
unit test: check that the accel bias is only learned when observable (#827) 2020-05-25 11:10:01 +02:00
kamilritz
39c09b8092 add basic gps yaw fusion test 2020-05-20 08:52:52 +02:00
kritz
bf78044bcd
EKF: fix initialization of local position validity 2 (#820)
The `_deadreckon_time_exceeded` flag is used in
`local_position_is_valid()`. This means that
`_params.valid_timeout_max` after startup, in my observed case 5
seconds, the local position switche from valid to invalid and then after
a while back to valid again.

With this fix, the local position is flagged invalid from boot and gets validated after the first aiding event.

Co-authored-by: Julian Oes <julian@oes.ch>
2020-05-20 08:24:23 +02:00
Mathieu Bresciani
37d9cef262
ekf: disable xy accel bias learning before takeoff (#818)
* ekf: disable xy accel bias learning before takeoff

As those biases are usually poorly observable before takeoff because
they are almost perpendicular to the gravity vector, learning is often
driven by noise and numerical issues. This results in incorrect bias
learning before takeoff when the drone is static on ground for a long
period of time.

* ekf: update unit test and change indicator
2020-05-19 18:02:40 +10:00
Mathieu Bresciani
9788c3bdf2
ekf: split accel bias learning in independant xyz components (#817)
This is a non-functional change required to select accel bias estimation
per axis selection. The intent is then to disable the learning before
takeoff of the components that are poorly observable.
2020-05-15 09:20:27 +02:00
kritz
98801ad17b
Support vision velocity expressed in body frame too (#708)
* Support vision velocity expressed in body frame

* Use switch statement for vision velocity frame

* Robustify vision velocity frame test

* Increase lower bound on vision velocity noise to 0.05 m/s
2020-05-12 16:03:35 +02:00
kamilritz
70d65ea55f Test:Increase GPS jump need for rejection 2020-04-25 10:11:01 +02:00
Kamil Ritz
c19f40e574 Add reset position test for GPS and VISION 2020-04-25 10:11:01 +02:00
Kamil Ritz
78a6b9f7a8 SensorSimulator: Fix GPS horizontal position step 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
Kamil Ritz
adacca099d test recording of velocity reset 2020-04-19 12:43:37 +02:00
kamilritz
6f383248ca update change indication 2020-04-13 20:34:41 +02:00
Kamil Ritz
a013bb9314 Add test for gps projection & reprojections 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
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
bresch
975afa6560 EKF: update csv for change indicator 2020-03-09 19:10:07 +01: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
Kamil Ritz
7c179b39b8 Make test with Clang 2020-03-03 11:23:45 +01:00
Julian Kent
c6d5a74685 Update change indicator 2020-02-12 22:34:44 +01:00
bresch
05d391c785 Update test csv after functional fix 2020-02-12 22:03:22 +01:00