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: UnaryFactor Jacobian #724

Merged
merged 3 commits into from
Apr 16, 2021
Merged

Conversation

nmahabadi
Copy link

  • Fix Unaryfactor jacobian in LocalizationExample.cpp.
  • Update gtsam document.

@nmahabadi
Copy link
Author

@dellaert @varunagrawal this is a new PR with the latest from "develop". Let me know if this seems fine.

@@ -8,7 +8,11 @@ class UnaryFactor: public NoiseModelFactor1<Pose2> {
Vector evaluateError(const Pose2& q,
boost::optional<Matrix&> H = boost::none) const
{
if (H) (*H) = (Matrix(2,3)<< 1.0,0.0,0.0, 0.0,1.0,0.0).finished();
const double cosTheta = cos(q.theta());
Copy link
Member

@dellaert dellaert Mar 23, 2021

Choose a reason for hiding this comment

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

Add comment, now that you figured it out :-) Also, GTSAM actually stores a Rot2 as sin and cos, so no need to re-compute. You can just use:

const Rot2& R = q.rotation();

and then use R.s() and R.c()

// Node's orientation reflects in the Jacobian, in tangent space this is equal to the right-hand rule rotation matrix
// H = [ cos(q.theta) -sin(q.theta) 0 ]
// [ sin(q.theta) cos(q.theta) 0 ]
const double cosTheta = cos(q.theta());
Copy link
Member

Choose a reason for hiding this comment

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

same comments as above of course :-)

Copy link
Author

Choose a reason for hiding this comment

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

Right! it is smart to use the available feature, I will update the PR soon.

@nmahabadi
Copy link
Author

@dellaert I updated the code/doc as you suggested.
(I am developing a version of the UnaryFactor that takes the measurement heading into account, once finished I will suggest to have it as a stand-alone factor in gtsam/nonlinear for example. If you agree by this proposal I can come back later by a new feature)

@dellaert
Copy link
Member

Merging failed. Try merging in develop?

@nmahabadi
Copy link
Author

@dellaert I merged the latest develop. The merge seems ok.

@varunagrawal varunagrawal merged commit daf9634 into borglab:develop Apr 16, 2021
@varunagrawal varunagrawal linked an issue Apr 16, 2021 that may be closed by this pull request
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.

Custom factor (unaryFactor) issue with initial heading
3 participants