constraint_builder_2d_test.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2018 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 <functional>
21 
26 #include "gmock/gmock.h"
27 #include "gtest/gtest.h"
28 
29 namespace cartographer {
30 namespace mapping {
31 namespace constraints {
32 namespace {
33 
34 class MockCallback {
35  public:
36  MOCK_METHOD1(Run, void(const ConstraintBuilder2D::Result&));
37 };
38 
39 class ConstraintBuilder2DTest : public ::testing::Test {
40  protected:
41  void SetUp() override {
42  auto constraint_builder_parameters = test::ResolveLuaParameters(R"text(
43  include "pose_graph.lua"
44  POSE_GRAPH.constraint_builder.sampling_ratio = 1
45  POSE_GRAPH.constraint_builder.min_score = 0
46  POSE_GRAPH.constraint_builder.global_localization_min_score = 0
47  return POSE_GRAPH.constraint_builder)text");
48  constraint_builder_ = common::make_unique<ConstraintBuilder2D>(
49  CreateConstraintBuilderOptions(constraint_builder_parameters.get()),
50  &thread_pool_);
51  }
52 
53  std::unique_ptr<ConstraintBuilder2D> constraint_builder_;
54  MockCallback mock_;
55  common::testing::ThreadPoolForTesting thread_pool_;
56 };
57 
58 TEST_F(ConstraintBuilder2DTest, CallsBack) {
59  EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), 0);
60  EXPECT_CALL(mock_, Run(testing::IsEmpty()));
61  constraint_builder_->NotifyEndOfNode();
62  constraint_builder_->WhenDone(
63  std::bind(&MockCallback::Run, &mock_, std::placeholders::_1));
64  thread_pool_.WaitUntilIdle();
65  EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), 1);
66 }
67 
68 TEST_F(ConstraintBuilder2DTest, FindsConstraints) {
69  TrajectoryNode::Data node_data;
70  node_data.filtered_gravity_aligned_point_cloud.push_back(
71  Eigen::Vector3f(0.1, 0.2, 0.3));
72  node_data.gravity_alignment = Eigen::Quaterniond::Identity();
73  node_data.local_pose = transform::Rigid3d::Identity();
74  SubmapId submap_id{0, 1};
75  MapLimits map_limits(1., Eigen::Vector2d(2., 3.), CellLimits(100, 110));
76  Submap2D submap(Eigen::Vector2f(4.f, 5.f),
77  common::make_unique<ProbabilityGrid>(map_limits));
78  int expected_nodes = 0;
79  for (int i = 0; i < 2; ++i) {
80  EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), expected_nodes);
81  for (int j = 0; j < 2; ++j) {
82  constraint_builder_->MaybeAddConstraint(submap_id, &submap, NodeId{},
83  &node_data,
85  }
86  constraint_builder_->MaybeAddGlobalConstraint(submap_id, &submap, NodeId{},
87  &node_data);
88  constraint_builder_->NotifyEndOfNode();
89  thread_pool_.WaitUntilIdle();
90  EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), ++expected_nodes);
91  constraint_builder_->NotifyEndOfNode();
92  thread_pool_.WaitUntilIdle();
93  EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), ++expected_nodes);
94  EXPECT_CALL(mock_,
95  Run(testing::AllOf(
96  testing::SizeIs(3),
97  testing::Each(testing::Field(
100  constraint_builder_->WhenDone(
101  std::bind(&MockCallback::Run, &mock_, std::placeholders::_1));
102  thread_pool_.WaitUntilIdle();
103  constraint_builder_->DeleteScanMatcher(submap_id);
104  }
105 }
106 
107 } // namespace
108 } // namespace constraints
109 } // namespace mapping
110 } // namespace cartographer
common::testing::ThreadPoolForTesting thread_pool_
MockCallback mock_
std::unique_ptr< ConstraintBuilder2D > constraint_builder_
enum cartographer::mapping::PoseGraphInterface::Constraint::Tag tag
static Rigid2< FloatType > Identity()
proto::ConstraintBuilderOptions CreateConstraintBuilderOptions(common::LuaParameterDictionary *const parameter_dictionary)
void Run(const std::string &configuration_directory, const std::string &configuration_basename)
std::unique_ptr<::cartographer::common::LuaParameterDictionary > ResolveLuaParameters(const std::string &lua_code)


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