Thanks for the clarification!
Yes, I noticed that the
PriorFactor::Pose3 actually achieves what I wanted to do - the naming
confused me a bit at the beginning.
Just as an exercise, how would you implement the
tutorial
example 3.2 using the methods provided by gtsam? In
the example, the derivate of the measurement function in exp coordinates
is calculated by hand. When I compare the output of these equations
(analytical_H) to the output of
' Pose2::ExpmapDerivative
' (w.r.t. q.x, q.y, q.theta) (denoted in the code as numer_H), the
outputs don't quite match. Am I correct in assuming that the rows of
analytical_H should match the columns of numer_H ? Is this caused by the
tutorial example using more drastic simplifications than those used in
the actual gtsam implementation?
Vector evaluateError(const Pose2& q, boost::optional<Matrix&> H = boost::none) const override {
// The measurement function for a GPS-like measurement h(q) which predicts the measurement (m) is h(q) = q, q = [qx qy qtheta]
// The error is then simply calculated as E(q) = h(q) - m:
// error_x = q.x - mx
// error_y = q.y - my
// 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 Rot2& R = q.rotation();
// This is the derivative from tutorial example 3.2.
auto analytical_H = (gtsam::Matrix(2, 3) << R.c(), -R.s(), 0.0, R.s(), R.c(), 0.0).finished();
// This is the derivative from the gtsam method
auto numer_H = Pose2::ExpmapDerivative(Vector3(q.x(), q.y(), q.theta()));
cout << "\n------------" << endl;
cout << "Analytical: \n" << analytical_H << endl;
cout << "\n" << endl;
cout << "Numerical: \n" << numer_H << endl;
if (H) (*H) = analytical_H;
return (Vector(2) << q.x() - mx_, q.y() - my_).finished();
------------
Analytical:
0.587440388 -0.809267441 0
0.809267441 0.587440388 0
Numerical:
0.858271294 0.437541478 0.161924745
-0.437541478 0.858271294 0.84848915
0 0 1
------------
Analytical:
0.587490952 -0.809230734 0
0.809230734 0.587490952 0
Numerical:
0.85828924 0.437516844 -0.579822049
-0.437516844 0.85828924 1.30812419
Thanks,
-Lauri