testPoseRTV.cpp
Go to the documentation of this file.
1 
7 #include <gtsam/base/Testable.h>
10 
12 
13 using namespace gtsam;
14 
17 
18 static const Rot3 rot = Rot3::RzRyRx(0.1, 0.2, 0.3);
19 static const Point3 pt(1.0, 2.0, 3.0);
20 static const Velocity3 vel(0.4, 0.5, 0.6);
21 static const Vector3 kZero3 = Vector3::Zero();
22 
23 /* ************************************************************************* */
24 TEST( testPoseRTV, constructors ) {
25  PoseRTV state1(pt, rot, vel);
26  EXPECT(assert_equal(pt, state1.t()));
27  EXPECT(assert_equal(rot, state1.R()));
28  EXPECT(assert_equal(vel, state1.v()));
29  EXPECT(assert_equal(Pose3(rot, pt), state1.pose()));
30 
32  EXPECT(assert_equal(Point3(0,0,0), state2.t()));
33  EXPECT(assert_equal(Rot3(), state2.R()));
34  EXPECT(assert_equal(kZero3, state2.v()));
35  EXPECT(assert_equal(Pose3(), state2.pose()));
36 
37  PoseRTV state3(Pose3(rot, pt), vel);
38  EXPECT(assert_equal(pt, state3.t()));
39  EXPECT(assert_equal(rot, state3.R()));
40  EXPECT(assert_equal(vel, state3.v()));
41  EXPECT(assert_equal(Pose3(rot, pt), state3.pose()));
42 
43  PoseRTV state4(Pose3(rot, pt));
44  EXPECT(assert_equal(pt, state4.t()));
45  EXPECT(assert_equal(rot, state4.R()));
46  EXPECT(assert_equal(kZero3, state4.v()));
47  EXPECT(assert_equal(Pose3(rot, pt), state4.pose()));
48 
49  Vector vec_init = (Vector(9) << 0.1, 0.2, 0.3, 1.0, 2.0, 3.0, 0.4, 0.5, 0.6).finished();
50  PoseRTV state5(vec_init);
51  EXPECT(assert_equal(pt, state5.t()));
52  EXPECT(assert_equal(rot, state5.R()));
53  EXPECT(assert_equal(vel, state5.v()));
54  EXPECT(assert_equal(vec_init, state5.vector()));
55 }
56 
57 /* ************************************************************************* */
58 TEST( testPoseRTV, dim ) {
59  PoseRTV state1(pt, rot, vel);
60  EXPECT_LONGS_EQUAL(9, state1.dim());
62 }
63 
64 /* ************************************************************************* */
65 TEST( testPoseRTV, equals ) {
66  PoseRTV state1, state2(pt, rot, vel), state3(state2), state4(Pose3(rot, pt));
67  EXPECT(assert_equal(state1, state1));
68  EXPECT(assert_equal(state2, state3));
69  EXPECT(assert_equal(state3, state2));
70  EXPECT(assert_inequal(state1, state2));
71  EXPECT(assert_inequal(state2, state1));
72  EXPECT(assert_inequal(state2, state4));
73 }
74 
75 /* ************************************************************************* */
76 TEST( testPoseRTV, Lie ) {
77  // origin and zero deltas
78  PoseRTV identity;
79  EXPECT(assert_equal(identity, (PoseRTV)identity.retract(Z_9x1)));
80  EXPECT(assert_equal((Vector) Z_9x1, identity.localCoordinates(identity)));
81 
82  PoseRTV state1(pt, rot, vel);
83  EXPECT(assert_equal(state1, (PoseRTV)state1.retract(Z_9x1)));
84  EXPECT(assert_equal((Vector) Z_9x1, state1.localCoordinates(state1)));
85 
86  Vector delta(9);
87  delta << 0.1, 0.1, 0.1, 0.2, 0.3, 0.4,-0.1,-0.2,-0.3;
88  Pose3 pose2 = Pose3(rot, pt).retract(delta.head<6>());
89  Velocity3 vel2 = vel + Velocity3(-0.1, -0.2, -0.3);
90  PoseRTV state2(pose2.translation(), pose2.rotation(), vel2);
91  EXPECT(assert_equal(state2, (PoseRTV)state1.retract(delta)));
92  EXPECT(assert_equal(delta, state1.localCoordinates(state2)));
93 
94  // roundtrip from state2 to state3 and back
95  PoseRTV state3 = state2.retract(delta);
96  EXPECT(assert_equal(delta, state2.localCoordinates(state3)));
97 
98  // roundtrip from state3 to state4 and back, with expmap.
99  PoseRTV state4 = state3.expmap(delta);
100  EXPECT(assert_equal(delta, state3.logmap(state4)));
101 
102  // For the expmap/logmap (not necessarily retract/local) -delta goes other way
103  EXPECT(assert_equal(state3, (PoseRTV)state4.expmap(-delta)));
104  EXPECT(assert_equal(delta, -state4.logmap(state3)));
105 }
106 
107 /* ************************************************************************* */
108 TEST( testPoseRTV, dynamics_identities ) {
109  // general dynamics should produce the same measurements as the imuPrediction function
110  PoseRTV x0, x1, x2, x3, x4;
111 
112  const double dt = 0.1;
113  Vector accel = Vector3(0.2, 0.0, 0.0), gyro = Vector3(0.0, 0.0, 0.2);
114  Vector imu01 = Z_6x1, imu12 = Z_6x1, imu23 = Z_6x1, imu34 = Z_6x1;
115 
116  x1 = x0.generalDynamics(accel, gyro, dt);
117  x2 = x1.generalDynamics(accel, gyro, dt);
118  x3 = x2.generalDynamics(accel, gyro, dt);
119  x4 = x3.generalDynamics(accel, gyro, dt);
120 
121 // EXPECT(assert_equal(imu01, x0.imuPrediction(x1, dt).first));
122 // EXPECT(assert_equal(imu12, x1.imuPrediction(x2, dt).first));
123 // EXPECT(assert_equal(imu23, x2.imuPrediction(x3, dt).first));
124 // EXPECT(assert_equal(imu34, x3.imuPrediction(x4, dt).first));
125 //
126 // EXPECT(assert_equal(x1.translation(), x0.imuPrediction(x1, dt).second));
127 // EXPECT(assert_equal(x2.translation(), x1.imuPrediction(x2, dt).second));
128 // EXPECT(assert_equal(x3.translation(), x2.imuPrediction(x3, dt).second));
129 // EXPECT(assert_equal(x4.translation(), x3.imuPrediction(x4, dt).second));
130 }
131 
132 
133 /* ************************************************************************* */
134 PoseRTV compose_proxy(const PoseRTV& A, const PoseRTV& B) { return A.compose(B); }
135 TEST( testPoseRTV, compose ) {
137 
138  Matrix actH1, actH2;
139  state1.compose(state2, actH1, actH2);
140  Matrix numericH1 = numericalDerivative21(compose_proxy, state1, state2);
141  Matrix numericH2 = numericalDerivative22(compose_proxy, state1, state2);
142  EXPECT(assert_equal(numericH1, actH1));
143  EXPECT(assert_equal(numericH2, actH2));
144 }
145 
146 /* ************************************************************************* */
147 PoseRTV between_proxy(const PoseRTV& A, const PoseRTV& B) { return A.between(B); }
148 TEST( testPoseRTV, between ) {
150 
151  Matrix actH1, actH2;
152  state1.between(state2, actH1, actH2);
153  Matrix numericH1 = numericalDerivative21(between_proxy, state1, state2);
154  Matrix numericH2 = numericalDerivative22(between_proxy, state1, state2);
155  EXPECT(assert_equal(numericH1, actH1));
156  EXPECT(assert_equal(numericH2, actH2));
157 }
158 
159 /* ************************************************************************* */
160 PoseRTV inverse_proxy(const PoseRTV& A) { return A.inverse(); }
161 TEST( testPoseRTV, inverse ) {
162  PoseRTV state1(pt, rot, vel);
163 
164  Matrix actH1;
165  state1.inverse(actH1);
166  Matrix numericH1 = numericalDerivative11(inverse_proxy, state1);
167  EXPECT(assert_equal(numericH1, actH1));
168 }
169 
170 /* ************************************************************************* */
171 double range_proxy(const PoseRTV& A, const PoseRTV& B) { return A.range(B); }
172 TEST( testPoseRTV, range ) {
173  Point3 tA(1.0, 2.0, 3.0), tB(3.0, 2.0, 3.0);
174  PoseRTV rtvA(tA), rtvB(tB);
175  EXPECT_DOUBLES_EQUAL(0.0, rtvA.range(rtvA), 1e-9);
176  EXPECT_DOUBLES_EQUAL(2.0, rtvA.range(rtvB), 1e-9);
177  EXPECT_DOUBLES_EQUAL(2.0, rtvB.range(rtvA), 1e-9);
178 
179  Matrix actH1, actH2;
180  rtvA.range(rtvB, actH1, actH2);
181  Matrix numericH1 = numericalDerivative21(range_proxy, rtvA, rtvB);
182  Matrix numericH2 = numericalDerivative22(range_proxy, rtvA, rtvB);
183  EXPECT(assert_equal(numericH1, actH1));
184  EXPECT(assert_equal(numericH2, actH2));
185 }
186 
187 /* ************************************************************************* */
189  return a.transformed_from(trans);
190 }
191 TEST( testPoseRTV, transformed_from_1 ) {
192  Rot3 R = Rot3::Rodrigues(0.1, 0.2, 0.3);
193  Point3 T(1.0, 2.0, 3.0);
194  Velocity3 V(2.0, 3.0, 4.0);
195  PoseRTV start(R, T, V);
196  Pose3 transform(Rot3::Yaw(M_PI_2), Point3(1.0, 2.0, 3.0));
197 
198  Matrix actDTrans, actDGlobal;
199  PoseRTV actual = start.transformed_from(transform, actDGlobal, actDTrans);
200  PoseRTV expected(transform.compose(start.pose()), transform.rotation().matrix() * V);
201  EXPECT(assert_equal(expected, actual));
202 
203  Matrix numDGlobal = numericalDerivative21(transformed_from_proxy, start, transform, 1e-5); // At 1e-8, fails
204  Matrix numDTrans = numericalDerivative22(transformed_from_proxy, start, transform, 1e-8); // Sensitive to step size
205  EXPECT(assert_equal(numDGlobal, actDGlobal));
206  EXPECT(assert_equal(numDTrans, actDTrans, 1e-5)); // FIXME: still needs analytic derivative
207 }
208 
209 /* ************************************************************************* */
210 TEST( testPoseRTV, transformed_from_2 ) {
211  Rot3 R;
212  Point3 T(1.0, 2.0, 3.0);
213  Velocity3 V(2.0, 3.0, 4.0);
214  PoseRTV start(R, T, V);
215  Pose3 transform(Rot3::Yaw(M_PI_2), Point3(1.0, 2.0, 3.0));
216 
217  Matrix actDTrans, actDGlobal;
218  PoseRTV actual = start.transformed_from(transform, actDGlobal, actDTrans);
219  PoseRTV expected(transform.compose(start.pose()), transform.rotation().matrix() * V);
220  EXPECT(assert_equal(expected, actual));
221 
222  Matrix numDGlobal = numericalDerivative21(transformed_from_proxy, start, transform, 1e-5); // At 1e-8, fails
223  Matrix numDTrans = numericalDerivative22(transformed_from_proxy, start, transform, 1e-8); // Sensitive to step size
224  EXPECT(assert_equal(numDGlobal, actDGlobal));
225  EXPECT(assert_equal(numDTrans, actDTrans, 1e-5)); // FIXME: still needs analytic derivative
226 }
227 
228 /* ************************************************************************* */
229 TEST(testPoseRTV, RRTMbn) {
232  EXPECT(assert_equal(PoseRTV::RRTMbn(Vector3(0.3, 0.2, 0.1)), PoseRTV::RRTMbn(Rot3::Ypr(0.1, 0.2, 0.3))));
233 }
234 
235 /* ************************************************************************* */
236 TEST(testPoseRTV, RRTMnb) {
239  EXPECT(assert_equal(PoseRTV::RRTMnb(Vector3(0.3, 0.2, 0.1)), PoseRTV::RRTMnb(Rot3::Ypr(0.1, 0.2, 0.3))));
240 }
241 
242 /* ************************************************************************* */
243 int main() { TestResult tr; return TestRegistry::runAllTests(tr); }
244 /* ************************************************************************* */
245 
Provides additional testing facilities for common data structures.
static Rot3 Ypr(double y, double p, double r, OptionalJacobian< 3, 1 > Hy={}, OptionalJacobian< 3, 1 > Hp={}, OptionalJacobian< 3, 1 > Hr={})
Definition: Rot3.h:196
ProductLieGroup compose(const ProductLieGroup &g) const
const Point3 & translation(OptionalJacobian< 3, 6 > Hself={}) const
get translation
Definition: Pose3.cpp:308
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
Eigen::Vector3d Vector3
Definition: Vector.h:43
static const Velocity3 vel(0.4, 0.5, 0.6)
Matrix expected
Definition: testMatrix.cpp:971
Vector3 Velocity3
Velocity is currently typedef&#39;d to Vector3.
Definition: NavState.h:28
PoseRTV transformed_from_proxy(const PoseRTV &a, const Pose3 &trans)
TangentVector logmap(const ProductLieGroup &g) const
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
Rot2 R(Rot2::fromAngle(0.1))
const Rot3 & R() const
Definition: PoseRTV.h:59
PoseRTV compose_proxy(const PoseRTV &A, const PoseRTV &B)
Some functions to compute numerical derivatives.
Pose3 x2(Rot3::Ypr(0.0, 0.0, 0.0), l2)
static const Vector3 kZero3
Definition: testPoseRTV.cpp:21
static const Point3 pt(1.0, 2.0, 3.0)
const Pose3 & pose() const
Definition: PoseRTV.h:56
static const NavState state1(x1, v1)
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
Definition: Rot3.h:58
#define GTSAM_CONCEPT_LIE_INST(T)
Definition: Lie.h:372
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
Definition: Test.h:161
EIGEN_DEVICE_FUNC const InverseReturnType inverse() const
Matrix trans(const Matrix &A)
Definition: base/Matrix.h:241
static Matrix RRTMnb(const Vector3 &euler)
Definition: PoseRTV.cpp:225
internal::FixedSizeMatrix< Y, X >::type numericalDerivative11(std::function< Y(const X &)> h, const X &x, double delta=1e-5)
New-style numerical derivatives using manifold_traits.
internal::FixedSizeMatrix< Y, X1 >::type numericalDerivative21(const std::function< Y(const X1 &, const X2 &)> &h, const X1 &x1, const X2 &x2, double delta=1e-5)
ProductLieGroup between(const ProductLieGroup &g) const
const double dt
ProductLieGroup expmap(const TangentVector &v) const
bool assert_inequal(const Matrix &A, const Matrix &B, double tol)
Definition: Matrix.cpp:60
static Rot3 Rodrigues(const Vector3 &w)
Definition: Rot3.h:240
static Rot3 Yaw(double t)
Positive yaw is to right (as in aircraft heading). See ypr.
Definition: Rot3.h:174
int main()
Eigen::VectorXd Vector
Definition: Vector.h:38
double range(const PoseRTV &other, OptionalJacobian< 1, 9 > H1={}, OptionalJacobian< 1, 9 > H2={}) const
Definition: PoseRTV.cpp:169
TangentVector localCoordinates(const ProductLieGroup &g, ChartJacobian H1={}, ChartJacobian H2={}) const
static const NavState state2(x2, v2)
#define EXPECT(condition)
Definition: Test.h:150
PoseRTV transformed_from(const Pose3 &trans, ChartJacobian Dglobal={}, OptionalJacobian< 9, 6 > Dtrans={}) const
Definition: PoseRTV.cpp:182
Eigen::Triplet< double > T
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static Matrix RRTMbn(const Vector3 &euler)
Definition: PoseRTV.cpp:208
EIGEN_DONT_INLINE void transform(const Transformation &t, Data &data)
Definition: geometry.cpp:25
Class compose(const Class &g) const
Definition: Lie.h:48
Pose3 x3(Rot3::Ypr(M_PI/4.0, 0.0, 0.0), l2)
PoseRTV between_proxy(const PoseRTV &A, const PoseRTV &B)
Pose3 with translational velocity.
traits
Definition: chartTesting.h:28
double range_proxy(const PoseRTV &A, const PoseRTV &B)
NavState retract(const Vector9 &v, OptionalJacobian< 9, 9 > H1={}, OptionalJacobian< 9, 9 > H2={}) const
retract with optional derivatives
Definition: NavState.cpp:107
static Symbol x0('x', 0)
#define EXPECT_LONGS_EQUAL(expected, actual)
Definition: Test.h:154
Class retract(const TangentVector &v) const
retract as required by manifold concept: applies v at *this
Definition: Lie.h:131
ProductLieGroup inverse() const
Double_ range(const Point2_ &p, const Point2_ &q)
Vector vector() const
Definition: PoseRTV.cpp:37
Pose3 x1
Definition: testPose3.cpp:663
Matrix3 matrix() const
Definition: Rot3M.cpp:218
Expression< T > compose(const Expression< T > &t1, const Expression< T > &t2)
ProductLieGroup retract(const TangentVector &v, ChartJacobian H1={}, ChartJacobian H2={}) const
PoseRTV generalDynamics(const Vector &accel, const Vector &gyro, double dt) const
General Dynamics update - supply control inputs in body frame.
Definition: PoseRTV.cpp:118
Vector9 localCoordinates(const NavState &g, OptionalJacobian< 9, 9 > H1={}, OptionalJacobian< 9, 9 > H2={}) const
localCoordinates with optional derivatives
Definition: NavState.cpp:133
static Pose3 pose2
static const Rot3 rot
Definition: testPoseRTV.cpp:18
internal::FixedSizeMatrix< Y, X2 >::type numericalDerivative22(std::function< Y(const X1 &, const X2 &)> h, const X1 &x1, const X2 &x2, double delta=1e-5)
const Point3 & t() const
Definition: PoseRTV.h:58
const Rot3 & rotation(OptionalJacobian< 3, 6 > Hself={}) const
get rotation
Definition: Pose3.cpp:315
Vector3 Point3
Definition: Point3.h:38
TEST(SmartFactorBase, Pinhole)
static string x4("x4")
PoseRTV inverse_proxy(const PoseRTV &A)
Expression< T > between(const Expression< T > &t1, const Expression< T > &t2)
const Velocity3 & v() const
Definition: PoseRTV.h:57
#define GTSAM_CONCEPT_TESTABLE_INST(T)
Definition: Testable.h:176


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:39:01