RTAB-Map 0.24.2
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#include <vector>
39
40namespace rtabmap {
41
77class RTABMAP_CORE_EXPORT ImuMotionPredictor
78{
79public:
104 double maxPoseInterval = 1.0,
105 double velocityWindow = 0.5,
106 double gravity = 9.80665);
107
108 double maxPoseInterval() const {return maxPoseInterval_;}
109 double velocityWindow() const {return velocityWindow_;}
111 double gravity() const {return gravity_;}
113 bool isGravityEstimated() const {return gravityEstimated_;}
115 size_t gravityWindows() const {return gravityWindowsCount_;}
116
127 void addImu(double stamp, const IMU & imu);
128
135 void addPose(double stamp, const rtabmap::Transform & pose);
136
139 void reset();
140
149 rtabmap::Transform predict(double stamp) const;
150
152 bool hasPose() const;
154 double lastPoseStamp() const;
156 Eigen::Vector3d velocity() const;
158 size_t samples() const;
159
160private:
161 // orientation: of the base frame in the IMU's world frame; acceleration: of the base in
162 // that frame, gravity removed
163 // specificForce: in that frame too, including the reaction to gravity (see
164 // hasAcceleration)
165 void addSample(double stamp, const Eigen::Quaterniond & orientation,
166 const Eigen::Vector3d & specificForce, bool hasAcceleration);
167 // Gravity estimation, from the IMU's own specific force and angular velocity norm
168 void estimateGravity(double stamp, const Eigen::Vector3d & specificForce, double angularVelocity);
169
170 struct Sample
171 {
172 Eigen::Quaterniond orientation;
173 // Kept with gravity, which is removed when used: the estimate can change
174 Eigen::Vector3d specificForce;
175 bool hasAcceleration;
176 };
177 // Acceleration of a sample, gravity removed (null without acceleration)
178 Eigen::Vector3d accelerationOf(const Sample & sample) const;
179 Eigen::Quaterniond orientationAt(double stamp) const;
180 Eigen::Vector3d accelerationAt(double stamp) const;
181 void integrate(double from, double to, const Eigen::Quaterniond & rotation,
182 Eigen::Vector3d & velocity, Eigen::Vector3d & position) const;
183 void updateIntegration() const;
184
185 // The acceleration integrated from the last pose up to a sample's stamp, in the
186 // odometry frame: predicting a stamp then only integrates from the sample before it.
187 struct Integrated
188 {
189 Eigen::Vector3d acceleration; // at that stamp
190 Eigen::Vector3d velocity; // change since the last pose
191 Eigen::Vector3d position; // change since the last pose (without its velocity)
192 };
193
194private:
195 double maxPoseInterval_;
196 double velocityWindow_;
197 double gravity_;
198 bool gravityEstimated_;
199 std::map<double, Sample> samples_;
200
201 // Gravity estimation: the samples of the current window, and the gravity measured over
202 // the last quiet windows
203 struct StillSample
204 {
205 double stamp;
206 Eigen::Vector3d specificForce; // in the IMU frame
207 double angularVelocity; // norm
208 };
209 std::vector<StillSample> stillWindow_;
210 std::vector<double> gravityWindows_;
211 size_t gravityWindowsCount_;
212 // Recent odometry poses, to estimate the velocity from (see velocityWindow)
213 std::map<double, rtabmap::Transform> poses_;
214
215 // The last odometry pose and the state predictions start from.
216 double poseStamp_;
217 rtabmap::Transform pose_;
218 Eigen::Vector3d velocity_;
219 // Rotation from the IMU's world frame to the odometry frame, at the last pose: the two
220 // are both gravity aligned, but their yaw differ.
221 Eigen::Quaterniond worldToOdom_;
222
223 // Built lazily by predict(), from the last pose to the newest sample; cleared when the
224 // pose or the samples it was built from change.
225 mutable std::map<double, Integrated> integrated_;
226 // Whether the acceleration at the last pose's stamp (the first entry) is final: it is
227 // held constant from the newest sample until a sample after that stamp is received.
228 mutable bool integratedStartIsFinal_;
229};
230
231}
232
233#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.
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.
double gravity() const
Gravity (m/s^2) removed from the specific force: the one given, or the estimate.
ImuMotionPredictor(double maxPoseInterval=1.0, double velocityWindow=0.5, double gravity=9.80665)
size_t gravityWindows() const
Number of quiet IMU windows the gravity estimate is from (0: not estimated yet)
bool isGravityEstimated() const
Whether the gravity is estimated from the IMU (see the constructor)
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