Main MRPT website > C++ reference for MRPT 1.9.9
SO_SE_average_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-2018, 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 
11 #include <mrpt/math/wrap2pi.h>
12 #include <gtest/gtest.h>
13 
14 using namespace mrpt;
15 using namespace mrpt::poses;
16 
17 using namespace mrpt::math;
18 using namespace std;
19 
21  const double* angs, const size_t N, const double ang_correct_avr)
22 {
23  SO_average<2> so_avr;
24  for (size_t i = 0; i < N; i++) so_avr.append(angs[i]);
25  const double calc_avr = so_avr.get_average();
26  EXPECT_NEAR(mrpt::math::wrapToPi(ang_correct_avr - calc_avr), .0, 1e-6);
27 }
28 
29 TEST(SE2_SE3_avrg, SO2_average)
30 {
31  // Simple tests:
32  {
33  const double angs[] = {.1};
34  const double ang_correct_avr = .1;
36  angs, sizeof(angs) / sizeof(angs[0]), ang_correct_avr);
37  }
38  {
39  const double angs[] = {.0, M_PI};
40  const double ang_correct_avr = .5 * M_PI;
42  angs, sizeof(angs) / sizeof(angs[0]), ang_correct_avr);
43  }
44  {
45  const double angs[] = {-0.75 * M_PI, 0.75 * M_PI};
46  const double ang_correct_avr = 1.0 * M_PI;
48  angs, sizeof(angs) / sizeof(angs[0]), ang_correct_avr);
49  }
50  {
51  const double angs[] = {-0.75 * M_PI, 0.75 * M_PI, 0.3 * M_PI};
52  // const double angs_w[] = {1.0, 1.0, 0.1 };
53  const double ang_correct_avr = 2.3668403111754515;
55  angs, sizeof(angs) / sizeof(angs[0]), ang_correct_avr);
56  }
57  // Test launching an exception when there is no data:
58  {
59  const double dummy[] = {0.};
60  try
61  {
62  run_test_so2_avrg(dummy, 0, 0);
63  GTEST_FAIL()
64  << "An exception should have been raised before this point!!";
65  }
66  catch (std::exception&)
67  {
68  // This error is expected, it's OK.
69  }
70  }
71 }
72 
74  const double* angs, const size_t N,
75  const mrpt::math::CMatrixDouble33 correct_avr)
76 {
77  SO_average<3> so_avr;
78  for (size_t i = 0; i < N; i++)
79  {
81  0, 0, 0, angs[3 * i + 0], angs[3 * i + 1], angs[3 * i + 2]);
82  so_avr.append(rot.getRotationMatrix());
83  }
84  Eigen::Matrix3d calc_avr = so_avr.get_average();
85  EXPECT_NEAR((correct_avr - calc_avr).array().abs().sum(), .0, 1e-5);
86 }
87 
88 TEST(SE2_SE3_avrg, SO3_average)
89 {
90  // Simple tests:
91  {
92  const double angs[] = {.0, .0, .0};
93  const auto correct_avr =
94  mrpt::poses::CPose3D(0, 0, 0, 0, 0, 0).getRotationMatrix();
96  angs, sizeof(angs) / (3 * sizeof(angs[0])), correct_avr);
97  }
98  {
99  const double angs[] = {-.75 * M_PI, .0, .0, .75 * M_PI, .0, .0};
100  const auto correct_avr =
101  mrpt::poses::CPose3D(0, 0, 0, M_PI, 0, 0).getRotationMatrix();
103  angs, sizeof(angs) / (3 * sizeof(angs[0])), correct_avr);
104  }
105  {
106  const double angs[] = {.0, -0.2, .0, .0, 0.2, .0};
107  const auto correct_avr =
108  mrpt::poses::CPose3D(0, 0, 0, 0, 0, 0).getRotationMatrix();
110  angs, sizeof(angs) / (3 * sizeof(angs[0])), correct_avr);
111  }
112  {
113  const double angs[] = {.0, .0, .3, .0, .0, -.3};
114  const auto correct_avr =
115  mrpt::poses::CPose3D(0, 0, 0, 0, 0, 0).getRotationMatrix();
117  angs, sizeof(angs) / (3 * sizeof(angs[0])), correct_avr);
118  }
119 }
mrpt::math::sum
CONTAINER::Scalar sum(const CONTAINER &v)
Computes the sum of all the elements.
Definition: ops_containers.h:211
TEST
TEST(SE2_SE3_avrg, SO2_average)
Definition: SO_SE_average_unittest.cpp:29
mrpt::poses::SO_average< 2 >::get_average
double get_average() const
Returns the average orientation (radians).
mrpt::poses::SO_average< 3 >::get_average
Eigen::Matrix3d get_average() const
Returns the average orientation.
wrap2pi.h
mrpt::poses::CPose3D::getRotationMatrix
void getRotationMatrix(mrpt::math::CMatrixDouble33 &ROT) const
Get the 3x3 rotation matrix.
Definition: CPose3D.h:232
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::poses::SO_average< 3 >::append
void append(const Eigen::Matrix3d &M)
Adds a new orientation to the computation.
mrpt::poses
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CHierarchicalMapMHPartition.h:25
mrpt::poses::SO_average< 2 >::append
void append(const double orientation_rad)
Adds a new orientation (radians) to the computation.
mrpt::poses::SO_average< 2 >
Computes weighted and un-weighted averages of SO(2) orientations.
Definition: SO_SE_average.h:44
M_PI
#define M_PI
Definition: core/include/mrpt/core/bits_math.h:38
mrpt::math::wrapToPi
T wrapToPi(T a)
Modifies the given angle to translate it into the ]-pi,pi] range.
Definition: wrap2pi.h:53
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
mrpt::math::CMatrixFixedNumeric< double, 3, 3 >
run_test_so2_avrg
void run_test_so2_avrg(const double *angs, const size_t N, const double ang_correct_avr)
Definition: SO_SE_average_unittest.cpp:20
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13
mrpt::poses::SO_average< 3 >
Computes weighted and un-weighted averages of SO(3) orientations.
Definition: SO_SE_average.h:86
SO_SE_average.h
run_test_so3_avrg
void run_test_so3_avrg(const double *angs, const size_t N, const mrpt::math::CMatrixDouble33 correct_avr)
Definition: SO_SE_average_unittest.cpp:73



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST