mapping_3d/sparse_pose_graph/spa_cost_function.h
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 
17 #ifndef CARTOGRAPHER_MAPPING_3D_SPARSE_POSE_GRAPH_SPA_COST_FUNCTION_H_
18 #define CARTOGRAPHER_MAPPING_3D_SPARSE_POSE_GRAPH_SPA_COST_FUNCTION_H_
19 
20 #include <array>
21 
22 #include "Eigen/Core"
23 #include "Eigen/Geometry"
28 #include "ceres/ceres.h"
29 #include "ceres/jet.h"
30 
31 namespace cartographer {
32 namespace mapping_3d {
33 namespace sparse_pose_graph {
34 
36  public:
38 
39  explicit SpaCostFunction(const Constraint::Pose& pose) : pose_(pose) {}
40 
41  // Computes the error between the scan-to-submap alignment 'zbar_ij' and the
42  // difference of submap pose 'c_i' and scan pose 'c_j' which are both in an
43  // arbitrary common frame.
44  template <typename T>
45  static std::array<T, 6> ComputeUnscaledError(
46  const transform::Rigid3d& zbar_ij, const T* const c_i_rotation,
47  const T* const c_i_translation, const T* const c_j_rotation,
48  const T* const c_j_translation) {
49  const Eigen::Quaternion<T> R_i_inverse(c_i_rotation[0], -c_i_rotation[1],
50  -c_i_rotation[2], -c_i_rotation[3]);
51 
52  const Eigen::Matrix<T, 3, 1> delta(c_j_translation[0] - c_i_translation[0],
53  c_j_translation[1] - c_i_translation[1],
54  c_j_translation[2] - c_i_translation[2]);
55  const Eigen::Matrix<T, 3, 1> h_translation = R_i_inverse * delta;
56 
57  const Eigen::Quaternion<T> h_rotation_inverse =
58  Eigen::Quaternion<T>(c_j_rotation[0], -c_j_rotation[1],
59  -c_j_rotation[2], -c_j_rotation[3]) *
60  Eigen::Quaternion<T>(c_i_rotation[0], c_i_rotation[1], c_i_rotation[2],
61  c_i_rotation[3]);
62 
63  const Eigen::Matrix<T, 3, 1> angle_axis_difference =
65  h_rotation_inverse * zbar_ij.rotation().cast<T>());
66 
67  return {{T(zbar_ij.translation().x()) - h_translation[0],
68  T(zbar_ij.translation().y()) - h_translation[1],
69  T(zbar_ij.translation().z()) - h_translation[2],
70  angle_axis_difference[0], angle_axis_difference[1],
71  angle_axis_difference[2]}};
72  }
73 
74  // Computes the error scaled by 'translation_weight' and 'rotation_weight',
75  // storing it in 'e'.
76  template <typename T>
78  const T* const c_i_rotation,
79  const T* const c_i_translation,
80  const T* const c_j_rotation,
81  const T* const c_j_translation, T* const e) {
82  const std::array<T, 6> e_ij =
83  ComputeUnscaledError(pose.zbar_ij, c_i_rotation, c_i_translation,
84  c_j_rotation, c_j_translation);
85  for (int ij : {0, 1, 2}) {
86  e[ij] = e_ij[ij] * T(pose.translation_weight);
87  }
88  for (int ij : {3, 4, 5}) {
89  e[ij] = e_ij[ij] * T(pose.rotation_weight);
90  }
91  }
92 
93  template <typename T>
94  bool operator()(const T* const c_i_rotation, const T* const c_i_translation,
95  const T* const c_j_rotation, const T* const c_j_translation,
96  T* const e) const {
97  ComputeScaledError(pose_, c_i_rotation, c_i_translation, c_j_rotation,
98  c_j_translation, e);
99  return true;
100  }
101 
102  private:
104 };
105 
106 } // namespace sparse_pose_graph
107 } // namespace mapping_3d
108 } // namespace cartographer
109 
110 #endif // CARTOGRAPHER_MAPPING_3D_SPARSE_POSE_GRAPH_SPA_COST_FUNCTION_H_
const Quaternion & rotation() const
Eigen::Matrix< T, 3, 1 > RotationQuaternionToAngleAxisVector(const Eigen::Quaternion< T > &quaternion)
Definition: transform.h:60
static void ComputeScaledError(const Constraint::Pose &pose, const T *const c_i_rotation, const T *const c_i_translation, const T *const c_j_rotation, const T *const c_j_translation, T *const e)
transform::Rigid3d pose
const Vector & translation() const
bool operator()(const T *const c_i_rotation, const T *const c_i_translation, const T *const c_j_rotation, const T *const c_j_translation, T *const e) const
static std::array< T, 6 > ComputeUnscaledError(const transform::Rigid3d &zbar_ij, const T *const c_i_rotation, const T *const c_i_translation, const T *const c_j_rotation, const T *const c_j_translation)


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