submap_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 
19 
20 #include <map>
21 #include <memory>
22 #include <set>
23 #include <string>
24 
29 #include "gmock/gmock.h"
30 
31 namespace cartographer {
32 namespace mapping {
33 namespace {
34 
35 TEST(Submap2DTest, TheRightNumberOfRangeDataAreInserted) {
36  constexpr int kNumRangeData = 10;
37  auto parameter_dictionary = common::MakeDictionary(
38  "return {"
39  "num_range_data = " +
40  std::to_string(kNumRangeData) +
41  ", "
42  "grid_options_2d = {"
43  "grid_type = \"PROBABILITY_GRID\","
44  "resolution = 0.05, "
45  "},"
46  "range_data_inserter = {"
47  "range_data_inserter_type = \"PROBABILITY_GRID_INSERTER_2D\","
48  "probability_grid_range_data_inserter = {"
49  "insert_free_space = true, "
50  "hit_probability = 0.53, "
51  "miss_probability = 0.495, "
52  "},"
53  "},"
54  "}");
55  ActiveSubmaps2D submaps{CreateSubmapsOptions2D(parameter_dictionary.get())};
56  std::set<std::shared_ptr<Submap2D>> all_submaps;
57  for (int i = 0; i != 1000; ++i) {
58  submaps.InsertRangeData({Eigen::Vector3f::Zero(), {}, {}});
59  // Except for the first, maps should only be returned after enough range
60  // data.
61  for (const auto& submap : submaps.submaps()) {
62  all_submaps.insert(submap);
63  }
64  if (submaps.matching_index() != 0) {
65  EXPECT_LE(kNumRangeData, submaps.submaps().front()->num_range_data());
66  }
67  }
68  int correct_num_range_data = 0;
69  for (const auto& submap : all_submaps) {
70  if (submap->num_range_data() == kNumRangeData * 2) {
71  ++correct_num_range_data;
72  }
73  }
74  // Submaps should not be left without the right number of range data in them.
75  EXPECT_EQ(correct_num_range_data, all_submaps.size() - 2);
76 }
77 
78 TEST(Submap2DTest, ToFromProto) {
79  MapLimits expected_map_limits(1., Eigen::Vector2d(2., 3.),
80  CellLimits(100, 110));
81  Submap2D expected(Eigen::Vector2f(4.f, 5.f),
82  common::make_unique<ProbabilityGrid>(expected_map_limits));
83  proto::Submap proto;
84  expected.ToProto(&proto, true /* include_probability_grid_data */);
85  EXPECT_TRUE(proto.has_submap_2d());
86  EXPECT_FALSE(proto.has_submap_3d());
87  const auto actual = Submap2D(proto.submap_2d());
88  EXPECT_TRUE(expected.local_pose().translation().isApprox(
89  actual.local_pose().translation(), 1e-6));
90  EXPECT_TRUE(expected.local_pose().rotation().isApprox(
91  actual.local_pose().rotation(), 1e-6));
92  EXPECT_EQ(expected.num_range_data(), actual.num_range_data());
93  EXPECT_EQ(expected.finished(), actual.finished());
94  EXPECT_NEAR(expected.grid()->limits().resolution(),
95  actual.grid()->limits().resolution(), 1e-6);
96  EXPECT_TRUE(expected.grid()->limits().max().isApprox(
97  actual.grid()->limits().max(), 1e-6));
98  EXPECT_EQ(expected.grid()->limits().cell_limits().num_x_cells,
99  actual.grid()->limits().cell_limits().num_x_cells);
100 }
101 
102 } // namespace
103 } // namespace mapping
104 } // namespace cartographer
proto::SubmapsOptions2D CreateSubmapsOptions2D(common::LuaParameterDictionary *const parameter_dictionary)
Definition: submap_2d.cc:35
std::unique_ptr< LuaParameterDictionary > MakeDictionary(const std::string &code)
TEST(TrajectoryConnectivityStateTest, UnknownTrajectory)


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