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


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