Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "cartographer/mapping/internal/constraints/constraint_builder_2d.h"
00018
00019 #include <functional>
00020
00021 #include "cartographer/common/internal/testing/thread_pool_for_testing.h"
00022 #include "cartographer/mapping/2d/probability_grid.h"
00023 #include "cartographer/mapping/2d/submap_2d.h"
00024 #include "cartographer/mapping/internal/constraints/constraint_builder.h"
00025 #include "cartographer/mapping/internal/testing/test_helpers.h"
00026 #include "gmock/gmock.h"
00027 #include "gtest/gtest.h"
00028
00029 namespace cartographer {
00030 namespace mapping {
00031 namespace constraints {
00032 namespace {
00033
00034 class MockCallback {
00035 public:
00036 MOCK_METHOD1(Run, void(const ConstraintBuilder2D::Result&));
00037 };
00038
00039 class ConstraintBuilder2DTest : public ::testing::Test {
00040 protected:
00041 void SetUp() override {
00042 auto constraint_builder_parameters = testing::ResolveLuaParameters(R"text(
00043 include "pose_graph.lua"
00044 POSE_GRAPH.constraint_builder.sampling_ratio = 1
00045 POSE_GRAPH.constraint_builder.min_score = 0
00046 POSE_GRAPH.constraint_builder.global_localization_min_score = 0
00047 return POSE_GRAPH.constraint_builder)text");
00048 constraint_builder_ = absl::make_unique<ConstraintBuilder2D>(
00049 CreateConstraintBuilderOptions(constraint_builder_parameters.get()),
00050 &thread_pool_);
00051 }
00052
00053 std::unique_ptr<ConstraintBuilder2D> constraint_builder_;
00054 MockCallback mock_;
00055 common::testing::ThreadPoolForTesting thread_pool_;
00056 };
00057
00058 TEST_F(ConstraintBuilder2DTest, CallsBack) {
00059 EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), 0);
00060 EXPECT_CALL(mock_, Run(::testing::IsEmpty()));
00061 constraint_builder_->NotifyEndOfNode();
00062 constraint_builder_->WhenDone(
00063 [this](const constraints::ConstraintBuilder2D::Result& result) {
00064 mock_.Run(result);
00065 });
00066 thread_pool_.WaitUntilIdle();
00067 EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), 1);
00068 }
00069
00070 TEST_F(ConstraintBuilder2DTest, FindsConstraints) {
00071 TrajectoryNode::Data node_data;
00072 node_data.filtered_gravity_aligned_point_cloud.push_back(
00073 {Eigen::Vector3f(0.1, 0.2, 0.3)});
00074 node_data.gravity_alignment = Eigen::Quaterniond::Identity();
00075 node_data.local_pose = transform::Rigid3d::Identity();
00076 SubmapId submap_id{0, 1};
00077 MapLimits map_limits(1., Eigen::Vector2d(2., 3.), CellLimits(100, 110));
00078 ValueConversionTables conversion_tables;
00079 Submap2D submap(
00080 Eigen::Vector2f(4.f, 5.f),
00081 absl::make_unique<ProbabilityGrid>(map_limits, &conversion_tables),
00082 &conversion_tables);
00083 int expected_nodes = 0;
00084 for (int i = 0; i < 2; ++i) {
00085 EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), expected_nodes);
00086 for (int j = 0; j < 2; ++j) {
00087 constraint_builder_->MaybeAddConstraint(submap_id, &submap, NodeId{0, 0},
00088 &node_data,
00089 transform::Rigid2d::Identity());
00090 }
00091 constraint_builder_->MaybeAddGlobalConstraint(submap_id, &submap,
00092 NodeId{0, 0}, &node_data);
00093 constraint_builder_->NotifyEndOfNode();
00094 thread_pool_.WaitUntilIdle();
00095 EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), ++expected_nodes);
00096 constraint_builder_->NotifyEndOfNode();
00097 thread_pool_.WaitUntilIdle();
00098 EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), ++expected_nodes);
00099 EXPECT_CALL(mock_,
00100 Run(::testing::AllOf(
00101 ::testing::SizeIs(3),
00102 ::testing::Each(::testing::Field(
00103 &PoseGraphInterface::Constraint::tag,
00104 PoseGraphInterface::Constraint::INTER_SUBMAP)))));
00105 constraint_builder_->WhenDone(
00106 [this](const constraints::ConstraintBuilder2D::Result& result) {
00107 mock_.Run(result);
00108 });
00109 thread_pool_.WaitUntilIdle();
00110 constraint_builder_->DeleteScanMatcher(submap_id);
00111 }
00112 }
00113
00114 }
00115 }
00116 }
00117 }