rpng / open_vins

An open source platform for visual-inertial navigation research.
https://docs.openvins.com
GNU General Public License v3.0
2.06k stars 616 forks source link

How to deal with the case where the diagonal elements of the covariance matrix are negative? #324

Closed ghost closed 1 year ago

ghost commented 1 year ago

Hello, I made a small change to the code:

1: In StateHelper::EKFUpdate() function the matrix operation related to the covariance matrix, use the float data type instead of the double type.

Exception result:

  1. The diagonal elements of the covariance matrix have negative values.

Questions: 1: Why the diagonal elements of covariance matrix have negative values? 2: Is there any way to avoid the situation where the diagonal elements in the covariance matrix is negative? 3: If the diagonal elements in the conference matrix have negative values, is there any better way to deal with it? The current solution is to exist the program directly.

Thanks a lot for your time.

goldbattle commented 1 year ago

Using a float data type reduces the numerical precision that the filter can handle. I recommend reading some literature / searching for methods which have run Kalman filters on embedded devices or space applications.

Likely negatives mean that there was a poor conditioned update, or the measurement model is incorrect. It is hard to address this problem. One simple method is to "undo" the update, and just drop the measurements if they cause a invalid covariance, but this is clearly not ideal.

Remember that the covariance should be a semi positive definite matrix to be a gaussian. https://en.wikipedia.org/wiki/Definite_matrix

ghost commented 1 year ago

Thank you for your timely response. We also noticed the following phenomena while trying:

  1. When we use the latest version of OpenVINS with double precision, the case that the main diagonal is negative also occurs.
  2. Another strange phenomenon is that with some data it is possible to use double OK, but the main diagonal is negative with float. For some data it is the other way around. Have you ever been in a similar situation? What are the possible reasons for it?

Thank you for your time.

goldbattle commented 1 year ago

Do you have a dataset where this problem occurs? Likely this means your sensors are not properly calibrated, the noises are not correct, or the chi2 allowed an outlier / bad measurement to be in the update.

HoEmpire commented 1 year ago

You might also try to play around with the initial prior. Sometimes a bad initial prior can easily lead to negative diagonals.

ghost commented 1 year ago

Thank you for your prompt reply. 1、Such a problem occurred in our own collection of data sets 2、We will take a closer look at the sensor calibration procedure. 3、Try adjusting the chi2 threshold. Thanks again.

ghost commented 1 year ago

You might also try to play around with the initial prior. Sometimes a bad initial prior can easily lead to negative diagonals.

Thank you for your reminder. We will go and confirm whether there is a problem with the initial prior.