-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ekf2: use Joseph covariance update #22770
Conversation
As discussed one big piece to understand here is how much we can actually afford. Then potentially one option could be doing this switch automatically if the Kalman gains are modified substantially (by clearInhibitedStateKalmanGains(K)). |
09fe932
to
5b23532
Compare
edit: I found a much faster implementation. Now the CPU increase is ~1%, which is totally acceptable given the gains in numerical stability and code cleanness. |
fc68cfc
to
953e5c7
Compare
0efdbcd
to
0b7a47c
Compare
@dagar I squashed the relevant commits together and rebased on main. Good to go on my side. |
Solved Problem
The conventional covariance update (
P = P - KHP
orP = P - KSK'
) is only correct when an optimal Kalman gain is used. EKF2 is closer to a Schmidt-Kalman filter as it "manually" clears part of the Kalman gain when states are poorly observable or when affecting a certain state can harm the estimate. For example, airspeed fusion is only allowed to affect the wind states when another velocity/position aiding source is active. Using the conventional update can be dangerous in that case as the covariances are not updated anymore while the state variance decreases; artificially increasing the correlation between the states.Solution
Use the famous Joseph stabilized covariance update as this equation is correct with any Kalman gain (not only the optimal one). Another benefit is that this equation is numerically more stable. The implementation ensures to have a symmetrical matrix as only the upper triangular matrix is computed and copied to the lower part.
The CPU increase is about 1%, which is IMO acceptable given the benefits of this equation.
Changelog Entry
For release notes:
Alternatives
Clear the covariance of a state when the Kalman gain has been modified significantly.