rotation_parameterization.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_INTERNAL_3D_ROTATION_PARAMETERIZATION_H_
18 #define CARTOGRAPHER_MAPPING_INTERNAL_3D_ROTATION_PARAMETERIZATION_H_
19 
21 #include "ceres/jet.h"
22 #include "ceres/rotation.h"
23 
24 namespace cartographer {
25 namespace mapping {
26 
28  template <typename T>
29  bool operator()(const T* x, const T* delta, T* x_plus_delta) const {
30  const T clamped_delta = common::Clamp(delta[0], T(-0.5), T(0.5));
31  T q_delta[4];
32  q_delta[0] = ceres::sqrt(1. - clamped_delta * clamped_delta);
33  q_delta[1] = T(0.);
34  q_delta[2] = T(0.);
35  q_delta[3] = clamped_delta;
36  ceres::QuaternionProduct(q_delta, x, x_plus_delta);
37  return true;
38  }
39 };
40 
42  template <typename T>
43  bool operator()(const T* x, const T* delta, T* x_plus_delta) const {
44  const T delta_norm =
45  ceres::sqrt(common::Pow2(delta[0]) + common::Pow2(delta[1]));
46  const T sin_delta_over_delta =
47  delta_norm < 1e-6 ? T(1.) : ceres::sin(delta_norm) / delta_norm;
48  T q_delta[4];
49  q_delta[0] = delta_norm < 1e-6 ? T(1.) : ceres::cos(delta_norm);
50  q_delta[1] = sin_delta_over_delta * delta[0];
51  q_delta[2] = sin_delta_over_delta * delta[1];
52  q_delta[3] = T(0.);
53  // We apply the 'delta' which is interpreted as an angle-axis rotation
54  // vector in the xy-plane of the submap frame. This way we can align to
55  // gravity because rotations around the z-axis in the submap frame do not
56  // change gravity alignment, while disallowing random rotations of the map
57  // that have nothing to do with gravity alignment (i.e. we disallow steps
58  // just changing "yaw" of the complete map).
59  ceres::QuaternionProduct(x, q_delta, x_plus_delta);
60  return true;
61  }
62 };
63 
64 } // namespace mapping
65 } // namespace cartographer
66 
67 #endif // CARTOGRAPHER_MAPPING_INTERNAL_3D_ROTATION_PARAMETERIZATION_H_
bool operator()(const T *x, const T *delta, T *x_plus_delta) const
constexpr T Pow2(T a)
Definition: math.h:50
bool operator()(const T *x, const T *delta, T *x_plus_delta) const
void QuaternionProduct(const double *const z, const T *const w, T *const zw)
Definition: math.h:75
T Clamp(const T value, const T min, const T max)
Definition: math.h:32


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