Skip to content

EKF3: Covariance stability improvement - #18008

Merged
tridge merged 30 commits into
ArduPilot:masterfrom
priseborough:pr-ekfCovariancePrediction
Jul 22, 2021
Merged

EKF3: Covariance stability improvement#18008
tridge merged 30 commits into
ArduPilot:masterfrom
priseborough:pr-ekfCovariancePrediction

Conversation

@priseborough

@priseborough priseborough commented Jul 12, 2021

Copy link
Copy Markdown
Contributor

This PR eliminated the incorrect state variances that a user encountered during a fixed wing flight without a magnetometer that resulted in multiple height and vertical velocity variance resets when that log was replayed using single precision. Replaying the log using master with double precision also eliminated the issue.

The symptons are a collapse of the vertical velocity and position variances and a resulting failure of the EKF to correct vertical velocity and position to the sensor values.

Although default use of EKF3 is new to the ArduPilot community, PX4 have been using the same mathematics in their ekf2 module estimator since 2016 and collapse of variances associated with the vertical velocity and Z axis delta velocity bias have been detected in a small number of logs with a number of mitigations introduced over the years. This potential fix to the mathematics was uncovered by Mathieu Bresciani during investigation of one such occurrence.

Whilst replay and SITL testing indicate a benefit, wider flight testing with LOG_DISARMED=1 and LOG_REPLAY=1 is required.

Here are the vertical position innovations for the original and replay using master with the --ekf-single processing option:

master - single

Here they are with replay using master with the default double precision processing - the behaviour is eliminated:

master - double

Here they are with replay using this PR with the --ekf-single precessing option:

derivation-single

If we look more closely at the original and replayed state variances for the original and replayed log using this PR with --ekf-single, we can see how the state variances for the vertical velocity (index 6) and position (index 9) collapse for the original log:

Screen Shot 2021-07-13 at 8 19 35 am

The current hypothesis for why this minor change to the prediction equations in the derivation improve stability is that it eliminates the presence of the qx quaternion in the rotation matrix x,x, qy in the y,y and qz in the z,z diagonals. Given that qx, qy and qz represent the cosines of a rotation vector along their respective axes, this intuitively makes sense. A rotation about Z for example should not change the projection of the Z earth axis along the Z body axis.

Even though the old and new equations are mathematically identical for a unit length quaternion, when the partial derivatives for the state transition matrix are calculated and used in the covariance prediction equation, the old equations may be resulting in higher order terms that lead to accumulation of unwanted numerical errors when single precision processing is used.

@priseborough

Copy link
Copy Markdown
Contributor Author

This is a candidate for backport to 4.1 beta

@priseborough
priseborough requested a review from tridge July 12, 2021 22:34
@tridge

tridge commented Jul 12, 2021

Copy link
Copy Markdown
Contributor

@giacomo892 we'd appreciate you testing this on your Dart, thanks!

@priseborough

Copy link
Copy Markdown
Contributor Author

Checking the GPS velocity innovations from the log shows that on replay the patch does reduce the size of the innovations when the vehicle switches to RTL, performs a turn and the yaw error becomes observable, eg:

image

@priseborough

Copy link
Copy Markdown
Contributor Author

@tridge the CI build is failing due to frame size on the lowest spec boards. Is there a way to work around that?

@priseborough

priseborough commented Jul 13, 2021

Copy link
Copy Markdown
Contributor Author

I've pushed a commit that fixes a logic bug that was preventing the XY accel biases being learned in flight unless there were large roll or pitch changes:

Original log shows no change in XY IMU accel bias (m/s/s)
Screen Shot 2021-07-13 at 9 51 23 pm

Replayed log using this PR:
Screen Shot 2021-07-13 at 9 51 40 pm

The gyro bias process noise reduction for EK3_GBIAS_P_NSE from 0.001 to 0.0001 has improved the gyro bias learning:

Original log shows learned gyro bias (deg/sec) is noisy
Screen Shot 2021-07-13 at 9 50 24 pm

Replayed using this PR shows much smoother bias esitmates:
Screen Shot 2021-07-13 at 9 50 36 pm

@tridge

tridge commented Jul 14, 2021

Copy link
Copy Markdown
Contributor

@priseborough I've run the failing test.Copter.PrecisionLoiterCompanion test with replay, and get this:
image
image
the replay log built with master is here:
http://uav.tridgell.net/EKF/3-precloiter-replay.bin

@tridge

tridge commented Jul 14, 2021

Copy link
Copy Markdown
Contributor

new formulation matches SIM2 state more closely for PN and PE:
image
image
a bit worse for PD. PD is a surprisingly long way from the sim state:
image

@tridge

tridge commented Jul 14, 2021

Copy link
Copy Markdown
Contributor

VN and VE are improved (lane 0 is master, lane 100 is this PR):
image
image
VD goes both ways:
image

@priseborough

Copy link
Copy Markdown
Contributor Author

a bit worse for PD. PD is a surprisingly long way from the sim state:

It's actually tracking baro alt better than before see:

image

The error is in the simulated baro alt sensor:
image

@priseborough
priseborough force-pushed the pr-ekfCovariancePrediction branch from 9888930 to e11a2c6 Compare July 15, 2021 04:51
@priseborough

Copy link
Copy Markdown
Contributor Author

Overview of single precision replay logs with updated tune at commit e11a2c6

The new tune gives equivalent to silightly better tracking of GPS velociities (lower innovations) so the weighting of IMU vs GPS is approximately the same:
image

Bias esitimates estimates are smooth but do respond to changes in offfset when IMU temperature changes:

image

image

image

@priseborough

Copy link
Copy Markdown
Contributor Author

The PrecisionLoiterCompanion test was failing due to a tight tolerance of 0.1m radially in the final position. Inspection of the log shows that this is due to a bias in the horizontal velocity innovation of 6 cm/s at the end of flight that offsets the position controller by 6 cm in esch axis.

image

Retuning the filter to handle a faster changing gyro bias (EK3_GBIAS_P_NSE 0.0001 -> 0.001) reduced this to 1 cm/s and the corresponding position controller offset to 1cm in each axis

image

However this gave a noisy gyro bias esitmate on replay of real flight logs, so a compromise tuning of 0.0003 will be adopted.

@giacomo892

giacomo892 commented Jul 15, 2021

Copy link
Copy Markdown
Contributor

Replayed a log I had from another plane using MPU6000 (Omnibus F4 Pro) on which I had similar issues with EK3, and guess what:
image

Also gyro/acc biases looks much better:
image
image
image
image

Dramatic improvements for down and east innovations:
image

@tridge

tridge commented Jul 15, 2021

Copy link
Copy Markdown
Contributor

@priseborough

Copy link
Copy Markdown
Contributor Author

The autotests failing currently are:

  1. Plane.FlyEachFrame where after landing, the autotester does not get the 'throttle disarmed' text it is looking for. The log shows that the vehicle does disarm.

  2. Copter.VibrationFailsafe where the changed filter tuning appears to have reduced the effectiveness of the current vibration compensation settings. These will need to be re-tuned.

@priseborough

priseborough commented Jul 16, 2021

Copy link
Copy Markdown
Contributor Author

I'm still working on getting the Copter vibration failsafe working again. Changes made in the process are being pushed to https://github.com/priseborough/ardupilot/tree/pr-ekfCovariancePrediction-wip

@rmackay9 I would be grateful for some assistance with this. The current stats when running

'./Tools/autotest/autotest.py --no-clean --replay build.Copter test.CopterTests1c.VibrationFailsafe'

is that the "Vibration compensation ON" message is received, but it doesn't go into land mode.

@rmackay9

rmackay9 commented Jul 16, 2021

Copy link
Copy Markdown
Contributor

@priseborough,

OK, the issue then is that the EKF is not losing its horizontal or vertical position estimate so the EKF failsafe isn't triggering. The purpose of this test is not actually to test the EKF failsafe so I can imagine two changes that would resolve the failing test:

  1. increase the vibration levels even higher so that it does lose its position fix
  2. we could modify the test so that it ensure the vehicle altitude stays within some range (using real numbers, not EKF numbers).

The 2nd choice is probably the better one.

I wrote the test so perhaps I should fix it..

@priseborough
priseborough force-pushed the pr-ekfCovariancePrediction branch from c9b191a to 903e4fc Compare July 16, 2021 23:35
@tridge

tridge commented Jul 17, 2021

Copy link
Copy Markdown
Contributor

@priseborough please also note this PR:
#18032

@priseborough

Copy link
Copy Markdown
Contributor Author

The wind estimation when not using an airspeed sensor has been modified and the process noise and initial uncertainty retuned to give a better result for the Plane test.Plane.DeadreckoningNoAirSpeed test with equivalent wind estimation for the two estimators:

Screen Shot 2021-07-17 at 4 58 06 pm

A number of factors were contributing to the poor EKF3 wind estimation performance in the test.Plane.DeadreckoningNoAirSpeed test:

  1. Fusion of the default airspeed in EKF3 that is a average of ARSPD_ASPD_MAX and ARSPD_ASPD_MIN combined with a TRIM_THROTTLE that was too high caused the plane to exceed ARSPD_ASPD_MAX which degraded the airspeed estimate between turns.

  2. EKF started wind speed estimation earlier in flight, whereas EKF2 started much later after the turn in guided mode had already started which gave EKF2 a better initialisation of the wind states. However this means the estimated airspeed derived from the EKF2 will be unavailable until then.

  3. The process noise on for the wind states on EKF3 require larger values due to the revised covariance prediction.

  4. The wind estimation for the no airspeed behaviour was tuned originally for hand launches with an into wind throw assumption whereas the test is for a downwind runway takeoff.

The wind estimation for a real flight log with airspeed sensor has also been checked on replay to check that we get acceptable state noise:

Screen Shot 2021-07-17 at 4 52 36 pm

@priseborough
priseborough force-pushed the pr-ekfCovariancePrediction branch from f8359f2 to f87ae35 Compare July 22, 2021 03:22
@priseborough

Copy link
Copy Markdown
Contributor Author

Conflict fixed and rebased on master.

The tuning param changes to the IMU noise, biases and wind velocity states have been reverted. This gives noisier state estimates, but is required until the EKF can discriminate between boards using the following information:

  • Lower sampling rate IMU's that are more susceptible to vibration.
  • Only one sensor so there is no backup IMU and EKF to fall back on if the IMU develops a rapid bias change.
  • The IMU's are temeprature calibrated so the likelihood of a rapdi change is bias is reduced.

priseborough and others added 17 commits July 22, 2021 13:43
This makes state corrections from GPS and baro observations more aggressive
Faster wind estimation when not using airspeed with acceptable noise in wind velocity estimates.
this fusion can cause problems with wind estimation, disable by
default for now
These are not required due to use of bit 7 in FLIGHT_OPTIONS to achieve the same function.
Also re-tunes process noise default for smoother wind velocity state estimates.
These give noisier state estimates, but are more robust to rapid changes in IMU biases.
TODO implement a means of using the modified parameters when there are more than one EKF instance running with IMU's that are sampling at a higher rate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants