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

Constant Velocity Constraint between NavStates #701

Merged
merged 13 commits into from
Mar 11, 2021

Conversation

asa
Copy link
Contributor

@asa asa commented Feb 24, 2021

Here is a first pass at a Constant Velocity Constraint between two NavStates.

It is much cribbed from the VelocityConstraint in gtsam_unstable/dynamics. Hopefully along the way we can improve this to be usable in external state tracking problems.

I am using almost always auto style here, let me know if that is discouraged, or how else I can tailor this back to being more in line with the rest of the library.

@asa asa marked this pull request as draft February 24, 2021 02:17
@asa asa marked this pull request as ready for review February 24, 2021 03:37
@dellaert
Copy link
Member

auto is great. Taking a look now.

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.

I gave some hints on how to use localCoordinates.
Maybe mark PR as Draft for now so people know,

gtsam/navigation/tests/testConstantVelocityFactor.cpp Outdated Show resolved Hide resolved
gtsam/navigation/ConstantVelocityFactor.h Show resolved Hide resolved
gtsam/navigation/ConstantVelocityFactor.h Show resolved Hide resolved
gtsam/navigation/ConstantVelocityFactor.h Show resolved Hide resolved
};

if (H1) {
(*H1) = numericalDerivative21<gtsam::Vector, NavState, NavState>(evaluateErrorInner, x1, x2, 1e-5);
Copy link
Member

Choose a reason for hiding this comment

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

I think what is needed here is a call to

Vector9 NavState::localCoordinates(const NavState& g, OptionalJacobian<9, 9> H1, OptionalJacobian<9, 9> H2) const {

where you evaluate the difference between predicted and x2, as in:

NavState predicted = (something that yields predicted_H_x1)
Vector9 error = predicted.localCoordinates(x2, error_H_predicted, H2);
if (H1) *H1 = error_H_predicted * predicted_H_x1;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any reason I can't just leverage the navstate.update(body_accel,body_omega, dt) function here to get my predicted NavState? I will want to use those terms later (and build out a NavState++ that can store those states as well) so this would get me closer to that final goal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I took a pass at this style. Seems to behave, but let me know if I missunderstood something. Obviously I need to test the rotation cases and find a cleaner way to init a Vector9 to clean up the verbosity of the tests.

@dellaert
Copy link
Member

BTW Matias from Oxford just posted three amazing posts on https://gtsam.org/blog/ that can help with manifold concepts. Esp. part 2.

@asa asa marked this pull request as draft February 25, 2021 13:50
@asa
Copy link
Contributor Author

asa commented Feb 26, 2021

BTW Matias from Oxford just posted three amazing posts on https://gtsam.org/blog/ that can help with manifold concepts. Esp. part 2.
Very nice posts! Thanks for the hint!

@asa
Copy link
Contributor Author

asa commented Feb 26, 2021

I also noticed while looking at NavState::localCoordinates() in detail that dt is used where perhaps dP is meant? Using dP would match the notation used in NavState::dP() static function. This use of dt is of course confusing in the context of the work in this PR.

@dellaert
Copy link
Member

Yes, feel free to change to dP, and dv to dV.

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.

Saw your changes, some quick comments.
Let me know when ready for re-review.

gtsam/navigation/ConstantVelocityFactor.h Outdated Show resolved Hide resolved
gtsam/navigation/ConstantVelocityFactor.h Outdated Show resolved Hide resolved
gtsam/navigation/tests/testConstantVelocityFactor.cpp Outdated Show resolved Hide resolved
@asa
Copy link
Contributor Author

asa commented Feb 26, 2021

Yes, feel free to change to dP, and dv to dV.

fixed.

@dellaert
Copy link
Member

dellaert commented Mar 9, 2021

Sorry, got busy with IROS. Is this still WIP or ready for re-review?

@asa
Copy link
Contributor Author

asa commented Mar 9, 2021

Sorry, got busy with IROS. Is this still WIP or ready for re-review?

Yes please. More extensions can come in a later pr.

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.

Awesome. Two small comments that will save some CPU...

NavState predicted = x1.update(b_accel, b_omega, dt_, predicted_H_x1, {}, {});

Matrix error_H_predicted;
Vector9 error = predicted.localCoordinates(x2, error_H_predicted, H2);
Copy link
Member

Choose a reason for hiding this comment

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

Cool. But please use H1 ? &error_H_predicted : nullptr to avoid evaluation of derivative if H1 is not asked for.

static const Vector3 b_omega{0.0, 0.0, 0.0};

Matrix predicted_H_x1;
NavState predicted = x1.update(b_accel, b_omega, dt_, predicted_H_x1, {}, {});
Copy link
Member

Choose a reason for hiding this comment

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

Cool. But please use H1 ? &predicted_H_x1 : nullptr to avoid evaluation of derivative if H1 is not asked for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't get this style to compile, so I went a little more verbose. Any thoughts on how to make this prettier would be appreciated, otherwise this accomplishes your request I believe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

error: no viable conversion from 'gtsam::Matrix *' (aka 'Matrix<double, Dynamic, Dynamic> *') to 'OptionalJacobian<9, 9>

Copy link
Member

Choose a reason for hiding this comment

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

Ah, yeah. This style should definitely compile, and I recommend you do use it. But the issue is you need a fixed size matrix. Which will also benefit performance, as it gets rid of a heap allocation. In example above:

Matrix99 predicted_H_x1;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh... got it. That compiles now. Should be done!

@dellaert dellaert marked this pull request as ready for review March 11, 2021 20:24
@dellaert dellaert merged commit a9f9d46 into borglab:develop Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants