mapping_3d/scan_matching/fast_correlative_scan_matcher_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 <algorithm>
20 #include <cmath>
21 #include <random>
22 #include <string>
23 
28 #include "gtest/gtest.h"
29 
30 namespace cartographer {
31 namespace mapping_3d {
32 namespace scan_matching {
33 namespace {
34 
35 proto::FastCorrelativeScanMatcherOptions
36 CreateFastCorrelativeScanMatcherTestOptions(const int branch_and_bound_depth) {
37  auto parameter_dictionary = common::MakeDictionary(
38  "return {"
39  "branch_and_bound_depth = " +
40  std::to_string(branch_and_bound_depth) +
41  ", "
42  "full_resolution_depth = " +
43  std::to_string(branch_and_bound_depth) +
44  ", "
45  "rotational_histogram_size = 30, "
46  "min_rotational_score = 0.1, "
47  "linear_xy_search_window = 0.8, "
48  "linear_z_search_window = 0.8, "
49  "angular_search_window = 0.3, "
50  "}");
51  return CreateFastCorrelativeScanMatcherOptions(parameter_dictionary.get());
52 }
53 
54 mapping_3d::proto::RangeDataInserterOptions
55 CreateRangeDataInserterTestOptions() {
56  auto parameter_dictionary = common::MakeDictionary(
57  "return { "
58  "hit_probability = 0.7, "
59  "miss_probability = 0.4, "
60  "num_free_space_voxels = 5, "
61  "}");
62  return CreateRangeDataInserterOptions(parameter_dictionary.get());
63 }
64 
65 TEST(FastCorrelativeScanMatcherTest, CorrectPose) {
66  std::mt19937 prng(42);
67  std::uniform_real_distribution<float> distribution(-1.f, 1.f);
68  RangeDataInserter range_data_inserter(CreateRangeDataInserterTestOptions());
69  constexpr float kMinScore = 0.1f;
70  const auto options = CreateFastCorrelativeScanMatcherTestOptions(5);
71 
72  sensor::PointCloud point_cloud{
73  Eigen::Vector3f(4.f, 0.f, 0.f), Eigen::Vector3f(4.5f, 0.f, 0.f),
74  Eigen::Vector3f(5.f, 0.f, 0.f), Eigen::Vector3f(5.5f, 0.f, 0.f),
75  Eigen::Vector3f(0.f, 4.f, 0.f), Eigen::Vector3f(0.f, 4.5f, 0.f),
76  Eigen::Vector3f(0.f, 5.f, 0.f), Eigen::Vector3f(0.f, 5.5f, 0.f),
77  Eigen::Vector3f(0.f, 0.f, 4.f), Eigen::Vector3f(0.f, 0.f, 4.5f),
78  Eigen::Vector3f(0.f, 0.f, 5.f), Eigen::Vector3f(0.f, 0.f, 5.5f)};
79 
80  for (int i = 0; i != 20; ++i) {
81  const float x = 0.7f * distribution(prng);
82  const float y = 0.7f * distribution(prng);
83  const float z = 0.7f * distribution(prng);
84  const float theta = 0.2f * distribution(prng);
85  const auto expected_pose =
86  transform::Rigid3f::Translation(Eigen::Vector3f(x, y, z)) *
88  Eigen::AngleAxisf(theta, Eigen::Vector3f::UnitZ()));
89 
90  HybridGrid hybrid_grid(0.05f);
91  hybrid_grid.StartUpdate();
92  range_data_inserter.Insert(
93  sensor::RangeData{
94  expected_pose.translation(),
95  sensor::TransformPointCloud(point_cloud, expected_pose),
96  {}},
97  &hybrid_grid);
98 
99  FastCorrelativeScanMatcher fast_correlative_scan_matcher(hybrid_grid, {},
100  options);
101  transform::Rigid3d pose_estimate;
102  float score;
103  EXPECT_TRUE(fast_correlative_scan_matcher.Match(
104  transform::Rigid3d::Identity(), point_cloud, point_cloud, kMinScore,
105  &score, &pose_estimate));
106  EXPECT_LT(kMinScore, score);
107  EXPECT_THAT(expected_pose,
108  transform::IsNearly(pose_estimate.cast<float>(), 0.05f))
109  << "Actual: " << transform::ToProto(pose_estimate).DebugString()
110  << "\nExpected: " << transform::ToProto(expected_pose).DebugString();
111  }
112 }
113 
114 } // namespace
115 } // namespace scan_matching
116 } // namespace mapping_3d
117 } // namespace cartographer
proto::FastCorrelativeScanMatcherOptions CreateFastCorrelativeScanMatcherOptions(common::LuaParameterDictionary *const parameter_dictionary)
PointCloud TransformPointCloud(const PointCloud &point_cloud, const transform::Rigid3f &transform)
Definition: point_cloud.cc:25
static Rigid3 Rotation(const AngleAxis &angle_axis)
proto::RangeDataInserterOptions CreateRangeDataInserterOptions(common::LuaParameterDictionary *parameter_dictionary)
Rigid3< double > Rigid3d
std::unique_ptr< LuaParameterDictionary > MakeDictionary(const string &code)
proto::Rigid2d ToProto(const transform::Rigid2d &transform)
Definition: transform.cc:44
std::vector< Eigen::Vector3f > PointCloud
Definition: point_cloud.h:30
static Rigid3 Translation(const Vector &vector)


cartographer
Author(s):
autogenerated on Wed Jun 5 2019 21:57:58