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 
34 {
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));
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 
71  }
72 }
73 
74 } //namespace rtabmap
cv::Vec3d angularVelocity_
Definition: IMU.h:76
cv::Mat angularVelocityCovariance_
Definition: IMU.h:77
cv::Mat linearAccelerationCovariance_
Definition: IMU.h:80
cv::Mat rotationMatrix() const
Definition: Transform.cpp:238
void convertToBaseFrame()
Definition: IMU.cpp:33
cv::Vec4d orientation_
Definition: IMU.h:73
cv::Mat orientationCovariance_
Definition: IMU.h:74
cv::Vec3d linearAcceleration_
Definition: IMU.h:79
Transform rotation() const
Definition: Transform.cpp:195
bool isNull() const
Definition: Transform.cpp:107
Transform localTransform_
Definition: IMU.h:82
float theta() const
Definition: Transform.cpp:162
Eigen::Quaterniond getQuaterniond() const
Definition: Transform.cpp:396
bool isIdentity() const
Definition: Transform.cpp:136
q


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Jan 23 2023 03:37:28