RTAB-Map 0.24.1
Real-Time Appearance-Based Mapping
Loading...
Searching...
No Matches
ImuMotionPredictor.h
1/*
2Copyright (c) 2010-2026, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the Universite de Sherbrooke nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#ifndef RTABMAP_CORE_IMUMOTIONPREDICTOR_H_
29#define RTABMAP_CORE_IMUMOTIONPREDICTOR_H_
30
31#include <rtabmap/core/rtabmap_core_export.h>
32#include <rtabmap/core/Transform.h>
33#include <rtabmap/core/IMU.h>
34
35#include <Eigen/Geometry>
36
37#include <map>
38
39namespace rtabmap {
40
65class RTABMAP_CORE_EXPORT ImuMotionPredictor
66{
67public:
90 double maxPoseInterval = 1.0,
91 double velocityWindow = 0.5,
92 double gravity = 9.80665);
93
94 double maxPoseInterval() const {return maxPoseInterval_;}
95 double velocityWindow() const {return velocityWindow_;}
96 double gravity() const {return gravity_;}
97
108 void addImu(double stamp, const IMU & imu);
109
116 void addPose(double stamp, const rtabmap::Transform & pose);
117
119 void reset();
120
129 rtabmap::Transform predict(double stamp) const;
130
132 bool hasPose() const;
134 double lastPoseStamp() const;
136 Eigen::Vector3d velocity() const;
138 size_t samples() const;
139
140private:
141 // orientation: of the base frame in the IMU's world frame; acceleration: of the base in
142 // that frame, gravity removed
143 void addSample(double stamp, const Eigen::Quaterniond & orientation, const Eigen::Vector3d & acceleration);
144
145 struct Sample
146 {
147 Eigen::Quaterniond orientation;
148 Eigen::Vector3d acceleration;
149 };
150 Eigen::Quaterniond orientationAt(double stamp) const;
151 Eigen::Vector3d accelerationAt(double stamp) const;
152 void integrate(double from, double to, const Eigen::Quaterniond & rotation,
153 Eigen::Vector3d & velocity, Eigen::Vector3d & position) const;
154 void updateIntegration() const;
155
156 // The acceleration integrated from the last pose up to a sample's stamp, in the
157 // odometry frame: predicting a stamp then only integrates from the sample before it.
158 struct Integrated
159 {
160 Eigen::Vector3d acceleration; // at that stamp
161 Eigen::Vector3d velocity; // change since the last pose
162 Eigen::Vector3d position; // change since the last pose (without its velocity)
163 };
164
165private:
166 double maxPoseInterval_;
167 double velocityWindow_;
168 double gravity_;
169 std::map<double, Sample> samples_;
170 // Recent odometry poses, to estimate the velocity from (see velocityWindow)
171 std::map<double, rtabmap::Transform> poses_;
172
173 // The last odometry pose and the state predictions start from.
174 double poseStamp_;
175 rtabmap::Transform pose_;
176 Eigen::Vector3d velocity_;
177 // Rotation from the IMU's world frame to the odometry frame, at the last pose: the two
178 // are both gravity aligned, but their yaw differ.
179 Eigen::Quaterniond worldToOdom_;
180
181 // Built lazily by predict(), from the last pose to the newest sample; cleared when the
182 // pose or the samples it was built from change.
183 mutable std::map<double, Integrated> integrated_;
184 // Whether the acceleration at the last pose's stamp (the first entry) is final: it is
185 // held constant from the newest sample until a sample after that stamp is received.
186 mutable bool integratedStartIsFinal_;
187};
188
189}
190
191#endif /* RTABMAP_CORE_IMUMOTIONPREDICTOR_H_ */
Inertial measurement sample (ROS sensor_msgs/Imu-like fields).
Definition IMU.h:57
Predicts the pose of the base frame from the last odometry pose and the IMU.
Eigen::Vector3d velocity() const
Velocity (m/s) of the base in the odometry frame at the last pose.
void reset()
Forgets the poses and the IMU samples.
bool hasPose() const
Whether there is a pose to predict from (none yet, or the last one was null).
void addImu(double stamp, const IMU &imu)
Adds an IMU measurement.
size_t samples() const
Number of IMU samples kept.
double lastPoseStamp() const
Stamp of the last pose added, 0 if there is none.
ImuMotionPredictor(double maxPoseInterval=1.0, double velocityWindow=0.5, double gravity=9.80665)
void addPose(double stamp, const rtabmap::Transform &pose)
Adds an odometry pose, from which the next poses are predicted.
rtabmap::Transform predict(double stamp) const
Predicts the pose of the base frame in the odometry frame.
Represents a 3D rigid body transformation (rotation + translation).
Definition Transform.h:53