trajectory_collator_test.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2018 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 
28 #include "gtest/gtest.h"
29 
30 namespace cartographer {
31 namespace sensor {
32 namespace {
33 
34 using test::CollatorInput;
36 
37 TEST(TrajectoryCollator, OrderingMultipleTrajectories) {
38  const int kTrajectoryId[] = {4, 7};
39  const std::array<std::string, 2> kSensorId = {{"my_points", "some_imu"}};
40 
41  std::vector<CollatorInput> input_data;
42 
43  input_data.push_back(CollatorInput::CreateTimedPointCloudData(
44  kTrajectoryId[0], kSensorId[0], 0));
45  input_data.push_back(CollatorInput::CreateTimedPointCloudData(
46  kTrajectoryId[1], kSensorId[0], 0));
47  input_data.push_back(
48  CollatorInput::CreateImuData(kTrajectoryId[1], kSensorId[1], 0));
49  input_data.push_back(
50  CollatorInput::CreateImuData(kTrajectoryId[0], kSensorId[1], 0));
51  input_data.push_back(CollatorInput::CreateTimedPointCloudData(
52  kTrajectoryId[1], kSensorId[0], 100));
53  input_data.push_back(CollatorInput::CreateTimedPointCloudData(
54  kTrajectoryId[0], kSensorId[0], 50));
55  input_data.push_back(
56  CollatorInput::CreateImuData(kTrajectoryId[0], kSensorId[1], 60));
57  input_data.push_back(CollatorInput::CreateTimedPointCloudData(
58  kTrajectoryId[1], kSensorId[0], 150));
59  input_data.push_back(
60  CollatorInput::CreateImuData(kTrajectoryId[1], kSensorId[1], 120));
61 
62  std::vector<CollatorOutput> received;
63  TrajectoryCollator collator;
64  collator.AddTrajectory(
65  kTrajectoryId[0],
66  std::unordered_set<std::string>(kSensorId.begin(), kSensorId.end()),
67  [&received, kTrajectoryId](const std::string& sensor_id,
68  std::unique_ptr<Data> data) {
69  received.push_back(CollatorOutput(kTrajectoryId[0], data->GetSensorId(),
70  data->GetTime()));
71  });
72  collator.AddTrajectory(
73  kTrajectoryId[1],
74  std::unordered_set<std::string>(kSensorId.begin(), kSensorId.end()),
75  [&received, kTrajectoryId](const std::string& sensor_id,
76  std::unique_ptr<Data> data) {
77  received.push_back(CollatorOutput(kTrajectoryId[1], data->GetSensorId(),
78  data->GetTime()));
79  });
80 
81  // Send each sensor_id once to establish a common start time.
82  input_data[0].MoveToCollator(&collator);
83  input_data[1].MoveToCollator(&collator);
84  EXPECT_EQ(0, received.size());
85  input_data[2].MoveToCollator(&collator);
86  input_data[3].MoveToCollator(&collator);
87  EXPECT_EQ(2, received.size());
88  EXPECT_EQ(input_data[1].expected_output, received[0]);
89  EXPECT_EQ(input_data[0].expected_output, received[1]);
90 
91  // Does not wait for other trajectory.
92  input_data[4].MoveToCollator(&collator);
93  EXPECT_EQ(3, received.size());
94  EXPECT_EQ(input_data[2].expected_output, received[2]);
95 
96  input_data[5].MoveToCollator(&collator);
97  EXPECT_EQ(4, received.size());
98  EXPECT_EQ(input_data[3].expected_output, received[3]);
99  input_data[6].MoveToCollator(&collator);
100  EXPECT_EQ(5, received.size());
101  EXPECT_EQ(input_data[5].expected_output, received[4]);
102 
103  // Sorts different sensors.
104  input_data[7].MoveToCollator(&collator);
105  EXPECT_EQ(5, received.size());
106  input_data[8].MoveToCollator(&collator);
107  EXPECT_EQ(7, received.size());
108  EXPECT_EQ(input_data[4].expected_output, received[5]);
109  EXPECT_EQ(input_data[8].expected_output, received[6]);
110 
111  EXPECT_FALSE(collator.GetBlockingTrajectoryId().has_value());
112 
113  collator.FinishTrajectory(kTrajectoryId[0]);
114  collator.FinishTrajectory(kTrajectoryId[1]);
115  collator.Flush();
116  ASSERT_EQ(input_data.size(), received.size());
117 }
118 
119 } // namespace
120 } // namespace sensor
121 } // namespace cartographer
std::tuple< int, std::string, common::Time > CollatorOutput
TEST(TrajectoryConnectivityStateTest, UnknownTrajectory)


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