rotation_parameterization.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2016 The Cartographer Authors
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef CARTOGRAPHER_MAPPING_INTERNAL_3D_ROTATION_PARAMETERIZATION_H_
00018 #define CARTOGRAPHER_MAPPING_INTERNAL_3D_ROTATION_PARAMETERIZATION_H_
00019 
00020 #include "cartographer/common/math.h"
00021 #include "ceres/jet.h"
00022 #include "ceres/rotation.h"
00023 
00024 namespace cartographer {
00025 namespace mapping {
00026 
00027 struct YawOnlyQuaternionPlus {
00028   template <typename T>
00029   bool operator()(const T* x, const T* delta, T* x_plus_delta) const {
00030     const T clamped_delta = common::Clamp(delta[0], T(-0.5), T(0.5));
00031     T q_delta[4];
00032     q_delta[0] = ceres::sqrt(1. - clamped_delta * clamped_delta);
00033     q_delta[1] = T(0.);
00034     q_delta[2] = T(0.);
00035     q_delta[3] = clamped_delta;
00036     ceres::QuaternionProduct(q_delta, x, x_plus_delta);
00037     return true;
00038   }
00039 };
00040 
00041 struct ConstantYawQuaternionPlus {
00042   template <typename T>
00043   bool operator()(const T* x, const T* delta, T* x_plus_delta) const {
00044     const T delta_norm =
00045         ceres::sqrt(common::Pow2(delta[0]) + common::Pow2(delta[1]));
00046     const T sin_delta_over_delta =
00047         delta_norm < 1e-6 ? T(1.) : ceres::sin(delta_norm) / delta_norm;
00048     T q_delta[4];
00049     q_delta[0] = delta_norm < 1e-6 ? T(1.) : ceres::cos(delta_norm);
00050     q_delta[1] = sin_delta_over_delta * delta[0];
00051     q_delta[2] = sin_delta_over_delta * delta[1];
00052     q_delta[3] = T(0.);
00053     // We apply the 'delta' which is interpreted as an angle-axis rotation
00054     // vector in the xy-plane of the submap frame. This way we can align to
00055     // gravity because rotations around the z-axis in the submap frame do not
00056     // change gravity alignment, while disallowing random rotations of the map
00057     // that have nothing to do with gravity alignment (i.e. we disallow steps
00058     // just changing "yaw" of the complete map).
00059     ceres::QuaternionProduct(x, q_delta, x_plus_delta);
00060     return true;
00061   }
00062 };
00063 
00064 }  // namespace mapping
00065 }  // namespace cartographer
00066 
00067 #endif  // CARTOGRAPHER_MAPPING_INTERNAL_3D_ROTATION_PARAMETERIZATION_H_


cartographer
Author(s): The Cartographer Authors
autogenerated on Thu May 9 2019 02:27:35