scan_matcher_test_utils.h
Go to the documentation of this file.
1 #ifndef SLAM_CTOR_TESTS_SCAN_MATCHER_TEST_UTILS_H_INCLUDED
2 #define SLAM_CTOR_TESTS_SCAN_MATCHER_TEST_UTILS_H_INCLUDED
3 
4 #include <limits>
5 #include <memory>
6 #include <gtest/gtest.h>
7 
8 #include "../mock_grid_cell.h"
9 #include "../../../src/utils/data_generation/map_primitives.h"
10 #include "../../../src/utils/data_generation/grid_map_patcher.h"
11 #include "../../../src/utils/data_generation/laser_scan_generator.h"
12 
13 #include "../../../src/core/scan_matchers/grid_scan_matcher.h"
14 #include "../../../src/core/scan_matchers/weighted_mean_point_probability_spe.h"
15 
16 
17 template<typename MapType>
18 class ScanMatcherTestBase : public ::testing::Test {
19 protected: // type aliases
21 protected: // consts
22  static constexpr RobotPoseDelta Acceptable_Error = {
23  std::numeric_limits<double>::epsilon(),
24  std::numeric_limits<double>::epsilon(),
25  std::numeric_limits<double>::epsilon()
26  };
27 protected: // methods
28 
29  ScanMatcherTestBase(std::shared_ptr<ScanProbabilityEstimator> prob_est,
30  int map_w, int map_h, double map_scale,
31  const LaserScannerParams &dflt_lsp)
32  : map{std::make_shared<MockGridCell>(), {map_w, map_h, map_scale}}
33  , rpose{map.scale() / 2, map.scale() / 2, 0}
34  , spe{prob_est}
35  , default_lsp{dflt_lsp} {}
36 
38  const DiscretePoint2D &offset,
39  int w_scale, int h_scale) {
41  offset, w_scale, h_scale);
42  }
43 
44  virtual GridScanMatcher& scan_matcher() = 0;
46 
47  virtual bool is_result_noise_acceptable(const TransformedLaserScan &raw_scan,
48  const RobotPoseDelta &init_noise,
49  const RobotPoseDelta &noise) {
50  auto scan = spe->filter_scan(raw_scan.scan, rpose, map);
51  auto no_noise_prob = spe->estimate_scan_probability(scan, rpose, map);
52  auto noise_prob = spe->estimate_scan_probability(scan, rpose + noise, map);
53  //std::cout << no_noise_prob << " vs " << noise_prob << std::endl;
54  return are_equal(no_noise_prob, noise_prob);
55  }
56 
58  const RobotPoseDelta &noise,
59  const RobotPoseDelta &acc_error) {
60  auto tr_scan = TransformedLaserScan{};
62  tr_scan.scan = LaserScanGenerator{lsp}.laser_scan_2D(map, rpose, 1);
63  tr_scan.quality = 1.0;
64 
65  ASSERT_TRUE(tr_scan.scan.points().size() != 0);
66 
67  auto correction = RobotPoseDelta{};
68  auto original_map_scale = map.scale();
69  scan_matcher().process_scan(tr_scan, rpose + noise, map, correction);
70  assert(map.scale() == original_map_scale);
71  auto result_noise = noise + correction;
72  if (is_result_noise_acceptable(tr_scan, noise, result_noise)) {
73  return;
74  }
75 
76  // OR scan probability is the same as actual
77  ASSERT_NEAR(0, std::abs(result_noise.x), acc_error.x);
78  ASSERT_NEAR(0, std::abs(result_noise.y), acc_error.y);
79  ASSERT_NEAR(0, std::abs(result_noise.theta), acc_error.theta);
80  }
81 
82  void test_scan_matcher(const RobotPoseDelta &noise,
83  const RobotPoseDelta &acc_error) {
84  test_scan_matcher(default_lsp, noise, acc_error);
85  }
86 
87  void test_scan_matcher(const RobotPoseDelta &noise) {
89  }
90 
91 protected: // fields
92  MapType map;
94  std::shared_ptr<ScanProbabilityEstimator> spe;
96 };
97 
98 #endif
void test_scan_matcher(const RobotPoseDelta &noise)
CONSTEXPR bool are_equal(const T &a, const T &b, const T &eps)
Definition: math_utils.h:17
double theta
Definition: robot_pose.h:131
ScanMatcherTestBase(std::shared_ptr< ScanProbabilityEstimator > prob_est, int map_w, int map_h, double map_scale, const LaserScannerParams &dflt_lsp)
double theta
Definition: robot_pose.h:51
std::istream & to_stream() const override
virtual RobotPoseDelta default_acceptable_error()
void test_scan_matcher(const LaserScannerParams &lsp, const RobotPoseDelta &noise, const RobotPoseDelta &acc_error)
LaserScannerParams default_lsp
virtual double process_scan(const TransformedLaserScan &scan, const RobotPose &init_pose, const GridMap &map, RobotPoseDelta &pose_delta)=0
virtual void add_primitive_to_map(const TextRasterMapPrimitive &mp, const DiscretePoint2D &offset, int w_scale, int h_scale)
void apply_text_raster(MapType &dst_map, std::istream &src_raster, const DiscretePoint2D &dst_offset, int w_zoom=1, int h_zoom=1)
virtual bool is_result_noise_acceptable(const TransformedLaserScan &raw_scan, const RobotPoseDelta &init_noise, const RobotPoseDelta &noise)
RobotPoseDelta pose_delta
Definition: sensor_data.h:177
std::shared_ptr< ScanProbabilityEstimator > spe
static constexpr RobotPoseDelta Acceptable_Error
double y
Definition: robot_pose.h:131
virtual GridScanMatcher & scan_matcher()=0
void test_scan_matcher(const RobotPoseDelta &noise, const RobotPoseDelta &acc_error)
double x
Definition: robot_pose.h:131


slam_constructor
Author(s): JetBrains Research, OSLL team
autogenerated on Mon Jun 10 2019 15:08:25