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:
86 double maxPoseInterval = 1.0,
87 double velocityWindow = 0.5,
88 double gravity = 9.80665);
89
90 double maxPoseInterval() const {return maxPoseInterval_;}
91 double velocityWindow() const {return velocityWindow_;}
92 double gravity() const {return gravity_;}
93
104 void addImu(double stamp, const IMU & imu);
105
112 void addPose(double stamp, const rtabmap::Transform & pose);
113
115 void reset();
116
125 rtabmap::Transform predict(double stamp) const;
126
128 bool hasPose() const;
130 double lastPoseStamp() const;
132 Eigen::Vector3d velocity() const;
134 size_t samples() const;
135
136private:
137 // orientation: of the base frame in the IMU's world frame; acceleration: of the base in
138 // that frame, gravity removed
139 void addSample(double stamp, const Eigen::Quaterniond & orientation, const Eigen::Vector3d & acceleration);
140
141 struct Sample
142 {
143 Eigen::Quaterniond orientation;
144 Eigen::Vector3d acceleration;
145 };
146 Eigen::Quaterniond orientationAt(double stamp) const;
147 Eigen::Vector3d accelerationAt(double stamp) const;
148 void integrate(double from, double to, const Eigen::Quaterniond & rotation,
149 Eigen::Vector3d & velocity, Eigen::Vector3d & position) const;
150 void updateIntegration() const;
151
152 // The acceleration integrated from the last pose up to a sample's stamp, in the
153 // odometry frame: predicting a stamp then only integrates from the sample before it.
154 struct Integrated
155 {
156 Eigen::Vector3d acceleration; // at that stamp
157 Eigen::Vector3d velocity; // change since the last pose
158 Eigen::Vector3d position; // change since the last pose (without its velocity)
159 };
160
161private:
162 double maxPoseInterval_;
163 double velocityWindow_;
164 double gravity_;
165 std::map<double, Sample> samples_;
166 // Recent odometry poses, to estimate the velocity from (see velocityWindow)
167 std::map<double, rtabmap::Transform> poses_;
168
169 // The last odometry pose and the state predictions start from.
170 double poseStamp_;
171 rtabmap::Transform pose_;
172 Eigen::Vector3d velocity_;
173 // Rotation from the IMU's world frame to the odometry frame, at the last pose: the two
174 // are both gravity aligned, but their yaw differ.
175 Eigen::Quaterniond worldToOdom_;
176
177 // Built lazily by predict(), from the last pose to the newest sample; cleared when the
178 // pose or the samples it was built from change.
179 mutable std::map<double, Integrated> integrated_;
180 // Whether the acceleration at the last pose's stamp (the first entry) is final: it is
181 // held constant from the newest sample until a sample after that stamp is received.
182 mutable bool integratedStartIsFinal_;
183};
184
185}
186
187#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