collator_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 <array>
20 #include <memory>
21 
25 #include "cartographer/sensor/proto/sensor.pb.h"
26 #include "gtest/gtest.h"
27 
28 namespace cartographer {
29 namespace sensor {
30 namespace {
31 
32 TEST(Collator, Ordering) {
33  const std::array<string, 4> kSensorId = {
34  {"horizontal_rangefinder", "vertical_rangefinder", "imu", "odometry"}};
35  Data zero(common::FromUniversal(0), Data::Rangefinder{});
36  Data first(common::FromUniversal(100), Data::Rangefinder{});
37  Data second(common::FromUniversal(200), Data::Rangefinder{});
38  Data third(common::FromUniversal(300), Data::Imu{});
39  Data fourth(common::FromUniversal(400), Data::Rangefinder{});
40  Data fifth(common::FromUniversal(500), Data::Rangefinder{});
42 
43  std::vector<std::pair<string, Data>> received;
44  Collator collator;
45  collator.AddTrajectory(
46  0, std::unordered_set<string>(kSensorId.begin(), kSensorId.end()),
47  [&received](const string& sensor_id, std::unique_ptr<Data> data) {
48  received.push_back(std::make_pair(sensor_id, *data));
49  });
50 
51  constexpr int kTrajectoryId = 0;
52 
53  // Establish a common start time.
54  collator.AddSensorData(kTrajectoryId, kSensorId[0],
55  common::make_unique<Data>(zero));
56  collator.AddSensorData(kTrajectoryId, kSensorId[1],
57  common::make_unique<Data>(zero));
58  collator.AddSensorData(kTrajectoryId, kSensorId[2],
59  common::make_unique<Data>(zero));
60  collator.AddSensorData(kTrajectoryId, kSensorId[3],
61  common::make_unique<Data>(zero));
62 
63  collator.AddSensorData(kTrajectoryId, kSensorId[0],
64  common::make_unique<Data>(first));
65  collator.AddSensorData(kTrajectoryId, kSensorId[3],
66  common::make_unique<Data>(sixth));
67  collator.AddSensorData(kTrajectoryId, kSensorId[0],
68  common::make_unique<Data>(fourth));
69  collator.AddSensorData(kTrajectoryId, kSensorId[1],
70  common::make_unique<Data>(second));
71  collator.AddSensorData(kTrajectoryId, kSensorId[1],
72  common::make_unique<Data>(fifth));
73  collator.AddSensorData(kTrajectoryId, kSensorId[2],
74  common::make_unique<Data>(third));
75 
76  ASSERT_EQ(7, received.size());
77  EXPECT_EQ(100, common::ToUniversal(received[4].second.time));
78  EXPECT_EQ(kSensorId[0], received[4].first);
79  EXPECT_EQ(200, common::ToUniversal(received[5].second.time));
80  EXPECT_EQ(kSensorId[1], received[5].first);
81  EXPECT_EQ(300, common::ToUniversal(received[6].second.time));
82  EXPECT_EQ(kSensorId[2], received[6].first);
83 
84  collator.Flush();
85 
86  ASSERT_EQ(10, received.size());
87  EXPECT_EQ(kSensorId[0], received[7].first);
88  EXPECT_EQ(500, common::ToUniversal(received[8].second.time));
89  EXPECT_EQ(kSensorId[1], received[8].first);
90  EXPECT_EQ(600, common::ToUniversal(received[9].second.time));
91  EXPECT_EQ(kSensorId[3], received[9].first);
92 }
93 
94 } // namespace
95 } // namespace sensor
96 } // namespace cartographer
Time FromUniversal(const int64 ticks)
Definition: time.cc:34
int64 ToUniversal(const Time time)
Definition: time.cc:36


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