MRPT  2.0.4
CAtan2LookUpTable_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <gtest/gtest.h>
11 #include <mrpt/core/bits_math.h> // DEG2RAD
13 #include <mrpt/random.h>
14 #include <cmath>
15 
16 template <class LUT_CLASS>
18  const LUT_CLASS& atan2lut, const double SIZE, const double max_deg_errors,
19  const double skip_area)
20 {
21  for (int i = 0; i < 1000; i++)
22  {
24  -.5 * SIZE, .5 * SIZE);
26  -.5 * SIZE, .5 * SIZE);
27 
28  // Avoid the central part, where accuracy is worse
29  if (std::abs(x) < skip_area || std::abs(y) < skip_area) continue;
30 
31  const double atan2_good = ::atan2(y, x);
32  double atan2_lut = .0;
33  bool atan2_lut_valid = atan2lut.atan2(y, x, atan2_lut);
34 
35  EXPECT_TRUE(atan2_lut_valid);
36  EXPECT_LT(
37  std::abs(atan2_good - atan2_lut), mrpt::DEG2RAD(max_deg_errors))
38  << "(x,y): (" << x << " , " << y << ")"
39  << "\natan2_good:" << atan2_good << " atan2_lut:" << atan2_lut
40  << std::endl;
41  }
42 }
43 
44 TEST(CAtan2LookUpTable, ValidValidTest)
45 {
46  const double SIZE = 20.0;
47  const double RES = 0.10;
49  -.5 * SIZE, .5 * SIZE, -.5 * SIZE, .5 * SIZE, RES);
50  atan2_lut_test(atan2lut, SIZE, 1.5 /*max error*/, 2.0 /* skip zone */);
51 }
52 
53 TEST(CAtan2LookUpTable, MultiResTest)
54 {
55  const double SIZE = 20.0;
57 
58  std::map<double, double> res2extension;
59  res2extension[0.001] = 0.8; // 0.1 cm resolution
60  res2extension[0.01] = 2.0; // 1.0 cm resolution
61  res2extension[0.02] = 5.0; // 2.0 cm resolution
62  res2extension[0.05] = 11.0; // 5.0 cm resolution
63  atan2lut.resize(res2extension);
64 
65  atan2_lut_test(atan2lut, SIZE, 0.5 /*max error*/, 0.4 /* skip zone */);
66 }
EXPECT_LT(out.final_rmse, 3.0)
EXPECT_TRUE(mrpt::system::fileExists(ini_fil))
TEST(CAtan2LookUpTable, ValidValidTest)
void resize(const std::map< double, double > &lst_resolutions2extensions) noexcept
See CAtan2LookUpTableMultiRes for a discussion of the parameters.
A look-up-table (LUT) of atan values for any (x,y) value in a square/rectangular grid of predefined r...
return_t drawUniform(const double Min, const double Max)
Generate a uniformly distributed pseudo-random number using the MT19937 algorithm, scaled to the selected range.
constexpr double DEG2RAD(const double x)
Degrees to radians.
Like CAtan2LookUpTable but with a multiresolution grid for increasingly better accuracy in points nea...
void atan2_lut_test(const LUT_CLASS &atan2lut, const double SIZE, const double max_deg_errors, const double skip_area)
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020