EKF2 errors at startup

Hi Paul and Randy,
Regarding the problem we’re chasing with the EKF2 attitude going crazy at startup I think it may be related to the arming time.
If we take this log as an example:
with the replay PR#4043 applied this replays nicely and gives good attitude. The real arming time for that log is 26192ms.
If however I use --arm-time=19000 in replay to force EKF2 to see the board as armed at 19s then the attitude goes completely mad. This is despite it having plenty of time to settle and the IMU data being fine.
I suspect there is something wrong in AP_NavEKF2_Control.cpp. If I use --arm-time=20000 then its all fine and gives good attitude. It is getting IMT data from 11.7s, so it should have had plenty of time to settle before 19s.
The plane user that saw this issue had ARMING_REQUIRE=0, so the board started armed. I suspect that is the same issue.
Cheers, Tridge

here are the specific commands needed:
This command will give a crazy NKF1.Roll:
./Replay.elf – --logmatch --arm-time 19000 xracer250-20.bin
and this command will give correct NKF1.Roll
./Replay.elf – --logmatch --arm-time 19400 xracer250-20.bin
note that the vehicle is completely still in the period between 19000 and 19400ms, yet EKF2 sees arming in that time as causing major errors.

the --logmatch option is a new replay option btw. It causes replay to log EKF output at the same rate as the input log. That makes it easier to compare input and output, plus produces much smaller output logs which are easier to analyse.


I don’t know if it is linked but I also got altitude problem at takeoff.
In guided mode, when I use mavlink commande takeoff to 2m. The copter takeoff but stay under 2m… (sometime even under 1m) but it reports 1.8m altitude… then if I send to go up, it seems to regain good alt.
If I use takeoff to 4m, the copter really goes to 4m and everything is find.

The problem is present even with ultrasound range finder.
I can provide multiple log and video if need !

@khancyr, no, that is unrelated to what we are discussing

here is another smoking gun log from Keeyen on plane:
in this case it starts up outside and has good attitude. Then he brings it inside and puts it down. The EKF2 attitude goes crazy. Replay reproduces the craziness exactly.
./Replay.elf – --logmatch keeyen-armreq1.bin

Keeyens unsteady horizon reference appears to be due to an excessive sensitivity to GPS noise in that operating mode. This is mostly a tuning/parameter scaling problem but it is exacerbated by the fact that the GPS reported position accuracy is not being used to scale the filter parameters. I have been able to bring it down through reductions to process noise along with some minor code changes but now need to check that these changes do not introduce excessive sensitivity to IMU errors and sustained high yaw rates.

This is a short term fix as Jon Challinger and I have some accuracy and robustness enhancements in development that will provide a solution with fewer compromises. As always, robustness of the attitude solution in-flight will be the highest tuning priority

I have started an interim prototype tuning and GPS handling update here : https://github.com/priseborough/ardupilot/tree/ekf2-wip that reduces sensitivity to GPS noise. This is a minimum change interim solution until the major updates arrive in the next few weeks.

I have a preliminary set of parameters for plane, but need both plane and copter replay logs from current master with replay logging enabled to complete tuning. The preliminary tune makes the attitude much less sensitive to GPS noise, but until I get some plane tuning logs with noisy IMU data and aerobatic flight including spins, will not know if the tuning has been pushed too far and may need to back the parameter changes off somewhat. When comparing EKF1 and EKF2 remember that EKF2 starts using GPS on the ground as soon as it passes checks, whereas EKF1 only uses GPS after the vehicle is armed.

I have been working through the issues and now have some updates that will help address what I understand to be the two main issues - loss of covariance matrix conditioning and sensitivity to GPS noise.

This has been tuned using plane logs and also tested on SILT replay, however I need some copter replay logs to complete the re-tune and validation.

Instructions on getting good replay logs are here:
please post links to your logs to this topic!

I’m experiencing even worse stuff after startup when quad for example hits something and is subjected to a series of very sudden movements. EKF never recovers and requires a restart - which is horrible when quad is in the air because it means it’s going down. Not sure if it is related to this issue though, but my impression of the ekf right now is that it is very unpredictable.