landmark_data_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 
24 #include "gtest/gtest.h"
25 
26 namespace cartographer {
27 namespace sensor {
28 namespace {
29 
30 using ::testing::DoubleNear;
31 using ::testing::Field;
32 
33 ::testing::Matcher<const LandmarkObservation&> EqualsLandmark(
34  const LandmarkObservation& expected) {
35  return ::testing::AllOf(
36  Field(&LandmarkObservation::id, expected.id),
38  transform::IsNearly(expected.landmark_to_tracking_transform, 1e-2)),
40  DoubleNear(expected.translation_weight, 0.01)),
42  DoubleNear(expected.rotation_weight, 0.01)));
43 }
44 
45 class LandmarkDataTest : public ::testing::Test {
46  protected:
47  LandmarkDataTest()
48  : observations_(
49  {{
50  "ID1",
51  transform::Rigid3d(Eigen::Vector3d(1., 1., 1.),
52  Eigen::Quaterniond(1., 1., -1., -1.)),
53  1.f,
54  3.f,
55  },
56  {
57  "ID2",
58  transform::Rigid3d(Eigen::Vector3d(2., 2., 2.),
59  Eigen::Quaterniond(2., 2., -2., -2.)),
60  2.f,
61  4.f,
62  }}) {}
63  std::vector<LandmarkObservation> observations_;
64 };
65 
66 TEST_F(LandmarkDataTest, LandmarkDataToAndFromProto) {
67  const auto expected = LandmarkData{common::FromUniversal(50), observations_};
68  const auto actual = FromProto(ToProto(expected));
69  EXPECT_EQ(expected.time, actual.time);
70  EXPECT_THAT(actual.landmark_observations,
71  ElementsAre(EqualsLandmark(expected.landmark_observations[0]),
72  EqualsLandmark(expected.landmark_observations[1])));
73 }
74 
75 } // namespace
76 } // namespace sensor
77 } // namespace cartographer
Rigid3< double > Rigid3d
std::vector< LandmarkObservation > observations_
proto::FixedFramePoseData ToProto(const FixedFramePoseData &pose_data)
transform::Rigid3d landmark_to_tracking_transform
Definition: landmark_data.h:34
FixedFramePoseData FromProto(const proto::FixedFramePoseData &proto)
Time FromUniversal(const int64 ticks)
Definition: time.cc:34


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