NDEVR
API Documentation
ImuTypes.h
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>
11typedef float g_type;
12namespace NDEVR
13{
17 namespace IMU
18 {
19 static constexpr g_type GRAVITY_VALUE = 9.81f;
20
24 class Point
25 {
26 public:
27 Point()
28 {}
29 Point(const Ray<3, fltp04>& acc, const Ray<3, fltp04>& gyro, fltp08 timestamp)
30 : acc(cast<g_type>(acc[X]), cast<g_type>(acc[Y]), cast<g_type>(acc[Z]))
31 , w(cast<g_type>(gyro[X]), cast<g_type>(gyro[Y]), cast<g_type>(gyro[Z]))
32 , t(timestamp)
33 {}
34 Point(const Ray<3, fltp08>& acc, const Ray<3, fltp08>& gyro, fltp08 timestamp)
35 : acc(cast<g_type>(acc[X]), cast<g_type>(acc[Y]), cast<g_type>(acc[Z]))
36 , w(cast<g_type>(gyro[X]), cast<g_type>(gyro[Y]), cast<g_type>(gyro[Z]))
37 , t(timestamp)
38 {
39 }
40 Point(g_type acc_x, g_type acc_y, g_type acc_z,
41 g_type ang_vel_x, g_type ang_vel_y, g_type ang_vel_z,
42 fltp08 timestamp)
43 : acc(acc_x, acc_y, acc_z)
44 , w(ang_vel_x, ang_vel_y, ang_vel_z)
45 , t(timestamp)
46 {}
47 template<class t_xyz_type>
48 Point(const t_xyz_type Acc, const t_xyz_type Gyro, const double& timestamp)
49 : acc(Acc.x, Acc.y, Acc.z)
50 , w(Gyro.x, Gyro.y, Gyro.z)
51 , t(timestamp)
52 {}
53 public:
54 Eigen::Vector3<g_type> acc;
55 Eigen::Vector3<g_type> w;
56 fltp08 t = 0.0;
57 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
58 };
59
63 class Bias
64 {
65 public:
66 Bias() :bax(0), bay(0), baz(0), bwx(0), bwy(0), bwz(0) {}
67 Bias(const fltp04& b_acc_x, const fltp04& b_acc_y, const fltp04& b_acc_z,
68 const fltp04& b_ang_vel_x, const fltp04& b_ang_vel_y, const fltp04& b_ang_vel_z)
69 : bax(cast<g_type>(b_acc_x))
70 , bay(cast<g_type>(b_acc_y))
71 , baz(cast<g_type>(b_acc_z))
72 , bwx(cast<g_type>(b_ang_vel_x))
73 , bwy(cast<g_type>(b_ang_vel_y))
74 , bwz(cast<g_type>(b_ang_vel_z))
75 {}
76 Bias(const fltp08& b_acc_x, const fltp08& b_acc_y, const fltp08& b_acc_z,
77 const fltp08& b_ang_vel_x, const fltp08& b_ang_vel_y, const fltp08& b_ang_vel_z)
78 : bax(cast<g_type>(b_acc_x))
79 , bay(cast<g_type>(b_acc_y))
80 , baz(cast<g_type>(b_acc_z))
81 , bwx(cast<g_type>(b_ang_vel_x))
82 , bwy(cast<g_type>(b_ang_vel_y))
83 , bwz(cast<g_type>(b_ang_vel_z))
84 {}
87 void CopyFrom(const Bias& b);
88
89 public:
90 g_type bax, bay, baz;
91 g_type bwx, bwy, bwz;
92 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
93 };
94
98 class Calib
99 {
100 public:
101
102 Calib(const Sophus::SE3<g_type>& Tbc, const g_type& ng, const g_type& na, const g_type& ngw, const g_type& naw)
103 {
104 Set(Tbc, ng, na, ngw, naw);
105 }
106
107 Calib(const Calib& calib);
108 Calib() { mbIsSet = false; }
109
116 void Set(const Sophus::SE3<g_type>& sophTbc, const g_type& ng, const g_type& na, const g_type& ngw, const g_type& naw);
117
118 public:
119 Sophus::SE3<g_type> mTcb;
120 Sophus::SE3<g_type> mTbc;
121 Eigen::DiagonalMatrix<g_type, 6> Cov, CovWalk;
122 g_type gyro_random_walk = 0.0f;
123 g_type acc_random_walk = 0.0f;
124 bool mbIsSet = false;
125 };
126
130 class IntegratedRotation
131 {
132 public:
133 IntegratedRotation() {}
138 IntegratedRotation(const Eigen::Vector3<g_type>& angVel, const Bias& imuBias, const g_type& time);
139
140 public:
141 g_type deltaT = 0.0f;
142 Eigen::Matrix3f deltaR;
143 Eigen::Matrix3f rightJ;
144 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
145 };
146
151 class Preintegrated
152 {
153 public:
154 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
158 Preintegrated(const Bias& b_, const Calib& calib);
161 Preintegrated(const Preintegrated& pImuPre);
162 Preintegrated() {}
163 ~Preintegrated() {}
166 void CopyFrom(const Preintegrated& pImuPre);
169 void Initialize(const Bias& b_);
174 void IntegrateNewMeasurement(const Eigen::Vector3<g_type>& acceleration, const Eigen::Vector3<g_type>& angVel, const g_type dt);
176 void Reintegrate();
179 void MergePrevious(Preintegrated* pPrev);
182 void SetNewBias(const Bias& bu_);
186 IMU::Bias GetDeltaBias(const Bias& b_);
189 Eigen::Matrix3<g_type> GetDeltaRotation(const Bias& b_);
192 Eigen::Vector3<g_type> GetDeltaVelocity(const Bias& b_);
195 Eigen::Vector3<g_type> GetDeltaPosition(const Bias& b_);
197 Eigen::Matrix3<g_type> GetUpdatedDeltaRotation();
199 Eigen::Vector3<g_type> GetUpdatedDeltaVelocity();
201 Eigen::Vector3<g_type> GetUpdatedDeltaPosition();
203 Eigen::Matrix3<g_type> GetOriginalDeltaRotation();
205 Eigen::Vector3<g_type> GetOriginalDeltaVelocity();
207 Eigen::Vector3<g_type> GetOriginalDeltaPosition();
209 Eigen::Matrix<g_type, 6, 1> GetDeltaBias();
211 Bias GetOriginalBias();
213 Bias GetUpdatedBias();
214 public:
215 g_type dT = 0.0f;
216 Eigen::Matrix<g_type, 15, 15> calc;
217 Eigen::Matrix<g_type, 15, 15> Info;
218 Eigen::DiagonalMatrix<g_type, 6> Nga, NgaWalk;
219
220 Bias b;
221 Eigen::Matrix3<g_type> dR;
222 Eigen::Vector3<g_type> dV, dP;
223 Eigen::Matrix3<g_type> JRg, JVg, JVa, JPg, JPa;
224 Eigen::Vector3<g_type> avgA, avgW;
225
226
227 private:
228 Bias bu;
229 Eigen::Matrix<g_type, 6, 1> db;
230
232 struct integrable
233 {
234 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
235 integrable() {}
236 integrable(const Eigen::Vector3<g_type>& a_, const Eigen::Vector3<g_type>& w_, const g_type& t_) :a(a_), w(w_), t(t_) {}
237 Eigen::Vector3<g_type> a, w;
238 g_type t = 0.0f;
239 };
240
241 Buffer<integrable> mvMeasurements;
242
243 std::mutex mMutex;
244 };
245
251 static Eigen::Matrix3<g_type> RightJacobianSO3(const g_type& x, const g_type& y, const g_type& z);
255 static Eigen::Matrix3<g_type> RightJacobianSO3(const Eigen::Vector3<g_type>& v);
261 static Eigen::Matrix3<g_type> InverseRightJacobianSO3(const g_type& x, const g_type& y, const g_type& z);
265 static Eigen::Matrix3<g_type> InverseRightJacobianSO3(const Eigen::Vector3<g_type>& v);
269 extern Eigen::Matrix3<g_type> NormalizeRotation(const Eigen::Matrix3<g_type>& R);
270
271 };
272}
273#endif
The primary namespace for the NDEVR SDK.
Eigen::Matrix< T, 3, 3 > NormalizeRotation(const Eigen::Matrix< T, 3, 3 > &R)
Normalizes a rotation matrix using SVD decomposition.
Definition G2oTypes.h:87
double fltp08
Defines an alias representing an 8 byte floating-point number.
Vector3< g_type > deltaR(const Matrix3< g_type > &R)
Extracts the rotation vector from a rotation matrix using the Rodrigues formula.
Definition se3_ops.hpp:41
Eigen::Matrix3< g_type > InverseRightJacobianSO3(const Eigen::Vector3< g_type > &v)
Computes the inverse right Jacobian of SO3.
Eigen::Matrix3< g_type > RightJacobianSO3(const Eigen::Vector3< g_type > &v)
Computes the right Jacobian of SO3.
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Definition Angle.h:408