Skip to content
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

Fix CombinedImuFactor #882

Merged
merged 13 commits into from
Jul 5, 2022
Merged

Fix CombinedImuFactor #882

merged 13 commits into from
Jul 5, 2022

Conversation

varunagrawal
Copy link
Collaborator

@varunagrawal varunagrawal commented Sep 28, 2021

This PR updates the CombinedImuFactor to compute the preintegration covariance as per the updated ImuFactor.pdf document.

@lucacarlone
Copy link
Contributor

@varunagrawal : how is it going on this? I'm happy to help if you want!

@varunagrawal
Copy link
Collaborator Author

I've actually figured this out but we're in the middle of a submission cycle, so I'll get back to this in a week. :)

@lucacarlone
Copy link
Contributor

yay! great to hear!

@varunagrawal varunagrawal self-assigned this May 5, 2022
@varunagrawal varunagrawal marked this pull request as ready for review May 5, 2022 15:36
@varunagrawal
Copy link
Collaborator Author

@lucacarlone I am requesting a review from you and I hope you will be the primary person for discussion to get this fix merged in.

I have updated the ImuFactor.lyx doc to demonstrate the math for the covariance propagation, and have made the necessary code updates based on that.

@dellaert
Copy link
Member

dellaert commented May 5, 2022

@varunagrawal could you give some more context and summary of changes in the PR comment so @lucacarlone could sanity-check this? I'll also be happy to take a look. Also, consider pasting the relevant change from the PDF in the comments so this is easy to review without having to checkout the pdf.

@lucacarlone
Copy link
Contributor

@varunagrawal @dellaert : I'm happy to review this!

@varunagrawal
Copy link
Collaborator Author

@dellaert @lucacarlone here are the relevant sections. The code should match the math. If something is unclear or the if there are better naming recommendations, I am happy to oblige.

IMUFactor1

IMUFactor2

IMUFactor3

Copy link
Member

@dellaert dellaert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are now changes in 808 files. Did you change the base? Reason it's not develop?

@dellaert
Copy link
Member

dellaert commented May 5, 2022

Also. just pasting those sections does not make clear what changed. Please help us by providing that and the reason for the change..

@varunagrawal
Copy link
Collaborator Author

The main idea is that I re-derived the covariance update equations for the CombinedImuFactor using the details in ImuFactor.lyx as well as the notes that @lucacarlone provided to me. I clarified a lot of the error terms and by writing it up in ImuFactor.lyx I was able to identify missing/poorly-named covariance blocks and rectify them.

@varunagrawal
Copy link
Collaborator Author

There are now changes in 808 files. Did you change the base? Reason it's not develop?

Sorry about that. Had to merge in develop across multiple branches. This PR does not target develop since the main fix for #368 is in #874 but when fixing that, we identified some issues in the covariance propagation of the CombinedImuFactor and this PR isolates that.

@varunagrawal varunagrawal requested a review from dellaert May 5, 2022 20:57
@varunagrawal
Copy link
Collaborator Author

I would argue that this PR and #879 should be looked at together (this PR targets #879) but I kept it separate for ease of reviewing.

