corelib
src
IMU.cpp
Go to the documentation of this file.
1
/*
2
Copyright (c) 2010-2021, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3
All rights reserved.
4
5
Redistribution and use in source and binary forms, with or without
6
modification, 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
16
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
ON 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
25
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
*/
27
28
29
#include <
rtabmap/core/IMU.h
>
30
31
namespace
rtabmap
{
32
33
void
IMU::convertToBaseFrame
()
34
{
35
if
(!
localTransform_
.
isNull
() && !
localTransform_
.
rotation
().
isIdentity
())
36
{
37
cv::Mat rotationMatrix, rotationMatrixT;
38
localTransform_
.
rotationMatrix
().convertTo(rotationMatrix, CV_64FC1);
39
cv::transpose(rotationMatrix, rotationMatrixT);
40
41
cv::Mat_<double>
v
= rotationMatrix * cv::Mat(
linearAcceleration_
);
42
linearAcceleration_
= cv::Vec3d(
v
(0,0),
v
(0,1),
v
(0,2));
43
if
(!
linearAccelerationCovariance_
.empty())
44
{
45
linearAccelerationCovariance_
= rotationMatrix *
linearAccelerationCovariance_
* rotationMatrixT;
46
}
47
48
v
= rotationMatrix * cv::Mat(
angularVelocity_
);
49
angularVelocity_
= cv::Vec3d(
v
(0,0),
v
(0,1),
v
(0,2));
50
if
(!
angularVelocityCovariance_
.empty())
51
{
52
angularVelocityCovariance_
= rotationMatrix *
angularVelocityCovariance_
* rotationMatrixT;
53
}
54
55
if
(!(
orientation_
[0] == 0.0 &&
orientation_
[1] == 0.0 &&
orientation_
[2] == 0.0))
56
{
57
// orientation includes roll and pitch but not yaw in local transform
58
Eigen::Quaterniond
qTheta =
59
Eigen::AngleAxisd
(0, Eigen::Vector3d::UnitX()) *
60
Eigen::AngleAxisd
(0, Eigen::Vector3d::UnitY()) *
61
Eigen::AngleAxisd
(
localTransform_
.
theta
(), Eigen::Vector3d::UnitZ());
62
Eigen::Quaterniond
q
= qTheta *
Eigen::Quaterniond
(
orientation_
[3],
orientation_
[0],
orientation_
[1],
orientation_
[2]) *
localTransform_
.
getQuaterniond
().inverse();
63
orientation_
= cv::Vec4d(
q
.x(),
q
.y(),
q
.z(),
q
.w());
64
if
(!
orientationCovariance_
.empty())
65
{
66
orientationCovariance_
= rotationMatrix *
orientationCovariance_
* rotationMatrixT;
67
}
68
}
69
70
localTransform_
=
Transform
(
localTransform_
.
x
(),
localTransform_
.
y
(),
localTransform_
.
z
(), 0,0,0);
71
}
72
}
73
74
}
//namespace rtabmap
rtabmap::IMU::linearAccelerationCovariance_
cv::Mat linearAccelerationCovariance_
Definition:
IMU.h:80
rtabmap::IMU::angularVelocity_
cv::Vec3d angularVelocity_
Definition:
IMU.h:76
rtabmap::Transform::theta
float theta() const
Definition:
Transform.cpp:162
rtabmap::IMU::localTransform_
Transform localTransform_
Definition:
IMU.h:82
rtabmap::Transform::isNull
bool isNull() const
Definition:
Transform.cpp:107
rtabmap::Transform::y
float & y()
Definition:
Transform.h:93
rtabmap::Transform::z
float & z()
Definition:
Transform.h:94
rtabmap::IMU::linearAcceleration_
cv::Vec3d linearAcceleration_
Definition:
IMU.h:79
q
EIGEN_DEVICE_FUNC const Scalar & q
rtabmap::Transform::x
float & x()
Definition:
Transform.h:92
rtabmap::IMU::orientationCovariance_
cv::Mat orientationCovariance_
Definition:
IMU.h:74
rtabmap::Transform::rotationMatrix
cv::Mat rotationMatrix() const
Definition:
Transform.cpp:248
Eigen::Quaterniond
Quaternion< double > Quaterniond
rtabmap::IMU::orientation_
cv::Vec4d orientation_
Definition:
IMU.h:73
Eigen::AngleAxisd
AngleAxis< double > AngleAxisd
Eigen::Quaternion
rtabmap::Transform
Definition:
Transform.h:41
rtabmap::Transform::rotation
Transform rotation() const
Definition:
Transform.cpp:195
rtabmap::Transform::isIdentity
bool isIdentity() const
Definition:
Transform.cpp:136
rtabmap::IMU::convertToBaseFrame
void convertToBaseFrame()
Definition:
IMU.cpp:33
v
Array< int, Dynamic, 1 > v
rtabmap::IMU::angularVelocityCovariance_
cv::Mat angularVelocityCovariance_
Definition:
IMU.h:77
IMU.h
rtabmap
Definition:
CameraARCore.cpp:35
rtabmap::Transform::getQuaterniond
Eigen::Quaterniond getQuaterniond() const
Definition:
Transform.cpp:406
rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:11