landmark_cost_function_3d_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 <memory>
20 
22 #include "gmock/gmock.h"
23 #include "gtest/gtest.h"
24 
25 namespace cartographer {
26 namespace mapping {
27 namespace optimization {
28 namespace {
29 
30 using ::testing::DoubleEq;
31 using ::testing::ElementsAre;
32 
33 using LandmarkObservation =
34  PoseGraphInterface::LandmarkNode::LandmarkObservation;
35 
36 TEST(LandmarkCostFunction3DTest, SmokeTest) {
37  NodeSpec3D prev_node;
38  prev_node.time = common::FromUniversal(0);
39  NodeSpec3D next_node;
40  next_node.time = common::FromUniversal(10);
41 
42  std::unique_ptr<ceres::CostFunction> cost_function(
44  LandmarkObservation{
45  0 /* trajectory ID */,
46  common::FromUniversal(5) /* time */,
47  transform::Rigid3d::Translation(Eigen::Vector3d(1., 1., 1.)),
48  1. /* translation_weight */,
49  2. /* rotation_weight */,
50  },
51  prev_node, next_node));
52 
53  const std::array<double, 4> prev_node_rotation{{1., 0., 0., 0.}};
54  const std::array<double, 3> prev_node_translation{{0., 0., 0.}};
55  const std::array<double, 4> next_node_rotation{{1., 0., 0., 0.}};
56  const std::array<double, 3> next_node_translation{{2., 2., 2.}};
57  const std::array<double, 4> landmark_rotation{{1., 0., 0., 0.}};
58  const std::array<double, 3> landmark_translation{{1., 2., 2.}};
59  const std::array<const double*, 6> parameter_blocks{
60  {prev_node_rotation.data(), prev_node_translation.data(),
61  next_node_rotation.data(), next_node_translation.data(),
62  landmark_rotation.data(), landmark_translation.data()}};
63 
64  std::array<double, 6> residuals;
65  std::array<std::array<double, 21>, 6> jacobians;
66  std::array<double*, 6> jacobians_ptrs;
67  for (int i = 0; i < 6; ++i) jacobians_ptrs[i] = jacobians[i].data();
68  cost_function->Evaluate(parameter_blocks.data(), residuals.data(),
69  jacobians_ptrs.data());
70  EXPECT_THAT(residuals, ElementsAre(DoubleEq(1.), DoubleEq(0.), DoubleEq(0.),
71  DoubleEq(0.), DoubleEq(0.), DoubleEq(0.)));
72 }
73 
74 } // namespace
75 } // namespace optimization
76 } // namespace mapping
77 } // namespace cartographer
static ceres::CostFunction * CreateAutoDiffCostFunction(const LandmarkObservation &observation, const NodeSpec3D &prev_node, const NodeSpec3D &next_node)
Time FromUniversal(const int64 ticks)
Definition: time.cc:34
static Rigid3 Translation(const Vector &vector)
TEST(TrajectoryConnectivityStateTest, UnknownTrajectory)


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