2018-03-07 19:43:30 -05:00
|
|
|
|
/*
|
2026-08-06 13:32:20 -07:00
|
|
|
|
Copyright (c) 2010-2026, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
|
* Neither the name of the Universite de Sherbrooke nor the
|
|
|
|
|
|
names of its contributors may be used to endorse or promote products
|
|
|
|
|
|
derived from this software without specific prior written permission.
|
|
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
*/
|
2018-03-07 19:43:30 -05:00
|
|
|
|
|
|
|
|
|
|
#ifndef IMU_H_
|
|
|
|
|
|
#define IMU_H_
|
|
|
|
|
|
|
2026-08-06 13:32:20 -07:00
|
|
|
|
#include "rtabmap/core/rtabmap_core_export.h" // DLL export/import defines
|
2018-03-07 20:55:10 -05:00
|
|
|
|
#include <opencv2/core/core.hpp>
|
2021-03-09 16:00:41 -05:00
|
|
|
|
#include <rtabmap/utilite/UEvent.h>
|
|
|
|
|
|
#include <rtabmap/core/Transform.h>
|
2018-03-07 19:43:30 -05:00
|
|
|
|
|
|
|
|
|
|
namespace rtabmap {
|
|
|
|
|
|
|
2026-08-06 13:32:20 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* @class IMU
|
|
|
|
|
|
* @brief Inertial measurement sample (ROS @c sensor_msgs/Imu-like fields).
|
|
|
|
|
|
*
|
|
|
|
|
|
* Holds orientation (quaternion), angular velocity, linear acceleration, optional
|
|
|
|
|
|
* 3×3 row-major covariance matrices (double), and an optional @ref Transform
|
|
|
|
|
|
* expressing the IMU frame relative to the robot base.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @ref empty() is true when @ref localTransform() is null (default constructor).
|
|
|
|
|
|
* A sample constructed with @ref Transform::getIdentity() is not empty.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @ref convertToBaseFrame() rotates linear/angular velocity (and orientation when
|
|
|
|
|
|
* quaternion x/y/z are non-zero) into the base frame, then clears rotation in
|
|
|
|
|
|
* @ref localTransform() while keeping translation.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @see SensorData::imu()
|
|
|
|
|
|
* @see IMUEvent
|
|
|
|
|
|
*/
|
|
|
|
|
|
class RTABMAP_CORE_EXPORT IMU
|
2018-03-07 19:43:30 -05:00
|
|
|
|
{
|
|
|
|
|
|
public:
|
2026-08-06 13:32:20 -07:00
|
|
|
|
/** @brief Default-constructs an empty sample (null @ref localTransform()). */
|
2018-03-07 19:43:30 -05:00
|
|
|
|
IMU() {}
|
2026-08-06 13:32:20 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Constructs a sample with orientation and motion data.
|
|
|
|
|
|
* @param orientation Unit quaternion (qx, qy, qz, qw).
|
|
|
|
|
|
* @param orientationCovariance 3×3 row-major covariance about x, y, z (empty if unused).
|
|
|
|
|
|
* @param angularVelocity Rad/s about x, y, z.
|
|
|
|
|
|
* @param angularVelocityCovariance 3×3 row-major covariance (empty if unused).
|
|
|
|
|
|
* @param linearAcceleration m/s² about x, y, z.
|
|
|
|
|
|
* @param linearAccelerationCovariance 3×3 row-major covariance (empty if unused).
|
|
|
|
|
|
* @param localTransform IMU frame in base coordinates (default identity).
|
|
|
|
|
|
*/
|
2019-05-07 18:57:53 -04:00
|
|
|
|
IMU(const cv::Vec4d & orientation, // qx qy qz qw
|
2018-03-07 19:43:30 -05:00
|
|
|
|
const cv::Mat & orientationCovariance,
|
2018-03-21 21:31:41 -04:00
|
|
|
|
const cv::Vec3d & angularVelocity,
|
2018-03-07 19:43:30 -05:00
|
|
|
|
const cv::Mat & angularVelocityCovariance,
|
2018-03-21 21:31:41 -04:00
|
|
|
|
const cv::Vec3d & linearAcceleration,
|
2018-03-07 19:43:30 -05:00
|
|
|
|
const cv::Mat & linearAccelerationCovariance,
|
|
|
|
|
|
const Transform & localTransform = Transform::getIdentity()) :
|
|
|
|
|
|
orientation_(orientation),
|
|
|
|
|
|
orientationCovariance_(orientationCovariance),
|
|
|
|
|
|
angularVelocity_(angularVelocity),
|
|
|
|
|
|
angularVelocityCovariance_(angularVelocityCovariance),
|
|
|
|
|
|
linearAcceleration_(linearAcceleration),
|
|
|
|
|
|
linearAccelerationCovariance_(linearAccelerationCovariance),
|
|
|
|
|
|
localTransform_(localTransform)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
2026-08-06 13:32:20 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Constructs a sample without orientation (e.g. no magnetometer / no attitude).
|
|
|
|
|
|
* @param angularVelocity Rad/s about x, y, z.
|
|
|
|
|
|
* @param angularVelocityCovariance 3×3 row-major covariance (empty if unused).
|
|
|
|
|
|
* @param linearAcceleration m/s² about x, y, z.
|
|
|
|
|
|
* @param linearAccelerationCovariance 3×3 row-major covariance (empty if unused).
|
|
|
|
|
|
* @param localTransform IMU frame in base coordinates (default identity).
|
|
|
|
|
|
*/
|
2018-03-21 21:31:41 -04:00
|
|
|
|
IMU(const cv::Vec3d & angularVelocity,
|
2018-03-07 19:43:30 -05:00
|
|
|
|
const cv::Mat & angularVelocityCovariance,
|
2018-03-21 21:31:41 -04:00
|
|
|
|
const cv::Vec3d & linearAcceleration,
|
2018-03-07 19:43:30 -05:00
|
|
|
|
const cv::Mat & linearAccelerationCovariance,
|
|
|
|
|
|
const Transform & localTransform = Transform::getIdentity()) :
|
|
|
|
|
|
angularVelocity_(angularVelocity),
|
|
|
|
|
|
angularVelocityCovariance_(angularVelocityCovariance),
|
|
|
|
|
|
linearAcceleration_(linearAcceleration),
|
|
|
|
|
|
linearAccelerationCovariance_(linearAccelerationCovariance),
|
|
|
|
|
|
localTransform_(localTransform)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-06 13:32:20 -07:00
|
|
|
|
/** @return Orientation quaternion (qx, qy, qz, qw). */
|
2018-03-21 21:31:41 -04:00
|
|
|
|
const cv::Vec4d & orientation() const {return orientation_;}
|
2026-08-06 13:32:20 -07:00
|
|
|
|
/** @return 3×3 orientation covariance (row-major, empty if orientation unset). */
|
|
|
|
|
|
const cv::Mat & orientationCovariance() const {return orientationCovariance_;}
|
2018-03-07 19:43:30 -05:00
|
|
|
|
|
2026-08-06 13:32:20 -07:00
|
|
|
|
/** @return Angular velocity (rad/s). */
|
2018-03-21 21:31:41 -04:00
|
|
|
|
const cv::Vec3d & angularVelocity() const {return angularVelocity_;}
|
2026-08-06 13:32:20 -07:00
|
|
|
|
/** @return 3×3 angular velocity covariance (row-major, empty if unused). */
|
|
|
|
|
|
const cv::Mat & angularVelocityCovariance() const {return angularVelocityCovariance_;}
|
2018-03-07 19:43:30 -05:00
|
|
|
|
|
2026-08-06 13:32:20 -07:00
|
|
|
|
/** @return Linear acceleration (m/s²). */
|
|
|
|
|
|
const cv::Vec3d & linearAcceleration() const {return linearAcceleration_;}
|
|
|
|
|
|
/** @return 3×3 linear acceleration covariance (row-major, empty if unused). */
|
|
|
|
|
|
const cv::Mat & linearAccelerationCovariance() const {return linearAccelerationCovariance_;}
|
2018-03-07 19:43:30 -05:00
|
|
|
|
|
2026-08-06 13:32:20 -07:00
|
|
|
|
/** @return Transform from IMU frame to base frame. */
|
2018-03-07 19:43:30 -05:00
|
|
|
|
const Transform & localTransform() const {return localTransform_;}
|
|
|
|
|
|
|
2026-08-06 13:32:20 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief Rotate motion (and optionally orientation) into the base frame.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Applies @ref localTransform() rotation to vectors and covariances, then sets
|
|
|
|
|
|
* rotational part of @ref localTransform() to identity (translation unchanged).
|
|
|
|
|
|
* No-op if @ref localTransform() is null or rotation is identity.
|
|
|
|
|
|
* Orientation is updated only when quaternion qx, qy, qz, qw are not all zero.
|
|
|
|
|
|
*/
|
2021-03-09 16:00:41 -05:00
|
|
|
|
void convertToBaseFrame();
|
|
|
|
|
|
|
2026-08-06 13:32:20 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief True when @ref localTransform() is null (placeholder / unset sample).
|
|
|
|
|
|
*/
|
2018-03-07 19:43:30 -05:00
|
|
|
|
bool empty() const
|
|
|
|
|
|
{
|
2018-07-18 16:15:41 -04:00
|
|
|
|
return localTransform_.isNull();
|
2018-03-07 19:43:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2018-03-21 21:31:41 -04:00
|
|
|
|
cv::Vec4d orientation_;
|
2026-08-06 13:32:20 -07:00
|
|
|
|
cv::Mat orientationCovariance_;
|
2018-03-07 19:43:30 -05:00
|
|
|
|
|
2018-03-21 21:31:41 -04:00
|
|
|
|
cv::Vec3d angularVelocity_;
|
2026-08-06 13:32:20 -07:00
|
|
|
|
cv::Mat angularVelocityCovariance_;
|
2018-03-07 19:43:30 -05:00
|
|
|
|
|
2018-03-21 21:31:41 -04:00
|
|
|
|
cv::Vec3d linearAcceleration_;
|
2026-08-06 13:32:20 -07:00
|
|
|
|
cv::Mat linearAccelerationCovariance_;
|
2018-03-07 19:43:30 -05:00
|
|
|
|
|
|
|
|
|
|
Transform localTransform_;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-08-06 13:32:20 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* @class IMUEvent
|
|
|
|
|
|
* @brief @ref UEvent carrying an @ref IMU sample and timestamp.
|
|
|
|
|
|
*/
|
2018-03-07 19:43:30 -05:00
|
|
|
|
class IMUEvent : public UEvent
|
|
|
|
|
|
{
|
|
|
|
|
|
public:
|
2026-08-06 13:32:20 -07:00
|
|
|
|
/** @brief Default-constructs an event with zero stamp. */
|
2018-03-07 19:43:30 -05:00
|
|
|
|
IMUEvent() :
|
|
|
|
|
|
stamp_(0.0)
|
|
|
|
|
|
{}
|
2026-08-06 13:32:20 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief Constructs an event with IMU data and stamp.
|
|
|
|
|
|
* @param data IMU sample.
|
|
|
|
|
|
* @param stamp Timestamp in seconds.
|
|
|
|
|
|
*/
|
2018-03-07 19:43:30 -05:00
|
|
|
|
IMUEvent(const IMU & data, double stamp) :
|
|
|
|
|
|
data_(data),
|
|
|
|
|
|
stamp_(stamp)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
2026-08-06 13:32:20 -07:00
|
|
|
|
/** @return Event type name for the utilite event system. */
|
2018-03-07 19:43:30 -05:00
|
|
|
|
virtual std::string getClassName() const {return "IMUEvent";}
|
2026-08-06 13:32:20 -07:00
|
|
|
|
/** @return IMU payload. */
|
2018-03-07 19:43:30 -05:00
|
|
|
|
const IMU & getData() const {return data_;}
|
2026-08-06 13:32:20 -07:00
|
|
|
|
/** @return Timestamp in seconds. */
|
2018-03-07 19:43:30 -05:00
|
|
|
|
double getStamp() const {return stamp_;}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
IMU data_;
|
|
|
|
|
|
double stamp_;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* IMU_H_ */
|