Get NavEKF2 covariance elements, and/or re-run NavEKF2?

I would like uncertainty information for the wind estimate which is produced by the NavEKF2 filter and saved in the .bin log. Based on my understanding of EKFs, this is the time-history of the 2 diagonal elements of the EKF covariance matrix P corresponding to states VWN and VWE. (I think they would be the 23rd and 24th elements of P’s diagonal.)

I’m looking through the AP_NavEKF2 code, and I don’t see any methods which access this information. Do any exist?

If not, and my understanding is correct that the diagonal elements of P contain the wind-estimate variance, is there any way to “re-simulate” the EKF code by drawing information from a dataflash log? (I hope then, if I can re-run, I can obtain an exact copy of the info I’m seeking.)

ArduCopter code does not (yet) do wind estimation. those two elements are not used in the code at all.

Ah, yes, I should have specified: I’m working with ArduPlane. (Specifically Plane 3.8 I think… I could look it up if it’s important.)

I think @priseborough might know the answer to this, who else does dev work on the NavEKF2? Please feel free to tag someone who might know, as I’m not sure who watches this forum!

No input re your specific question, but Replay might be useful for you.

1 Like

Thanks @james_pattison for the recommendation. I was able to run Replay on my log with no errors, but the output has NKF2.VWN set to all zeros. I don’t know why… but most importantly, I don’t know what the Replay tool actually does. (and doesn’t do)

Based on my present understanding, there is no record of the EKF’s internal covariance information during flight. To get it, I need to create a version of the ArduPlane firmware which logs the covariance information that I seek, and then “replay” my .bin logfile through that new firmware version in order to extract the covariance info. Can anyone comment on whether this is a “good” or “bad” thing to attempt?

Adding some debug code to log the innovations should be fine but to be frank this one is beyond me.

Hi @hunt0r,
You’ll need to add additional logging information to do this. There is a function getVariances() on NavEKF2 which provides some variances, but only for the velocity, position, magnetic field and airspeed. These are logged in the NKF4 packet.
You’ll need to extend getVariances() to allow access to the wind_vel variances, then add those to the logging.
Cheers, Tridge

1 Like

Have you looked through the NKF* messages in the dataflash logs?

@peterbarker Yes, I looked through all of them. Did I miss something?

At the moment there is no way to access the covariance matrix elements corresponding to the wind states. An accessor function could be added to provide this. The variances currently provided by the getVariances() function are normalised innovation levels from the innovation consistency tests and not the covariance information the OP is looking for.

1 Like

Based on what I learned here, I’m going to investigate adding my desired covariance-logging and then using the Replay tool to extract the info I’m seeking. This seems to be a good solution, so I’ll mark this question as resolved.

As for learning the Replay tool, I am planning to just source-dive… which can be a time-consuming process. If anyone has documentation about Replay (or would be willing to answer a few quick questions) please contact me.

Thank you very much to all who responded!

No documentation, but feel free to drop questions in here.