Main MRPT website > C++ reference for MRPT 1.9.9
SE_traits_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <mrpt/poses/CPose3D.h>
11 #include <mrpt/poses/SE_traits.h>
12 #include <mrpt/math/jacobians.h>
13 #include <gtest/gtest.h>
14 
15 using namespace mrpt;
16 using namespace mrpt::poses;
17 using namespace mrpt::utils;
18 using namespace mrpt::math;
19 using namespace std;
20 
21 template <class POSE_TYPE>
22 class SE_traits_tests : public ::testing::Test
23 {
24  protected:
25  virtual void SetUp() {}
26  virtual void TearDown() {}
28 
29  struct TParams
30  {
31  typename SE_TYPE::pose_t P1, D, P2;
32  };
33 
34  static void func_numeric(
37  {
38  typename SE_TYPE::array_t eps1, eps2;
39  for (int i = 0; i < SE_TYPE::VECTOR_SIZE; i++)
40  {
41  eps1[i] = x[0 + i];
42  eps2[i] = x[SE_TYPE::VECTOR_SIZE + i];
43  }
44 
45  POSE_TYPE incr1, incr2;
46  SE_TYPE::exp(eps1, incr1);
47  SE_TYPE::exp(eps2, incr2);
48 
49  const POSE_TYPE P1 = incr1 + params.P1;
50  const POSE_TYPE P2 = incr2 + params.P2;
51  const POSE_TYPE& Pd = params.D;
52 
53  const CPose3D P1DP2inv_(
55  P1.getHomogeneousMatrixVal() * Pd.getHomogeneousMatrixVal() *
56  P2.getInverseHomogeneousMatrix()));
57  const POSE_TYPE P1DP2inv(P1DP2inv_);
58 
59  // Pseudo-logarithm:
60  SE_TYPE::pseudo_ln(P1DP2inv, Y);
61  }
62 
64  double x1, double y1, double z1, double yaw1, double pitch1,
65  double roll1, double xd, double yd, double zd, double yawd,
66  double pitchd, double rolld, double x2, double y2, double z2,
67  double yaw2, double pitch2, double roll2)
68  {
69  const CPose3D P1_(x1, y1, z1, yaw1, pitch1, roll1);
70  const CPose3D Pd_(xd, yd, zd, yawd, pitchd, rolld);
71  const CPose3D P2_(x2, y2, z2, yaw2, pitch2, roll2);
72 
73  const POSE_TYPE P1(P1_);
74  const POSE_TYPE Pd(Pd_);
75  const POSE_TYPE P2(P2_);
76 
77  const CPose3D P1DP2inv_(
79  P1.getHomogeneousMatrixVal() * Pd.getHomogeneousMatrixVal() *
80  P2.getInverseHomogeneousMatrix()));
81  const POSE_TYPE P1DP2inv(P1DP2inv_); // Convert to 2D if needed
82 
83  static const int DIMS = SE_TYPE::VECTOR_SIZE;
84 
85  // Theoretical results:
87  SE_TYPE::jacobian_dP1DP2inv_depsilon(P1DP2inv, &J1, &J2);
88 
89  // Numerical approx:
91  {
93  for (int i = 0; i < DIMS + DIMS; i++) x_mean[i] = 0;
94 
96  params.P1 = P1;
97  params.D = Pd;
98  params.P2 = P2;
99 
101  x_incrs.assign(1e-4);
102  CMatrixDouble numJacobs;
104  x_mean,
105  std::function<void(
107  const TParams& params,
108  CArrayDouble<SE_TYPE::VECTOR_SIZE>& Y)>(&func_numeric),
109  x_incrs, params, numJacobs);
110 
111  numJacobs.extractMatrix(0, 0, num_J1);
112  numJacobs.extractMatrix(0, DIMS, num_J2);
113  }
114 
115  const double max_eror = 1e-3;
116 
117  EXPECT_NEAR(0, (num_J1 - J1).array().abs().sum(), max_eror)
118  << "p1: " << P1 << endl
119  << "d: " << Pd << endl
120  << "p2: " << P2 << endl
121  << "Numeric J1:\n"
122  << num_J1 << endl
123  << "Implemented J1:\n"
124  << J1 << endl
125  << "Error:\n"
126  << J1 - num_J1 << endl;
127 
128  EXPECT_NEAR(0, (num_J2 - J2).array().abs().sum(), max_eror)
129  << "p1: " << P1 << endl
130  << "d: " << Pd << endl
131  << "p2: " << P2 << endl
132  << "Numeric J2:\n"
133  << num_J2 << endl
134  << "Implemented J2:\n"
135  << J2 << endl
136  << "Error:\n"
137  << J2 - num_J2 << endl;
138  }
139 
141  {
142  test_jacobs_P1DP2inv(
143  0, 0, 0, DEG2RAD(0), DEG2RAD(0), DEG2RAD(0), 0, 0, 0, DEG2RAD(0),
144  DEG2RAD(0), DEG2RAD(0), 0, 0, 0, DEG2RAD(0), DEG2RAD(0),
145  DEG2RAD(0));
146 
147  test_jacobs_P1DP2inv(
148  0, 0, 0, DEG2RAD(10), DEG2RAD(0), DEG2RAD(0), 0, 0, 0, DEG2RAD(10),
149  DEG2RAD(0), DEG2RAD(0), 0, 0, 0, DEG2RAD(20), DEG2RAD(0),
150  DEG2RAD(0));
151 
152  test_jacobs_P1DP2inv(
153  0, 0, 0, DEG2RAD(10), DEG2RAD(0), DEG2RAD(0), 0, 0, 0, DEG2RAD(12),
154  DEG2RAD(0), DEG2RAD(0), 0, 0, 0, DEG2RAD(20), DEG2RAD(0),
155  DEG2RAD(0));
156 
157  test_jacobs_P1DP2inv(
158  0, 0, 0, DEG2RAD(10), DEG2RAD(20), DEG2RAD(30), 0, 0, 0, DEG2RAD(4),
159  DEG2RAD(3), DEG2RAD(8), 0, 0, 0, DEG2RAD(15), DEG2RAD(25),
160  DEG2RAD(35));
161 
162  test_jacobs_P1DP2inv(
163  10, 20, 30, DEG2RAD(0), DEG2RAD(0), DEG2RAD(0), -5, -5, -5,
164  DEG2RAD(0), DEG2RAD(0), DEG2RAD(0), 5, 15, 25, DEG2RAD(0),
165  DEG2RAD(0), DEG2RAD(0));
166 
167  test_jacobs_P1DP2inv(
168  10, 20, 30, DEG2RAD(0), DEG2RAD(0), DEG2RAD(0), -5.2, -5.3, -4.9,
169  DEG2RAD(0), DEG2RAD(0), DEG2RAD(0), 5, 15, 25, DEG2RAD(0),
170  DEG2RAD(0), DEG2RAD(0));
171 
172  test_jacobs_P1DP2inv(
173  10, 20, 30, DEG2RAD(10), DEG2RAD(20), DEG2RAD(30), 4.7, 4.8, 5.3,
174  DEG2RAD(4), DEG2RAD(3), DEG2RAD(8), 15, 25, 35, DEG2RAD(15),
175  DEG2RAD(25), DEG2RAD(35));
176  }
177 };
178 
181 
182 TEST_F(SE3_traits_tests, SE3_jacobs) { do_all_jacobs_test(); }
183 TEST_F(SE2_traits_tests, SE2_jacobs) { do_all_jacobs_test(); }
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
INT32 z2
Definition: jidctint.cpp:130
virtual void SetUp()
mrpt::poses::SE_traits< POSE_TYPE::rotation_dimensions > SE_TYPE
TEST_F(SE3_traits_tests, SE3_jacobs)
STL namespace.
void jacob_numeric_estimate(const VECTORLIKE &x, std::function< void(const VECTORLIKE &x, const USERPARAM &y, VECTORLIKE3 &out)> functor, const VECTORLIKE2 &increments, const USERPARAM &userParam, MATRIXLIKE &out_Jacobian)
Numerical estimation of the Jacobian of a user-supplied function - this template redirects to mrpt::m...
Definition: jacobians.h:144
A numeric matrix of compile-time fixed size.
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
CONTAINER::Scalar sum(const CONTAINER &v)
Computes the sum of all the elements.
virtual void TearDown()
#define DEG2RAD
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
static void func_numeric(const CArrayDouble< 2 *SE_TYPE::VECTOR_SIZE > &x, const TParams &params, CArrayDouble< SE_TYPE::VECTOR_SIZE > &Y)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
SE_traits_tests< mrpt::poses::CPose3D > SE3_traits_tests
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
A helper class for SE(2) and SE(3) geometry-related transformations, on-manifold optimization Jacobia...
Definition: SE_traits.h:29
A partial specialization of CArrayNumeric for double numbers.
Definition: CArrayNumeric.h:87
void test_jacobs_P1DP2inv(double x1, double y1, double z1, double yaw1, double pitch1, double roll1, double xd, double yd, double zd, double yawd, double pitchd, double rolld, double x2, double y2, double z2, double yaw2, double pitch2, double roll2)
SE_traits_tests< mrpt::poses::CPose2D > SE2_traits_tests
GLenum GLint x
Definition: glext.h:3538
INT32 z1
Definition: jidctint.cpp:130
GLenum const GLfloat * params
Definition: glext.h:3534
CMatrixFixedNumeric< double, 4, 4 > CMatrixDouble44
Definition: eigen_frwds.h:56



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019