[Fix] Compute Kalman gain in update_iterated_dyn_share_diagonal when n > dof_Measurement #29
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses a critical issue in the update_iterated_dyn_share_diagonal function of esekfom.hpp.
When the number of state dimensions (n) exceeds the measurement dimension (dof_Measurement), the
Kalman gain computation was disabled (the intended code was commented out). As a result, in scenarios
with very few measurements, the filter update was performed incorrectly, leading to divergence.
Changes
Original Code:
The code in the if(n > dof_Measurement) branch originally only created an h_x_cur matrix by copying h_x_
into the top-left corner:
Modified Code:
The fix extends the available measurement Jacobian to a full measurement Jacobian (H_full)
by padding with zeros. Additionally, both operands in the addition are converted to dense matrices,
which is necessary because Eigen's lazy-evaluated product expressions and DiagonalWrapper do not
support operator+ directly. The updated code is as follows:
This ensures that the operands of the addition are both dense matrices, resolving the operator+
error and enabling a valid Kalman gain computation even when measurements are few.
Testing
computed correctly, and the filter update behaves as expected without divergence.
Notes
Using .eval() and .toDenseMatrix() forces the lazy Eigen expressions to be evaluated into standard dense
matrices. This conversion is necessary because the DiagonalWrapper (returned by dyn_share.R.asDiagonal())
cannot be directly added to an unevaluated product expression. This change ensures numerical consistency
and proper filter updates even in low-measurement cases.