real_time_correlative_scan_matcher_3d_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 
21 #include "Eigen/Core"
29 #include "gtest/gtest.h"
30 
31 namespace cartographer {
32 namespace mapping {
33 namespace scan_matching {
34 namespace {
35 
36 class RealTimeCorrelativeScanMatcher3DTest : public ::testing::Test {
37  protected:
38  RealTimeCorrelativeScanMatcher3DTest()
39  : hybrid_grid_(0.1f),
40  expected_pose_(Eigen::Vector3d(-1., 0., 0.),
41  Eigen::Quaterniond::Identity()) {
42  for (const Eigen::Vector3f& point :
43  {Eigen::Vector3f(-3.f, 2.f, 0.f), Eigen::Vector3f(-4.f, 2.f, 0.f),
44  Eigen::Vector3f(-5.f, 2.f, 0.f), Eigen::Vector3f(-6.f, 2.f, 0.f),
45  Eigen::Vector3f(-6.f, 3.f, 1.f), Eigen::Vector3f(-6.f, 4.f, 2.f),
46  Eigen::Vector3f(-7.f, 3.f, 1.f)}) {
47  point_cloud_.push_back(point);
48  hybrid_grid_.SetProbability(
49  hybrid_grid_.GetCellIndex(expected_pose_.cast<float>() * point), 1.);
50  }
51 
52  auto parameter_dictionary = common::MakeDictionary(R"text(
53  return {
54  linear_search_window = 0.3,
55  angular_search_window = math.rad(1.),
56  translation_delta_cost_weight = 1e-1,
57  rotation_delta_cost_weight = 1.,
58  })text");
60  new RealTimeCorrelativeScanMatcher3D(
62  parameter_dictionary.get())));
63  }
64 
65  void TestFromInitialPose(const transform::Rigid3d& initial_pose) {
67 
68  const float score = real_time_correlative_scan_matcher_->Match(
69  initial_pose, point_cloud_, hybrid_grid_, &pose);
70  LOG(INFO) << "Score: " << score;
71  EXPECT_THAT(pose, transform::IsNearly(expected_pose_, 1e-3));
72  }
73 
74  HybridGrid hybrid_grid_;
77  std::unique_ptr<RealTimeCorrelativeScanMatcher3D>
79 };
80 
81 TEST_F(RealTimeCorrelativeScanMatcher3DTest, PerfectEstimate) {
82  TestFromInitialPose(
83  transform::Rigid3d::Translation(Eigen::Vector3d(-1., 0., 0.)));
84 }
85 
86 TEST_F(RealTimeCorrelativeScanMatcher3DTest, AlongX) {
87  TestFromInitialPose(
88  transform::Rigid3d::Translation(Eigen::Vector3d(-0.8, 0., 0.)));
89 }
90 
91 TEST_F(RealTimeCorrelativeScanMatcher3DTest, AlongZ) {
92  TestFromInitialPose(
93  transform::Rigid3d::Translation(Eigen::Vector3d(-1., 0., -0.2)));
94 }
95 
96 TEST_F(RealTimeCorrelativeScanMatcher3DTest, AlongXYZ) {
97  TestFromInitialPose(
98  transform::Rigid3d::Translation(Eigen::Vector3d(-0.9, -0.2, 0.2)));
99 }
100 
101 TEST_F(RealTimeCorrelativeScanMatcher3DTest, RotationAroundX) {
102  TestFromInitialPose(transform::Rigid3d(
103  Eigen::Vector3d(-1., 0., 0.),
104  Eigen::AngleAxisd(0.8 / 180. * M_PI, Eigen::Vector3d(1., 0., 0.))));
105 }
106 
107 TEST_F(RealTimeCorrelativeScanMatcher3DTest, RotationAroundY) {
108  TestFromInitialPose(transform::Rigid3d(
109  Eigen::Vector3d(-1., 0., 0.),
110  Eigen::AngleAxisd(0.8 / 180. * M_PI, Eigen::Vector3d(0., 1., 0.))));
111 }
112 
113 TEST_F(RealTimeCorrelativeScanMatcher3DTest, RotationAroundYZ) {
114  TestFromInitialPose(transform::Rigid3d(
115  Eigen::Vector3d(-1., 0., 0.),
116  Eigen::AngleAxisd(0.8 / 180. * M_PI, Eigen::Vector3d(0., 1., 1.))));
117 }
118 
119 } // namespace
120 } // namespace scan_matching
121 } // namespace mapping
122 } // namespace cartographer
Rigid3< double > Rigid3d
std::unique_ptr< LuaParameterDictionary > MakeDictionary(const std::string &code)
sensor::PointCloud point_cloud_
transform::Rigid3d expected_pose_
std::vector< Eigen::Vector3f > PointCloud
Definition: point_cloud.h:32
proto::RealTimeCorrelativeScanMatcherOptions CreateRealTimeCorrelativeScanMatcherOptions(common::LuaParameterDictionary *const parameter_dictionary)
transform::Rigid3d pose
static Rigid3 Translation(const Vector &vector)
std::unique_ptr< RealTimeCorrelativeScanMatcher3D > real_time_correlative_scan_matcher_


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