motion_filter_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 
20 #include "gmock/gmock.h"
21 
22 namespace cartographer {
23 namespace mapping_3d {
24 namespace {
25 
26 class MotionFilterTest : public ::testing::Test {
27  protected:
28  MotionFilterTest() {
29  auto parameter_dictionary = common::MakeDictionary(
30  "return {"
31  "max_time_seconds = 0.5, "
32  "max_distance_meters = 0.2, "
33  "max_angle_radians = 2., "
34  "}");
35  options_ = CreateMotionFilterOptions(parameter_dictionary.get());
36  }
37 
38  common::Time SecondsSinceEpoch(int seconds) {
39  return common::FromUniversal(seconds * 10000000);
40  }
41 
42  proto::MotionFilterOptions options_;
43 };
44 
45 TEST_F(MotionFilterTest, NotInitialized) {
46  MotionFilter motion_filter(options_);
47  EXPECT_FALSE(
48  motion_filter.IsSimilar(common::Time(), transform::Rigid3d::Identity()));
49 }
50 
51 TEST_F(MotionFilterTest, NoChange) {
52  MotionFilter motion_filter(options_);
53  EXPECT_FALSE(motion_filter.IsSimilar(SecondsSinceEpoch(42),
55  EXPECT_TRUE(motion_filter.IsSimilar(SecondsSinceEpoch(42),
57 }
58 
59 TEST_F(MotionFilterTest, TimeElapsed) {
60  MotionFilter motion_filter(options_);
61  EXPECT_FALSE(motion_filter.IsSimilar(SecondsSinceEpoch(42),
63  EXPECT_FALSE(motion_filter.IsSimilar(SecondsSinceEpoch(43),
65  EXPECT_TRUE(motion_filter.IsSimilar(SecondsSinceEpoch(43),
67 }
68 
69 TEST_F(MotionFilterTest, LinearMotion) {
70  MotionFilter motion_filter(options_);
71  EXPECT_FALSE(motion_filter.IsSimilar(SecondsSinceEpoch(42),
73  EXPECT_FALSE(motion_filter.IsSimilar(
74  SecondsSinceEpoch(42),
75  transform::Rigid3d::Translation(Eigen::Vector3d(0.3, 0., 0.))));
76  EXPECT_TRUE(motion_filter.IsSimilar(
77  SecondsSinceEpoch(42),
78  transform::Rigid3d::Translation(Eigen::Vector3d(0.45, 0., 0.))));
79  EXPECT_FALSE(motion_filter.IsSimilar(
80  SecondsSinceEpoch(42),
81  transform::Rigid3d::Translation(Eigen::Vector3d(0.6, 0., 0.))));
82  EXPECT_TRUE(motion_filter.IsSimilar(
83  SecondsSinceEpoch(42),
84  transform::Rigid3d::Translation(Eigen::Vector3d(0.6, 0.15, 0.))));
85 }
86 
87 TEST_F(MotionFilterTest, RotationalMotion) {
88  MotionFilter motion_filter(options_);
89  EXPECT_FALSE(motion_filter.IsSimilar(SecondsSinceEpoch(42),
91  EXPECT_TRUE(motion_filter.IsSimilar(
92  SecondsSinceEpoch(42), transform::Rigid3d::Rotation(Eigen::AngleAxisd(
93  1.9, Eigen::Vector3d::UnitY()))));
94  EXPECT_FALSE(motion_filter.IsSimilar(
95  SecondsSinceEpoch(42), transform::Rigid3d::Rotation(Eigen::AngleAxisd(
96  2.1, Eigen::Vector3d::UnitY()))));
97  EXPECT_TRUE(motion_filter.IsSimilar(
98  SecondsSinceEpoch(42), transform::Rigid3d::Rotation(Eigen::AngleAxisd(
99  4., Eigen::Vector3d::UnitY()))));
100  EXPECT_FALSE(motion_filter.IsSimilar(
101  SecondsSinceEpoch(42), transform::Rigid3d::Rotation(Eigen::AngleAxisd(
102  5.9, Eigen::Vector3d::UnitY()))));
103  EXPECT_TRUE(motion_filter.IsSimilar(SecondsSinceEpoch(42),
105 }
106 
107 } // namespace
108 } // namespace mapping_3d
109 } // namespace cartographer
static Rigid3 Rotation(const AngleAxis &angle_axis)
proto::MotionFilterOptions options_
UniversalTimeScaleClock::time_point Time
Definition: time.h:44
std::unique_ptr< LuaParameterDictionary > MakeDictionary(const string &code)
Time FromUniversal(const int64 ticks)
Definition: time.cc:34
static Rigid3 Translation(const Vector &vector)
proto::MotionFilterOptions CreateMotionFilterOptions(common::LuaParameterDictionary *const parameter_dictionary)


cartographer
Author(s):
autogenerated on Mon Jun 10 2019 12:51:39