API Documentation
Loading...
Searching...
No Matches
ImuTypes.h
Go to the documentation of this file.
1#pragma once
2#include <NDEVR/Buffer.h>
3#include <NDEVR/Vertex.h>
4#if _WIN32
5#include <utility>
6#include <Eigen/Core>
7#include <Eigen/Geometry>
8#include <Eigen/Dense>
9#include <OrbSLAM/Thirdparty/Sophus/sophus/se3.hpp>
10#include <mutex>
11
12namespace NDEVR
13{
14 namespace IMU
15 {
16 const float GRAVITY_VALUE = 9.81f;
17
18 //IMU measurement (gyro, accelerometer and timestamp)
19 class Point
20 {
21 public:
22 Point()
23 {}
24 Point(const Ray<3, fltp04>& acc, const Ray<3, fltp04>& gyro, fltp08 timestamp)
25 : acc(acc[X], acc[Y], acc[Z])
26 , w(gyro[X], gyro[Y], gyro[Z])
27 , t(timestamp)
28 {}
29 Point(fltp04 acc_x, fltp04 acc_y, fltp04 acc_z,
30 fltp04 ang_vel_x, fltp04 ang_vel_y, fltp04 ang_vel_z,
31 fltp08 timestamp)
32 : acc(acc_x, acc_y, acc_z)
33 , w(ang_vel_x, ang_vel_y, ang_vel_z)
34 , t(timestamp)
35 {}
36 template<class t_xyz_type>
37 Point(const t_xyz_type Acc, const t_xyz_type Gyro, const double& timestamp)
38 : acc(Acc.x, Acc.y, Acc.z)
39 , w(Gyro.x, Gyro.y, Gyro.z)
40 , t(timestamp)
41 {}
42 public:
43 Eigen::Vector3f acc;
44 Eigen::Vector3f w;
45 fltp08 t = 0.0;
46 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
47 };
48
49 //IMU biases (gyro and accelerometer)
50 class Bias
51 {
52 public:
53 Bias() :bax(0), bay(0), baz(0), bwx(0), bwy(0), bwz(0) {}
54 Bias(const float& b_acc_x, const float& b_acc_y, const float& b_acc_z,
55 const float& b_ang_vel_x, const float& b_ang_vel_y, const float& b_ang_vel_z)
56 : bax(b_acc_x)
57 , bay(b_acc_y)
58 , baz(b_acc_z)
59 , bwx(b_ang_vel_x)
60 , bwy(b_ang_vel_y)
61 , bwz(b_ang_vel_z)
62 {}
63 Bias(const fltp08& b_acc_x, const fltp08& b_acc_y, const fltp08& b_acc_z,
64 const fltp08& b_ang_vel_x, const fltp08& b_ang_vel_y, const fltp08& b_ang_vel_z)
65 : bax(cast<fltp04>(b_acc_x))
66 , bay(cast<fltp04>(b_acc_y))
67 , baz(cast<fltp04>(b_acc_z))
68 , bwx(cast<fltp04>(b_ang_vel_x))
69 , bwy(cast<fltp04>(b_ang_vel_y))
70 , bwz(cast<fltp04>(b_ang_vel_z))
71 {}
72 void CopyFrom(Bias& b);
73
74 public:
75 float bax, bay, baz;
76 float bwx, bwy, bwz;
77 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
78 };
79
80 //IMU calibration (Tbc, Tcb, noise)
81 class Calib
82 {
83 public:
84
85 Calib(const Sophus::SE3<float>& Tbc, const float& ng, const float& na, const float& ngw, const float& naw)
86 {
87 Set(Tbc, ng, na, ngw, naw);
88 }
89
90 Calib(const Calib& calib);
91 Calib() { mbIsSet = false; }
92
93 //void Set(const cv::Mat &cvTbc, const float &ng, const float &na, const float &ngw, const float &naw);
94 void Set(const Sophus::SE3<float>& sophTbc, const float& ng, const float& na, const float& ngw, const float& naw);
95
96 public:
97 // Sophus/Eigen implementation
98 Sophus::SE3<float> mTcb;
99 Sophus::SE3<float> mTbc;
100 Eigen::DiagonalMatrix<float, 6> Cov, CovWalk;
101 bool mbIsSet = false;
102 };
103
104 //Integration of 1 gyro measurement
105 class IntegratedRotation
106 {
107 public:
108 IntegratedRotation() {}
109 IntegratedRotation(const Eigen::Vector3f& angVel, const Bias& imuBias, const float& time);
110
111 public:
112 float deltaT = 0.0f; //integration time
113 Eigen::Matrix3f deltaR;
114 Eigen::Matrix3f rightJ; // right jacobian
115 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
116 };
117
118 //Preintegration of Imu Measurements
119 class Preintegrated
120 {
121 public:
122 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
123 Preintegrated(const Bias& b_, const Calib& calib);
124 Preintegrated(Preintegrated* pImuPre);
125 Preintegrated() {}
126 ~Preintegrated() {}
127 void CopyFrom(Preintegrated* pImuPre);
128 void Initialize(const Bias& b_);
129 void IntegrateNewMeasurement(const Eigen::Vector3f& acceleration, const Eigen::Vector3f& angVel, const float& dt);
130 void Reintegrate();
131 void MergePrevious(Preintegrated* pPrev);
132 void SetNewBias(const Bias& bu_);
133 IMU::Bias GetDeltaBias(const Bias& b_);
134
135 Eigen::Matrix3f GetDeltaRotation(const Bias& b_);
136 Eigen::Vector3f GetDeltaVelocity(const Bias& b_);
137 Eigen::Vector3f GetDeltaPosition(const Bias& b_);
138
139 Eigen::Matrix3f GetUpdatedDeltaRotation();
140 Eigen::Vector3f GetUpdatedDeltaVelocity();
141 Eigen::Vector3f GetUpdatedDeltaPosition();
142
143 Eigen::Matrix3f GetOriginalDeltaRotation();
144 Eigen::Vector3f GetOriginalDeltaVelocity();
145 Eigen::Vector3f GetOriginalDeltaPosition();
146
147 Eigen::Matrix<float, 6, 1> GetDeltaBias();
148
149 Bias GetOriginalBias();
150 Bias GetUpdatedBias();
151 public:
152 float dT = 0.0f;
153 Eigen::Matrix<float, 15, 15> C;
154 Eigen::Matrix<float, 15, 15> Info;
155 Eigen::DiagonalMatrix<float, 6> Nga, NgaWalk;
156
157 // Values for the original bias (when integration was computed)
158 Bias b;
159 Eigen::Matrix3f dR;
160 Eigen::Vector3f dV, dP;
161 Eigen::Matrix3f JRg, JVg, JVa, JPg, JPa;
162 Eigen::Vector3f avgA, avgW;
163
164
165 private:
166 // Updated bias
167 Bias bu;
168 // Dif between original and updated bias
169 // This is used to compute the updated values of the preintegration
170 Eigen::Matrix<float, 6, 1> db;
171
172 struct integrable
173 {
174 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
175 integrable() {}
176 integrable(const Eigen::Vector3f& a_, const Eigen::Vector3f& w_, const float& t_) :a(a_), w(w_), t(t_) {}
177 Eigen::Vector3f a, w;
178 float t = 0.0f;
179 };
180
181 Buffer<integrable> mvMeasurements;
182
183 std::mutex mMutex;
184 };
185
186 // Lie Algebra Functions
187 Eigen::Matrix3f RightJacobianSO3(const float& x, const float& y, const float& z);
188 Eigen::Matrix3f RightJacobianSO3(const Eigen::Vector3f& v);
189
190 Eigen::Matrix3f InverseRightJacobianSO3(const float& x, const float& y, const float& z);
191 Eigen::Matrix3f InverseRightJacobianSO3(const Eigen::Vector3f& v);
192
193 Eigen::Matrix3f NormalizeRotation(const Eigen::Matrix3f& R);
194
195 }
196
197}
198#endif
Definition ACIColor.h:37
float fltp04
Defines an alias representing a 4 byte floating-point number.
Definition BaseValues.hpp:157
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:514
@ Y
Definition BaseValues.hpp:202
@ X
Definition BaseValues.hpp:200
@ C
Definition BaseValues.hpp:205
@ Z
Definition BaseValues.hpp:204
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181