imu_integration.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_IMU_INTEGRATION_H_
18 #define CARTOGRAPHER_MAPPING_INTERNAL_3D_IMU_INTEGRATION_H_
19 
20 #include <algorithm>
21 #include <deque>
22 
23 #include "Eigen/Core"
24 #include "Eigen/Geometry"
28 #include "glog/logging.h"
29 
30 namespace cartographer {
31 namespace mapping {
32 
33 template <typename T>
35  Eigen::Matrix<T, 3, 1> delta_velocity;
36  Eigen::Quaternion<T> delta_rotation;
37 };
38 
39 template <typename T, typename RangeType, typename IteratorType>
41  const RangeType& imu_data,
42  const Eigen::Transform<T, 3, Eigen::Affine>&
43  linear_acceleration_calibration,
44  const Eigen::Transform<T, 3, Eigen::Affine>& angular_velocity_calibration,
45  const common::Time start_time, const common::Time end_time,
46  IteratorType* const it) {
47  CHECK_LE(start_time, end_time);
48  CHECK(*it != imu_data.end());
49  CHECK_LE((*it)->time, start_time);
50  if (std::next(*it) != imu_data.end()) {
51  CHECK_GT(std::next(*it)->time, start_time);
52  }
53 
54  common::Time current_time = start_time;
55 
56  IntegrateImuResult<T> result = {Eigen::Matrix<T, 3, 1>::Zero(),
57  Eigen::Quaterniond::Identity().cast<T>()};
58  while (current_time < end_time) {
59  common::Time next_imu_data = common::Time::max();
60  if (std::next(*it) != imu_data.end()) {
61  next_imu_data = std::next(*it)->time;
62  }
63  common::Time next_time = std::min(next_imu_data, end_time);
64  const T delta_t(common::ToSeconds(next_time - current_time));
65 
66  const Eigen::Matrix<T, 3, 1> delta_angle =
67  (angular_velocity_calibration *
68  (*it)->angular_velocity.template cast<T>()) *
69  delta_t;
70  result.delta_rotation *=
72  result.delta_velocity += result.delta_rotation *
73  ((linear_acceleration_calibration *
74  (*it)->linear_acceleration.template cast<T>()) *
75  delta_t);
76  current_time = next_time;
77  if (current_time == next_imu_data) {
78  ++(*it);
79  }
80  }
81  return result;
82 }
83 
84 // Returns velocity delta in map frame.
85 template <typename RangeType, typename IteratorType>
86 IntegrateImuResult<double> IntegrateImu(const RangeType& imu_data,
87  const common::Time start_time,
88  const common::Time end_time,
89  IteratorType* const it) {
90  return IntegrateImu<double, RangeType, IteratorType>(
91  imu_data, Eigen::Affine3d::Identity(), Eigen::Affine3d::Identity(),
92  start_time, end_time, it);
93 }
94 
95 } // namespace mapping
96 } // namespace cartographer
97 
98 #endif // CARTOGRAPHER_MAPPING_INTERNAL_3D_IMU_INTEGRATION_H_
Eigen::Quaternion< T > AngleAxisVectorToRotationQuaternion(const Eigen::Matrix< T, 3, 1 > &angle_axis)
Definition: transform.h:86
UniversalTimeScaleClock::time_point Time
Definition: time.h:44
IntegrateImuResult< T > IntegrateImu(const RangeType &imu_data, const Eigen::Transform< T, 3, Eigen::Affine > &linear_acceleration_calibration, const Eigen::Transform< T, 3, Eigen::Affine > &angular_velocity_calibration, const common::Time start_time, const common::Time end_time, IteratorType *const it)
double ToSeconds(const Duration duration)
Definition: time.cc:29


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