mapping_2d/scan_matching/ceres_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 <memory>
20 
27 #include "gtest/gtest.h"
28 
29 namespace cartographer {
30 namespace mapping_2d {
31 namespace scan_matching {
32 namespace {
33 
34 class CeresScanMatcherTest : public ::testing::Test {
35  protected:
36  CeresScanMatcherTest()
38  MapLimits(1., Eigen::Vector2d(10., 10.), CellLimits(20, 20))) {
39  probability_grid_.SetProbability(
40  probability_grid_.limits().GetXYIndexOfCellContainingPoint(-3.5, 2.5),
42 
43  point_cloud_.emplace_back(-3.f, 2.f, 0.f);
44 
45  auto parameter_dictionary = common::MakeDictionary(R"text(
46  return {
47  occupied_space_weight = 1.,
48  translation_weight = 0.1,
49  rotation_weight = 1.5,
50  ceres_solver_options = {
51  use_nonmonotonic_steps = true,
52  max_num_iterations = 50,
53  num_threads = 1,
54  },
55  })text");
56  const proto::CeresScanMatcherOptions options =
57  CreateCeresScanMatcherOptions(parameter_dictionary.get());
58  ceres_scan_matcher_ = common::make_unique<CeresScanMatcher>(options);
59  }
60 
61  void TestFromInitialPose(const transform::Rigid2d& initial_pose) {
63  const transform::Rigid2d expected_pose =
65  ceres::Solver::Summary summary;
66  ceres_scan_matcher_->Match(initial_pose, initial_pose, point_cloud_,
67  probability_grid_, &pose, &summary);
68  EXPECT_NEAR(0., summary.final_cost, 1e-2) << summary.FullReport();
69  EXPECT_THAT(pose, transform::IsNearly(expected_pose, 1e-2))
70  << "Actual: " << transform::ToProto(pose).DebugString()
71  << "\nExpected: " << transform::ToProto(expected_pose).DebugString();
72  }
73 
74  ProbabilityGrid probability_grid_;
76  std::unique_ptr<CeresScanMatcher> ceres_scan_matcher_;
77 };
78 
79 TEST_F(CeresScanMatcherTest, testPerfectEstimate) {
80  TestFromInitialPose(transform::Rigid2d::Translation({-0.5, 0.5}));
81 }
82 
83 TEST_F(CeresScanMatcherTest, testOptimizeAlongX) {
84  TestFromInitialPose(transform::Rigid2d::Translation({-0.3, 0.5}));
85 }
86 
87 TEST_F(CeresScanMatcherTest, testOptimizeAlongY) {
88  TestFromInitialPose(transform::Rigid2d::Translation({-0.45, 0.3}));
89 }
90 
91 TEST_F(CeresScanMatcherTest, testOptimizeAlongXY) {
92  TestFromInitialPose(transform::Rigid2d::Translation({-0.3, 0.3}));
93 }
94 
95 } // namespace
96 } // namespace scan_matching
97 } // namespace mapping_2d
98 } // namespace cartographer
transform::Rigid3d pose
constexpr float kMaxProbability
Rigid2< double > Rigid2d
std::unique_ptr< LuaParameterDictionary > MakeDictionary(const string &code)
proto::Rigid2d ToProto(const transform::Rigid2d &transform)
Definition: transform.cc:44
proto::CeresScanMatcherOptions CreateCeresScanMatcherOptions(common::LuaParameterDictionary *const parameter_dictionary)
std::vector< Eigen::Vector3f > PointCloud
Definition: point_cloud.h:30
static Rigid2 Translation(const Vector &vector)
std::unique_ptr< CeresScanMatcher > ceres_scan_matcher_


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