gtsam
Loading...
Searching...
No Matches
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
18
19#pragma once
20
24
25namespace gtsam {
26
30class DeltaFactor : public NoiseModelFactorT<Vector2, Pose2, Point2> {
31
32public:
33 typedef DeltaFactor This;
35 typedef std::shared_ptr<This> shared_ptr;
36
37private:
38 Point2 measured_;
39
40public:
41
42 // Provide access to the Matrix& version of evaluateError:
44
46 DeltaFactor(Key i, Key j, const Point2& measured,
47 const SharedNoiseModel& model) :
48 Base(model, i, j), measured_(measured) {
49 }
50
52 Vector2 evaluateError(const Pose2& pose, const Point2& point,
54 OptionalMatrixType H2) const override {
55 return pose.transformTo(point, H1, H2) - measured_;
56 }
57};
58
62class DeltaFactorBase: public NoiseModelFactorN<Pose2, Pose2, Pose2, Point2> {
63
64public:
65 typedef DeltaFactorBase This;
67 typedef std::shared_ptr<This> shared_ptr;
68
69private:
70 Point2 measured_;
71
72public:
73
74 // Provide access to the Matrix& version of evaluateError:
76
78 DeltaFactorBase(Key b1, Key i, Key b2, Key j, const Point2& measured,
79 const SharedNoiseModel& model) :
80 Base(model, b1, i, b2, j), measured_(measured) {
81 }
82
84 Vector evaluateError(const Pose2& base1, const Pose2& pose,
85 const Pose2& base2, const Point2& point, //
87 OptionalMatrixType H3, OptionalMatrixType H4) const override {
88 if (H1 || H2 || H3 || H4) {
89 // TODO use fixed-size matrices
90 Matrix D_pose_g_base1, D_pose_g_pose;
91 Pose2 pose_g = base1.compose(pose, D_pose_g_base1, D_pose_g_pose);
92 Matrix D_point_g_base2, D_point_g_point;
93 Point2 point_g = base2.transformFrom(point, D_point_g_base2,
94 D_point_g_point);
95 Matrix D_e_pose_g, D_e_point_g;
96 Point2 d = pose_g.transformTo(point_g, D_e_pose_g, D_e_point_g);
97 if (H1)
98 *H1 = D_e_pose_g * D_pose_g_base1;
99 if (H2)
100 *H2 = D_e_pose_g * D_pose_g_pose;
101 if (H3)
102 *H3 = D_e_point_g * D_point_g_base2;
103 if (H4)
104 *H4 = D_e_point_g * D_point_g_point;
105 return d - measured_;
106 } else {
107 Pose2 pose_g = base1.compose(pose);
108 Point2 point_g = base2.transformFrom(point);
109 Point2 d = pose_g.transformTo(point_g);
110 return d - measured_;
111 }
112 }
113};
114
118class OdometryFactorBase: public NoiseModelFactorN<Pose2, Pose2, Pose2, Pose2> {
119
120public:
121 typedef OdometryFactorBase This;
123 typedef std::shared_ptr<This> shared_ptr;
124
125private:
126 Pose2 measured_;
127
128public:
129
130 // Provide access to the Matrix& version of evaluateError:
132
134 OdometryFactorBase(Key b1, Key i, Key b2, Key j, const Pose2& measured,
135 const SharedNoiseModel& model) :
136 Base(model, b1, i, b2, j), measured_(measured) {
137 }
138
140 Vector evaluateError(const Pose2& base1, const Pose2& pose1,
141 const Pose2& base2, const Pose2& pose2,
143 OptionalMatrixType H3, OptionalMatrixType H4) const override {
144 if (H1 || H2 || H3 || H4) {
145 // TODO use fixed-size matrices
146 Matrix D_pose1_g_base1, D_pose1_g_pose1;
147 Pose2 pose1_g = base1.compose(pose1, D_pose1_g_base1, D_pose1_g_pose1);
148 Matrix D_pose2_g_base2, D_pose2_g_pose2;
149 Pose2 pose2_g = base2.compose(pose2, D_pose2_g_base2, D_pose2_g_pose2);
150 Matrix D_e_pose1_g, D_e_pose2_g;
151 Pose2 d = pose1_g.between(pose2_g, D_e_pose1_g, D_e_pose2_g);
152 Matrix3 localJacobian;
153 const Vector error =
154 measured_.localCoordinates(d, nullptr, localJacobian);
155 if (H1) *H1 = localJacobian * D_e_pose1_g * D_pose1_g_base1;
156 if (H2) *H2 = localJacobian * D_e_pose1_g * D_pose1_g_pose1;
157 if (H3) *H3 = localJacobian * D_e_pose2_g * D_pose2_g_base2;
158 if (H4) *H4 = localJacobian * D_e_pose2_g * D_pose2_g_pose2;
159 return error;
160 } else {
161 Pose2 pose1_g = base1.compose(pose1);
162 Pose2 pose2_g = base2.compose(pose2);
163 Pose2 d = pose1_g.between(pose2_g);
164 return measured_.localCoordinates(d);
165 }
166 }
167};
168
169}
2D Pose
Base class for noise model factors with N variables.
Non-linear factor base classes.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
Matrix * OptionalMatrixType
This typedef will be used everywhere boost::optional<Matrix&> reference was used previously.
Definition NonlinearFactor.h:57
NoiseModelFactorT< Vector, ValueTypes... > NoiseModelFactorN
Noise model factor with N value types and dynamic-sized error vector.
Definition NoiseModelFactorN.h:561
Vector2 Point2
As of GTSAM 4, in order to make GTSAM more lean, it is now possible to just typedef Point2 to Vector2...
Definition Point2.h:32
noiseModel::Base::shared_ptr SharedNoiseModel
Aliases.
Definition NoiseModel.h:846
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
TangentVector localCoordinates(const Class &g) const
localCoordinates as required by manifold concept: finds tangent vector between *this and g
Definition Lie.h:226
A 2D pose (Point2,Rot2).
Definition Pose2.h:39
Point2 transformFrom(const Point2 &point, OptionalJacobian< 2, 3 > Dpose={}, OptionalJacobian< 2, 2 > Dpoint={}) const
Return point coordinates in global frame.
Definition Pose2.cpp:257
Point2 transformTo(const Point2 &point, OptionalJacobian< 2, 3 > Dpose={}, OptionalJacobian< 2, 2 > Dpoint={}) const
Return point coordinates in pose coordinate frame.
Definition Pose2.cpp:238
NoiseModelFactorT()
Definition NoiseModelFactorN.h:257
virtual Vector2 evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const=0
double error(const Values &c) const override
Calculate the error of the factor.
Definition NonlinearFactor.cpp:146
Vector2 evaluateError(const Pose2 &pose, const Point2 &point, OptionalMatrixType H1, OptionalMatrixType H2) const override
Evaluate measurement error h(x)-z.
Definition TSAMFactors.h:52
DeltaFactor(Key i, Key j, const Point2 &measured, const SharedNoiseModel &model)
Constructor.
Definition TSAMFactors.h:46
DeltaFactorBase(Key b1, Key i, Key b2, Key j, const Point2 &measured, const SharedNoiseModel &model)
Constructor.
Definition TSAMFactors.h:78
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:84
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:140
OdometryFactorBase(Key b1, Key i, Key b2, Key j, const Pose2 &measured, const SharedNoiseModel &model)
Constructor.
Definition TSAMFactors.h:134