real_time_correlative_scan_matcher_2d_test.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2016 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #include <cmath>
20 #include <memory>
21 
22 #include "Eigen/Geometry"
30 #include "gtest/gtest.h"
31 
32 namespace cartographer {
33 namespace mapping {
34 namespace scan_matching {
35 namespace {
36 
37 class RealTimeCorrelativeScanMatcherTest : public ::testing::Test {
38  protected:
39  RealTimeCorrelativeScanMatcherTest()
41  MapLimits(0.05, Eigen::Vector2d(0.05, 0.25), CellLimits(6, 6))) {
42  {
43  auto parameter_dictionary = common::MakeDictionary(
44  "return { "
45  "insert_free_space = true, "
46  "hit_probability = 0.7, "
47  "miss_probability = 0.4, "
48  "}");
50  common::make_unique<ProbabilityGridRangeDataInserter2D>(
52  parameter_dictionary.get()));
53  }
54  point_cloud_.emplace_back(0.025f, 0.175f, 0.f);
55  point_cloud_.emplace_back(-0.025f, 0.175f, 0.f);
56  point_cloud_.emplace_back(-0.075f, 0.175f, 0.f);
57  point_cloud_.emplace_back(-0.125f, 0.175f, 0.f);
58  point_cloud_.emplace_back(-0.125f, 0.125f, 0.f);
59  point_cloud_.emplace_back(-0.125f, 0.075f, 0.f);
60  point_cloud_.emplace_back(-0.125f, 0.025f, 0.f);
61  range_data_inserter_->Insert(
62  sensor::RangeData{Eigen::Vector3f::Zero(), point_cloud_, {}},
64  probability_grid_.FinishUpdate();
65  {
66  auto parameter_dictionary = common::MakeDictionary(
67  "return {"
68  "linear_search_window = 0.6, "
69  "angular_search_window = 0.16, "
70  "translation_delta_cost_weight = 0., "
71  "rotation_delta_cost_weight = 0., "
72  "}");
74  common::make_unique<RealTimeCorrelativeScanMatcher2D>(
76  parameter_dictionary.get()));
77  }
78  }
79 
80  ProbabilityGrid probability_grid_;
81  std::unique_ptr<ProbabilityGridRangeDataInserter2D> range_data_inserter_;
83  std::unique_ptr<RealTimeCorrelativeScanMatcher2D>
85 };
86 
87 TEST_F(RealTimeCorrelativeScanMatcherTest,
88  ScorePerfectHighResolutionCandidate) {
89  const std::vector<sensor::PointCloud> scans =
90  GenerateRotatedScans(point_cloud_, SearchParameters(0, 0, 0., 0.));
91  const std::vector<DiscreteScan2D> discrete_scans = DiscretizeScans(
92  probability_grid_.limits(), scans, Eigen::Translation2f::Identity());
93  std::vector<Candidate2D> candidates;
94  candidates.emplace_back(0, 0, 0, SearchParameters(0, 0, 0., 0.));
95  real_time_correlative_scan_matcher_->ScoreCandidates(
96  probability_grid_, discrete_scans, SearchParameters(0, 0, 0., 0.),
97  &candidates);
98  EXPECT_EQ(0, candidates[0].scan_index);
99  EXPECT_EQ(0, candidates[0].x_index_offset);
100  EXPECT_EQ(0, candidates[0].y_index_offset);
101  // Every point should align perfectly.
102  EXPECT_NEAR(0.7, candidates[0].score, 1e-2);
103 }
104 
105 TEST_F(RealTimeCorrelativeScanMatcherTest,
106  ScorePartiallyCorrectHighResolutionCandidate) {
107  const std::vector<sensor::PointCloud> scans =
108  GenerateRotatedScans(point_cloud_, SearchParameters(0, 0, 0., 0.));
109  const std::vector<DiscreteScan2D> discrete_scans = DiscretizeScans(
110  probability_grid_.limits(), scans, Eigen::Translation2f::Identity());
111  std::vector<Candidate2D> candidates;
112  candidates.emplace_back(0, 0, 1, SearchParameters(0, 0, 0., 0.));
113  real_time_correlative_scan_matcher_->ScoreCandidates(
114  probability_grid_, discrete_scans, SearchParameters(0, 0, 0., 0.),
115  &candidates);
116  EXPECT_EQ(0, candidates[0].scan_index);
117  EXPECT_EQ(0, candidates[0].x_index_offset);
118  EXPECT_EQ(1, candidates[0].y_index_offset);
119  // 3 points should align perfectly.
120  EXPECT_LT(0.7 * 3. / 7., candidates[0].score);
121  EXPECT_GT(0.7, candidates[0].score);
122 }
123 
124 } // namespace
125 } // namespace scan_matching
126 } // namespace mapping
127 } // namespace cartographer
std::vector< DiscreteScan2D > DiscretizeScans(const MapLimits &map_limits, const std::vector< sensor::PointCloud > &scans, const Eigen::Translation2f &initial_translation)
proto::ProbabilityGridRangeDataInserterOptions2D CreateProbabilityGridRangeDataInserterOptions2D(common::LuaParameterDictionary *parameter_dictionary)
std::unique_ptr< LuaParameterDictionary > MakeDictionary(const std::string &code)
sensor::PointCloud point_cloud_
std::vector< sensor::PointCloud > GenerateRotatedScans(const sensor::PointCloud &point_cloud, const SearchParameters &search_parameters)
std::vector< Eigen::Vector3f > PointCloud
Definition: point_cloud.h:32
std::unique_ptr< ProbabilityGridRangeDataInserter2D > range_data_inserter_
ProbabilityGrid probability_grid_
std::unique_ptr< RealTimeCorrelativeScanMatcher2D > real_time_correlative_scan_matcher_
proto::RealTimeCorrelativeScanMatcherOptions CreateRealTimeCorrelativeScanMatcherOptions(common::LuaParameterDictionary *const parameter_dictionary)


cartographer
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:00:58