rotational_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 <cmath>
20 
21 #include "gtest/gtest.h"
22 
23 namespace cartographer {
24 namespace mapping {
25 namespace scan_matching {
26 namespace {
27 
28 TEST(RotationalScanMatcher3DTest, OnlySameHistogramIsScoreOne) {
29  Eigen::VectorXf histogram(7);
30  histogram << 1.f, 43.f, 0.5f, 0.3123f, 23.f, 42.f, 0.f;
31  RotationalScanMatcher matcher({{histogram, 0.f}});
32  const auto scores = matcher.Match(histogram, 0.f, {0.f, 1.f});
33  ASSERT_EQ(2, scores.size());
34  EXPECT_NEAR(1.f, scores[0], 1e-6);
35  EXPECT_GT(1.f, scores[1]);
36 }
37 
38 TEST(RotationalScanMatcher3DTest, InterpolatesAsExpected) {
39  constexpr int kNumBuckets = 10;
40  constexpr float kAnglePerBucket = M_PI / kNumBuckets;
41  constexpr float kNoInitialRotation = 0.f;
42  RotationalScanMatcher matcher(
43  {{Eigen::VectorXf::Unit(kNumBuckets, 3), kNoInitialRotation}});
44  for (float t = 0.f; t < 1.f; t += 0.1f) {
45  // 't' is the fraction of overlap and we have to divide by the norm of the
46  // histogram to get the expected score.
47  const float expected_score = t / std::hypot(t, 1 - t);
48  // We rotate the 't'-th fraction of a bucket into the matcher's histogram.
49  auto scores = matcher.Match(Eigen::VectorXf::Unit(kNumBuckets, 2),
50  kNoInitialRotation, {t * kAnglePerBucket});
51  ASSERT_EQ(1, scores.size());
52  EXPECT_NEAR(expected_score, scores[0], 1e-6);
53  // Also verify rotating out of a bucket.
54  scores = matcher.Match(Eigen::VectorXf::Unit(kNumBuckets, 2),
55  kNoInitialRotation, {(2 - t) * kAnglePerBucket});
56  ASSERT_EQ(1, scores.size());
57  EXPECT_NEAR(expected_score, scores[0], 1e-6);
58  // And into and out of a bucket with negative angle.
59  scores =
60  matcher.Match(Eigen::VectorXf::Unit(kNumBuckets, 4), kNoInitialRotation,
61  {-t * kAnglePerBucket, (t - 2) * kAnglePerBucket});
62  ASSERT_EQ(2, scores.size());
63  EXPECT_NEAR(expected_score, scores[0], 1e-6);
64  EXPECT_NEAR(expected_score, scores[1], 1e-6);
65  }
66 }
67 
68 } // namespace
69 } // namespace scan_matching
70 } // namespace mapping
71 } // namespace cartographer
TEST(TrajectoryConnectivityStateTest, UnknownTrajectory)


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