landmark_cost_function_2d_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(LandmarkCostFunctionTest, SmokeTest) {
37  NodeSpec2D prev_node;
38  prev_node.time = common::FromUniversal(0);
39  prev_node.gravity_alignment = Eigen::Quaterniond::Identity();
40  NodeSpec2D next_node;
41  next_node.time = common::FromUniversal(10);
42  next_node.gravity_alignment = Eigen::Quaterniond::Identity();
43 
44  std::unique_ptr<ceres::CostFunction> cost_function(
46  LandmarkObservation{
47  0 /* trajectory ID */,
48  common::FromUniversal(5) /* time */,
49  transform::Rigid3d::Translation(Eigen::Vector3d(1., 1., 1.)),
50  1. /* translation_weight */,
51  2. /* rotation_weight */,
52  },
53  prev_node, next_node));
54 
55  const std::array<double, 3> prev_node_pose{{2., 0., 0.}};
56  const std::array<double, 3> next_node_pose{{0., 2., 0.}};
57  const std::array<double, 4> landmark_rotation{{1., 0., 0., 0.}};
58  const std::array<double, 3> landmark_translation{{1., 2., 1.}};
59  const std::array<const double*, 4> parameter_blocks{
60  {prev_node_pose.data(), next_node_pose.data(), landmark_rotation.data(),
61  landmark_translation.data()}};
62 
63  std::array<double, 6> residuals;
64  std::array<std::array<double, 13>, 6> jacobians;
65  std::array<double*, 6> jacobians_ptrs;
66  for (int i = 0; i < 6; ++i) jacobians_ptrs[i] = jacobians[i].data();
67 
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 NodeSpec2D &prev_node, const NodeSpec2D &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