@@ -123,7 +123,7 @@ boost::shared_ptr<PreintegratedCombinedMeasurements::Params> imuParams() {
// PreintegrationCombinedMeasurements params:
p->biasAccCovariance = bias_acc_cov; // acc bias in continuous
p->biasOmegaCovariance = bias_omega_cov; // gyro bias in continuous
p->biasAccOmegaInt = bias_acc_omega_int;
p->biasAccOmegaInit = bias_acc_omega_init;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming breaks API and I really think it was meant to be "int" for "integration"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, we have integrationCovariance in PreintegrationParams.h for integration. This was a typo that I fixed.

@@ -94,7 +94,7 @@ boost::shared_ptr<PreintegratedCombinedMeasurements::Params> imuParams() {
I_3x3 * 1e-8; // error committed in integrating position from velocities
Matrix33 bias_acc_cov = I_3x3 * pow(accel_bias_rw_sigma, 2);
Matrix33 bias_omega_cov = I_3x3 * pow(gyro_bias_rw_sigma, 2);
Matrix66 bias_acc_omega_int =
Matrix66 bias_acc_omega_init =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@@ -39,7 +39,7 @@ void PreintegrationCombinedParams::print(const string& s) const {
<< endl;
cout << "biasOmegaCovariance:\n[\n" << biasOmegaCovariance << "\n]"
<< endl;
cout << "biasAccOmegaInt:\n[\n" << biasAccOmegaInt << "\n]"
cout << "biasAccOmegaInit:\n[\n" << biasAccOmegaInit << "\n]"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@@ -62,19 +62,19 @@ typedef ManifoldPreintegration PreintegrationType;
struct GTSAM_EXPORT PreintegrationCombinedParams : PreintegrationParams {
Matrix3 biasAccCovariance; ///< continuous-time "Covariance" describing accelerometer bias random walk
Matrix3 biasOmegaCovariance; ///< continuous-time "Covariance" describing gyroscope bias random walk
Matrix6 biasAccOmegaInt; ///< covariance of bias used for pre-integration
Matrix6 biasAccOmegaInit; ///< covariance of bias used as initial estimate.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

etc...

@@ -145,7 +145,8 @@ Eigen::Matrix<double, 15, 15> CombinedScenarioRunner::estimateCovariance(
auto pim = integrate(T, estimatedBias, true);
NavState sampled = predict(pim);
Vector15 xi = Vector15::Zero();
xi << sampled.localCoordinates(prediction), estimatedBias_.vector();
xi << sampled.localCoordinates(prediction),
(estimatedBias_.vector() - estimatedBias.vector());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the only real change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this PR? CombinedImuFactor.cpp has the main changes.

Copy link
Member

@dellaert dellaert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are making a math change - in future make this as atomic as possible. Lot's of distractions that make this hard to review.

D_R_R(&G_measCov_Gt) = theta_H_biasOmega //
* (wCov_updated / dt) //
* (theta_H_biasOmega.transpose());
D_v_v(&G_measCov_Gt) =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you restore the order in which these terms are computed for easier review, and comment on what has changed and why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This order would be more aligned with the math and should make verifying it easier.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm saying it's harder for review. It's also not arbitrary. Maybe re-arrange the math. The order of Navstate is "attitude", "position", "velocity".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused. It's already in attitude-position-velocity order (D_R_R for attitude, D_t_t for position and D_v_v fro velocity). The prior code had it position-velocity-attitude which isn't the expected order.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@varunagrawal : besides the order of the pre-integrated measurements, can you point out what changed with respect to my (terrible) writeup? I think you added a second-order term in the position and changed how the covariances are discretized. were there other bugs you fixed with respect to my writeup? (i.e., was my writeup wrong, or only the implementation? or both? :-) )

also: is the order attitude-position-velocity now also used in the standard IMU factor? or only the combined?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe just the implementation was incorrect in certain places. @lucacarlone's overall writeup was pretty great and I just expanded upon that with additional information I picked up from other books and papers. :)
It's been a while since I've seen this math though so I may have added minor corrections where I found them which I don't remember of the top of my head.

As for the attitude-position-velocity order, this was not really an issue for ImuFactor since the expression for the jacobians was a lot simpler (G * C/dt * G')

Copy link
Collaborator Author

@varunagrawal varunagrawal Jul 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at the differences again: I also changed the noise variable order from
$$\epsilon_{int}, \epsilon_{a}, \epsilon_{\omega}, \epsilon_{b^{a}_{init}} $$

$$\epsilon_{b^{\omega}{init}}, \epsilon{\Delta b^{a}}, \epsilon_{\Delta b^{\omega}}$$

to
$$\epsilon_{\omega}, \epsilon_{a}, \epsilon_{\Delta b^{a}}, \epsilon_{\Delta b^{\omega}}$$

$$\epsilon_{int}, \epsilon_{b^{a}{init}}, \epsilon{b^{\omega}_{init}}$$

(Apologies for the rendering issues. Seems like Github's Math mode is a bit buggy.)

D_v_t(&G_measCov_Gt) = vel_H_biasAcc * (aCov / dt) * pos_H_biasAcc.transpose();
D_R_v(&G_measCov_Gt) = temp.transpose();
D_t_v(&G_measCov_Gt) = pos_H_biasAcc * (aCov / dt) * vel_H_biasAcc.transpose();
D_R_t(&G_measCov_Gt) =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same. And why get rid of temp?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got rid of temp because the derivation is no longer D_v_R = temp and D_R_v = temp.transpose().

Copy link
Contributor

@lucacarlone lucacarlone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@varunagrawal : I'm starting to review the PR - great job overall! I plan to add comments as I go, starting from the writeup

@lucacarlone lucacarlone self-requested a review July 2, 2022 16:30
Copy link
Contributor

@lucacarlone lucacarlone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me overall - thanks for the great work @varunagrawal !! It would be amazing to have a numerical analysis / example showing that this leads to better results (or at least better bias estimates).

\begin_inset Formula $\zeta_{k}=[\theta_{k},p_{k},v_{k}]$
\end_inset

and rewrite Eqns.
, as a 9D vector on tangent space at and rewrite Eqns.
(
\begin_inset CommandInset ref
LatexCommand ref
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

near eq (17) it is worth remarking these are discrete-time covariances (and point to the section on covariance discretization)


The noise model associated with this factor is assumed to be zero-mean Gaussian
with a
\begin_inset Formula $9\times9$
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slightly confusing, since it is 15x15 in the combined factor. I would rephrase this sentence to keep it more general.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, though Frank wanted this to be specific since we have different sections for ImuFactor and CombinedFactor. I'll add a corresponding paragraph in the Combined IMU Factor subsection.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!


.
This covariance matrix is computed in the preintegrated measurement class,
of which there are two variants as discussed above.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here I suggest making the terminology clearer: are these continuous-time densities/covariances or discrete-time covariances?


: The covariance associated with the gyroscope bias random walk.
\end_layout

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

below the reference "Murray84book" does not render correctly

D_R_R(&G_measCov_Gt) = theta_H_biasOmega //
* (wCov_updated / dt) //
* (theta_H_biasOmega.transpose());
D_v_v(&G_measCov_Gt) =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@varunagrawal : besides the order of the pre-integrated measurements, can you point out what changed with respect to my (terrible) writeup? I think you added a second-order term in the position and changed how the covariances are discretized. were there other bugs you fixed with respect to my writeup? (i.e., was my writeup wrong, or only the implementation? or both? :-) )

also: is the order attitude-position-velocity now also used in the standard IMU factor? or only the combined?

@@ -76,7 +76,7 @@ TEST(TestImuPreintegration, LoadedSimulationData) {
imuPreintegratedParams->gyroscopeCovariance = I_3x3 * pow(gyrNoiseSigma, 2);
imuPreintegratedParams->biasOmegaCovariance = I_3x3 * pow(gyrBiasRwSigma, 2);
imuPreintegratedParams->integrationCovariance = I_3x3 * integrationCovariance;
imuPreintegratedParams->biasAccOmegaInt = I_6x6 * biasAccOmegaInt;
imuPreintegratedParams->biasAccOmegaInit = I_6x6 * biasAccOmegaInit;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not there yet, I suggest adding a unit test on the block-wise implementation of G * cov * G'

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will have to be an MCMC test similar to ImuFactor.

@varunagrawal varunagrawal added the bugfix Fixes an issue or bug label Jul 4, 2022
Copy link
Contributor

@lucacarlone lucacarlone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@varunagrawal : this is good to go to me, but do you have stats to show how it compares with the standard imu factor?

@varunagrawal
Copy link
Collaborator Author

@lucacarlone that is going to have to be another PR since I will need to implement the CombinedImuFactor equivalent of the ScenarioRunner. I can and will do that but I am keen to land this PR. I'll create an issue for it so we can track it.

@varunagrawal varunagrawal merged commit 4244345 into fix/combined-imu-cov Jul 5, 2022
@varunagrawal varunagrawal deleted the fix/combined-imu branch July 5, 2022 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Fixes an issue or bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Details about IMU Integration Covariance
3 participants