TSAMFactors.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
19 #pragma once
20 
21 #include <gtsam/geometry/Pose2.h>
23 
24 namespace gtsam {
25 
29 class DeltaFactor: public NoiseModelFactorN<Pose2, Point2> {
30 
31 public:
32  typedef DeltaFactor This;
34  typedef std::shared_ptr<This> shared_ptr;
35 
36 private:
38 
39 public:
40 
41  // Provide access to the Matrix& version of evaluateError:
42  using Base::evaluateError;
43 
46  const SharedNoiseModel& model) :
47  Base(model, i, j), measured_(measured) {
48  }
49 
52  OptionalMatrixType H1, OptionalMatrixType H2) const override {
53  return pose.transformTo(point, H1, H2) - measured_;
54  }
55 };
56 
60 class DeltaFactorBase: public NoiseModelFactorN<Pose2, Pose2, Pose2, Point2> {
61 
62 public:
65  typedef std::shared_ptr<This> shared_ptr;
66 
67 private:
69 
70 public:
71 
72  // Provide access to the Matrix& version of evaluateError:
73  using Base::evaluateError;
74 
77  const SharedNoiseModel& model) :
78  Base(model, b1, i, b2, j), measured_(measured) {
79  }
80 
82  Vector evaluateError(const Pose2& base1, const Pose2& pose,
83  const Pose2& base2, const Point2& point, //
85  OptionalMatrixType H3, OptionalMatrixType H4) const override {
86  if (H1 || H2 || H3 || H4) {
87  // TODO use fixed-size matrices
88  Matrix D_pose_g_base1, D_pose_g_pose;
89  Pose2 pose_g = base1.compose(pose, D_pose_g_base1, D_pose_g_pose);
90  Matrix D_point_g_base2, D_point_g_point;
91  Point2 point_g = base2.transformFrom(point, D_point_g_base2,
92  D_point_g_point);
93  Matrix D_e_pose_g, D_e_point_g;
94  Point2 d = pose_g.transformTo(point_g, D_e_pose_g, D_e_point_g);
95  if (H1)
96  *H1 = D_e_pose_g * D_pose_g_base1;
97  if (H2)
98  *H2 = D_e_pose_g * D_pose_g_pose;
99  if (H3)
100  *H3 = D_e_point_g * D_point_g_base2;
101  if (H4)
102  *H4 = D_e_point_g * D_point_g_point;
103  return d - measured_;
104  } else {
105  Pose2 pose_g = base1.compose(pose);
106  Point2 point_g = base2.transformFrom(point);
107  Point2 d = pose_g.transformTo(point_g);
108  return d - measured_;
109  }
110  }
111 };
112 
116 class OdometryFactorBase: public NoiseModelFactorN<Pose2, Pose2, Pose2, Pose2> {
117 
118 public:
121  typedef std::shared_ptr<This> shared_ptr;
122 
123 private:
125 
126 public:
127 
128  // Provide access to the Matrix& version of evaluateError:
129  using Base::evaluateError;
130 
133  const SharedNoiseModel& model) :
134  Base(model, b1, i, b2, j), measured_(measured) {
135  }
136 
138  Vector evaluateError(const Pose2& base1, const Pose2& pose1,
139  const Pose2& base2, const Pose2& pose2,
141  OptionalMatrixType H3, OptionalMatrixType H4) const override {
142  if (H1 || H2 || H3 || H4) {
143  // TODO use fixed-size matrices
144  Matrix D_pose1_g_base1, D_pose1_g_pose1;
145  Pose2 pose1_g = base1.compose(pose1, D_pose1_g_base1, D_pose1_g_pose1);
146  Matrix D_pose2_g_base2, D_pose2_g_pose2;
147  Pose2 pose2_g = base2.compose(pose2, D_pose2_g_base2, D_pose2_g_pose2);
148  Matrix D_e_pose1_g, D_e_pose2_g;
149  Pose2 d = pose1_g.between(pose2_g, D_e_pose1_g, D_e_pose2_g);
150  if (H1)
151  *H1 = D_e_pose1_g * D_pose1_g_base1;
152  if (H2)
153  *H2 = D_e_pose1_g * D_pose1_g_pose1;
154  if (H3)
155  *H3 = D_e_pose2_g * D_pose2_g_base2;
156  if (H4)
157  *H4 = D_e_pose2_g * D_pose2_g_pose2;
158  return measured_.localCoordinates(d);
159  } else {
160  Pose2 pose1_g = base1.compose(pose1);
161  Pose2 pose2_g = base2.compose(pose2);
162  Pose2 d = pose1_g.between(pose2_g);
163  return measured_.localCoordinates(d);
164  }
165  }
166 };
167 
168 }
169 
Point2 measured(-17, 30)
Vector evaluateError(const Pose2 &pose, const Point2 &point, OptionalMatrixType H1, OptionalMatrixType H2) const override
Evaluate measurement error h(x)-z.
Definition: TSAMFactors.h:51
GTSAM_EXPORT Point2 transformFrom(const Point2 &point, OptionalJacobian< 2, 3 > Dpose={}, OptionalJacobian< 2, 2 > Dpoint={}) const
Definition: Pose2.cpp:226
NoiseModelFactorN< Pose2, Point2 > Base
Definition: TSAMFactors.h:33
noiseModel::Diagonal::shared_ptr model
NoiseModelFactorN< Pose2, Pose2, Pose2, Pose2 > Base
Definition: TSAMFactors.h:120
Vector2 Point2
Definition: Point2.h:32
virtual Vector evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const=0
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
Vector2 b2(4, -5)
std::shared_ptr< This > shared_ptr
Definition: TSAMFactors.h:121
Vector evaluateError(const Pose2 &base1, const Pose2 &pose1, const Pose2 &base2, const Pose2 &pose2, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3, OptionalMatrixType H4) const override
Evaluate measurement error h(x)-z.
Definition: TSAMFactors.h:138
std::shared_ptr< This > shared_ptr
Definition: TSAMFactors.h:34
Point2 measured_
the measurement
Definition: TSAMFactors.h:68
TangentVector localCoordinates(const Class &g) const
localCoordinates as required by manifold concept: finds tangent vector between *this and g ...
Definition: Lie.h:136
DeltaFactorBase This
Definition: TSAMFactors.h:63
Matrix * OptionalMatrixType
Eigen::VectorXd Vector
Definition: Vector.h:38
DeltaFactor This
Definition: TSAMFactors.h:32
Class compose(const Class &g) const
Definition: Lie.h:48
NoiseModelFactorN< Pose2, Pose2, Pose2, Point2 > Base
Definition: TSAMFactors.h:64
static const Pose3 pose1(Rot3(), Point3(0, 1, 0.5))
traits
Definition: chartTesting.h:28
static const Pose3 pose(Rot3(Vector3(1, -1, -1).asDiagonal()), Point3(0, 0, 0.5))
OdometryFactorBase(Key b1, Key i, Key b2, Key j, const Pose2 &measured, const SharedNoiseModel &model)
Constructor.
Definition: TSAMFactors.h:132
Non-linear factor base classes.
Class between(const Class &g) const
Definition: Lie.h:52
std::shared_ptr< This > shared_ptr
Definition: TSAMFactors.h:65
DeltaFactorBase(Key b1, Key i, Key b2, Key j, const Point2 &measured, const SharedNoiseModel &model)
Constructor.
Definition: TSAMFactors.h:76
static Pose3 pose2
2D Pose
Vector evaluateError(const Pose2 &base1, const Pose2 &pose, const Pose2 &base2, const Point2 &point, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3, OptionalMatrixType H4) const override
Evaluate measurement error h(x)-z.
Definition: TSAMFactors.h:82
GTSAM_EXPORT Point2 transformTo(const Point2 &point, OptionalJacobian< 2, 3 > Dpose={}, OptionalJacobian< 2, 2 > Dpoint={}) const
Definition: Pose2.cpp:207
DeltaFactor(Key i, Key j, const Point2 &measured, const SharedNoiseModel &model)
Constructor.
Definition: TSAMFactors.h:45
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102
std::ptrdiff_t j
Pose2 measured_
the measurement
Definition: TSAMFactors.h:124
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:741
Point2 measured_
the measurement
Definition: TSAMFactors.h:37
OdometryFactorBase This
Definition: TSAMFactors.h:119
Vector2 b1(2, -1)


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:40:38