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/3d/scan_matching/rotational_scan_matcher.h"
00018
00019 #include <cmath>
00020
00021 #include "gtest/gtest.h"
00022
00023 namespace cartographer {
00024 namespace mapping {
00025 namespace scan_matching {
00026 namespace {
00027
00028 TEST(RotationalScanMatcher3DTest, OnlySameHistogramIsScoreOne) {
00029 Eigen::VectorXf histogram(7);
00030 histogram << 1.f, 43.f, 0.5f, 0.3123f, 23.f, 42.f, 0.f;
00031 RotationalScanMatcher matcher(&histogram);
00032 const auto scores = matcher.Match(histogram, 0.f, {0.f, 1.f});
00033 ASSERT_EQ(2, scores.size());
00034 EXPECT_NEAR(1.f, scores[0], 1e-6);
00035 EXPECT_GT(1.f, scores[1]);
00036 }
00037
00038 TEST(RotationalScanMatcher3DTest, InterpolatesAsExpected) {
00039 constexpr int kNumBuckets = 10;
00040 constexpr float kAnglePerBucket = M_PI / kNumBuckets;
00041 constexpr float kNoInitialRotation = 0.f;
00042 const Eigen::VectorXf histogram_no_initial_rotation =
00043 Eigen::VectorXf::Unit(kNumBuckets, 3);
00044 RotationalScanMatcher matcher(&histogram_no_initial_rotation);
00045 for (float t = 0.f; t < 1.f; t += 0.1f) {
00046
00047
00048 const float expected_score = t / std::hypot(t, 1 - t);
00049
00050 auto scores = matcher.Match(Eigen::VectorXf::Unit(kNumBuckets, 2),
00051 kNoInitialRotation, {t * kAnglePerBucket});
00052 ASSERT_EQ(1, scores.size());
00053 EXPECT_NEAR(expected_score, scores[0], 1e-6);
00054
00055 scores = matcher.Match(Eigen::VectorXf::Unit(kNumBuckets, 2),
00056 kNoInitialRotation, {(2 - t) * kAnglePerBucket});
00057 ASSERT_EQ(1, scores.size());
00058 EXPECT_NEAR(expected_score, scores[0], 1e-6);
00059
00060 scores =
00061 matcher.Match(Eigen::VectorXf::Unit(kNumBuckets, 4), kNoInitialRotation,
00062 {-t * kAnglePerBucket, (t - 2) * kAnglePerBucket});
00063 ASSERT_EQ(2, scores.size());
00064 EXPECT_NEAR(expected_score, scores[0], 1e-6);
00065 EXPECT_NEAR(expected_score, scores[1], 1e-6);
00066 }
00067 }
00068
00069 }
00070 }
00071 }
00072 }