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

Inverse using Expressions differs from normal inverse #128

Closed
thorstink opened this issue Oct 2, 2019 · 5 comments
Closed

Inverse using Expressions differs from normal inverse #128

thorstink opened this issue Oct 2, 2019 · 5 comments

Comments

@thorstink
Copy link
Contributor

Description

I tried inverting rotations and poses using gtsam expressions. They don't seem to work.. (giving different values from expected). However, it might also be my lack of knowledge on the inner workings of the lie-stuff and I am just making a really novice faulty assumption on what I'm doing?

I also noticed some commit-messages from @dellaert about Pose3 losing mojo and wrong derivatives around identity? I guess this might be something related?

Steps to reproduce

#include <gtsam/geometry/Pose3.h>
#include <gtsam/nonlinear/Values.h>
#include <gtsam/slam/expressions.h>

using namespace gtsam;

int main() {

  using symbol_shorthand::R;
  using symbol_shorthand::T;

  double y_offset = -1;
  Rot3 bRs = Rot3(Rot3::Ry(M_PI / 2)) * Rot3::Rz(0.2);
  Pose3 bTs(bRs, Point3(0, y_offset, 0));

  Values values;
  values.insert(T(0), bTs);
  values.insert(R(0), bRs);

  Pose3_((&LieGroup<Pose3, 6>::inverse, Pose3_(T(0))))
      .value(values)
      .print("\nT expression liegroup value\n");

  (values.at<Pose3>(T(0)).inverse()).print("\nT just composition\n");

  Rot3_((&LieGroup<Rot3, 3>::inverse, Rot3_(R(0))))
      .value(values)
      .print("\nR expression liegroup value\n");

  (values.at<Rot3>(R(0)).inverse()).print("\nR just composition\n");

  
  return 0;
}
T expression liegroup value
R:
[
 	6.00118e-17 -1.2165e-17           1;
    	   0.198669    0.980067           0;
    	  -0.980067    0.198669 6.12323e-17
  ]
[0, -1, 0]';
T just composition
R:
[
 	6.00118e-17    0.198669   -0.980067;
    	-1.2165e-17    0.980067    0.198669;
    	          1           0 6.12323e-17
  ]
[0.198669, 0.980067, 0]';
R expression liegroup value
[
 	6.00118e-17 -1.2165e-17           1;
    	   0.198669    0.980067           0;
    	  -0.980067    0.198669 6.12323e-17
  ]

R just composition
[
 	6.00118e-17    0.198669   -0.980067;
    	-1.2165e-17    0.980067    0.198669;
    	          1           0 6.12323e-17
  ]

Expected behavior

I expected that the inverses would be the same?

Environment

Latest and greatest GTSAM. Ubuntu 18.04.

Additional information

@thorstink thorstink changed the title Inverse using Expressions Inverse using Expressions differs from normal inverse Oct 2, 2019
@dellaert
Copy link
Member

dellaert commented Oct 2, 2019

Nothing to do with Pose3 mojo. But the above is concerning! What happens if you use &Pose3::inverse Rather than &LieGroup<Pose3, 6>::inverse ?

@thorstink
Copy link
Contributor Author

thorstink commented Oct 2, 2019

In that case the compiler doesn't get it;

expr.cc:20:11: error: left operand of comma operator cannot resolve address of overloaded function
   Pose3_((&Pose3::inverse, Pose3_(T(0))))
           ^~~~~~
expr.cc:26:10: error: left operand of comma operator cannot resolve address of overloaded function
   Rot3_((&Rot3::inverse, Rot3_(R(0))))

I also did it the same way recently some expressions were added to the navigation-part; but that gave the same incorrect results. it looks as if it simply doesn’t invert the rotation..?

@thduynguyen
Copy link
Contributor

You have extra pairs of parentheses. I guess it's a rare pitfall of C++ called comma operator: https://en.cppreference.com/w/cpp/language/operator_other

@thduynguyen
Copy link
Contributor

This works fine for me:

double y_offset = -1;
  Rot3 bRs = Rot3(Rot3::Ry(M_PI / 2)) * Rot3::Rz(0.2);
  Pose3 bTs(bRs, Point3(0, y_offset, 0));

  Values values;
  values.insert(T(0), bTs);
  values.insert(R(0), bRs);

  Pose3_(&LieGroup<Pose3, 6>::inverse, Pose3_(T(0)))
      .value(values)
      .print("\nT expression liegroup value\n");

  (values.at<Pose3>(T(0)).inverse()).print("\nT just composition\n");

  Rot3_(&LieGroup<Rot3, 3>::inverse, Rot3_(R(0)))
      .value(values)
      .print("\nR expression liegroup value\n");

  (values.at<Rot3>(R(0)).inverse()).print("\nR just composition\n");

@thorstink
Copy link
Contributor Author

I can confirm it works :-)

I thought I knew C++....

varunagrawal added a commit that referenced this issue Oct 25, 2021
0ab10c359 Fix pyparsing version and replace `create_symlinks` with `copy_directory` (#128)
230a3c967 Merge pull request #127 from borglab/feature/template-instantiator
cc7d9a8b4 breakdown template instantiator into smaller submodules
59536220a Merge pull request #126 from borglab/feature/instantiation-tests
7ee715ecc add type info to template_instantiator
b367ed93d tests for InstantiationHelper
e41cfd50e tests for InstantiatedGlobalFunction
1837982a7 tests for InstantiatedClass
a7e3678a3 tests for InstantiatedStaticMethod
da06c53f7 tests for InstantiatedMethod
c645c143c tests for InstantiatedConstructor
b8a046267 tests for InstantiatedDeclaration
af80c9d04 finish all tests for namespace level instantiation
d6085c37a add tests for high level template instantiation
f7ae91346 add docs and utility method
d90abb52b Merge pull request #125 from borglab/feature/templated-static
58cdab20d clean up
247cea727 add helper for multilevel instantiation
761f588e4 update tests
81e5d5d19 update pybind wrapper to use new way
96d1575d8 streamlined way of instantiating template for class methods
1e4e88799 add to_cpp method for Method
485d43138 add the test fixtures
8cb943635 support instantiation of static method templates
84ef6679b add template to static method parser

git-subtree-dir: wrap
git-subtree-split: 0ab10c359a6528def20eddc60aced74a04250419
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

No branches or pull requests

3 participants