gtsam
Loading...
Searching...
No Matches
EquivInertialNavFactor_GlobalVel_NoBias.h
Go to the documentation of this file.
1
2/* ----------------------------------------------------------------------------
3
4 * GTSAM Copyright 2010, Georgia Tech Research Corporation,
5 * Atlanta, Georgia 30332-0415
6 * All Rights Reserved
7 * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
8
9 * See LICENSE for the license information
10
11 * -------------------------------------------------------------------------- */
12
21
22#pragma once
23
24#include <gtsam/config.h>
25
26#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
27
28#include <gtsam/base/Matrix.h>
30#include <gtsam/geometry/Rot3.h>
33
34// Using numerical derivative to calculate d(Pose3::Expmap)/dw
36
37
38#include <ostream>
39
40namespace gtsam {
41
42/*
43 * NOTES:
44 * =====
45 * Concept: Based on [Lupton12tro]
46 * - Pre-integrate IMU measurements using the static function PreIntegrateIMUObservations.
47 * Pre-integrated quantities are expressed in the body system of t0 - the first time instant (in which pre-integration began).
48 * All sensor-to-body transformations are performed here.
49 * - If required, calculate inertial solution by calling the static functions: predictPose_inertial, predictVelocity_inertial.
50 * - When the time is right, incorporate pre-integrated IMU data by creating an EquivInertialNavFactor_GlobalVel_NoBias factor, which will
51 * relate between navigation variables at the two time instances (t0 and current time).
52 *
53 * Other notes:
54 * - The global frame (NED or ENU) is defined by the user by specifying the gravity vector in this frame.
55 * - The IMU frame is implicitly defined by the user via the rotation matrix between global and imu frames.
56 * - Camera and IMU frames are identical
57 * - The user should specify a continuous equivalent noise covariance, which can be calculated using
58 * the static function CalcEquivalentNoiseCov based on the IMU gyro and acc measurement noise covariance
59 * matrices and the process\modeling covariance matrix. The IneritalNavFactor converts this into a
60 * discrete form using the supplied delta_t between sub-sequential measurements.
61 * - Earth-rate correction:
62 * + Currently the user should supply R_ECEF_to_G, which is the rotation from ECEF to the global
63 * frame (Local-Level system: ENU or NED, see above).
64 * + R_ECEF_to_G can be calculated by approximated values of latitude and longitude of the system.
65 * + Currently it is assumed that a relatively small distance is traveled w.r.t. to initial pose, since R_ECEF_to_G is constant.
66 * Otherwise, R_ECEF_to_G should be updated each time using the current lat-lon.
67 *
68 * - Frame Notation:
69 * Quantities are written as {Frame of Representation/Destination Frame}_{Quantity Type}_{Quatity Description/Origination Frame}
70 * So, the rotational velocity of the sensor written in the body frame is: body_omega_sensor
71 * And the transformation from the body frame to the world frame would be: world_P_body
72 * This allows visual chaining. For example, converting the sensed angular velocity of the IMU
73 * (angular velocity of the sensor in the sensor frame) into the world frame can be performed as:
74 * world_R_body * body_R_sensor * sensor_omega_sensor = world_omega_sensor
75 *
76 *
77 * - Common Quantity Types
78 * P : pose/3d transformation
79 * R : rotation
80 * omega : angular velocity
81 * t : translation
82 * v : velocity
83 * a : acceleration
84 *
85 * - Common Frames
86 * sensor : the coordinate system attached to the sensor origin
87 * body : the coordinate system attached to body/inertial frame.
88 * Unless an optional frame transformation is provided, the
89 * sensor frame and the body frame will be identical
90 * world : the global/world coordinate frame. This is assumed to be
91 * a tangent plane to the earth's surface somewhere near the
92 * vehicle
93 */
94
95template<class POSE, class VELOCITY>
96class EquivInertialNavFactor_GlobalVel_NoBias : public NoiseModelFactorN<POSE, VELOCITY, POSE, VELOCITY> {
97
98private:
99
100 typedef EquivInertialNavFactor_GlobalVel_NoBias<POSE, VELOCITY> This;
101 typedef NoiseModelFactorN<POSE, VELOCITY, POSE, VELOCITY> Base;
102
103 Vector delta_pos_in_t0_;
104 Vector delta_vel_in_t0_;
105 Vector3 delta_angles_;
106 double dt12_;
107
108 Vector world_g_;
109 Vector world_rho_;
110 Vector world_omega_earth_;
111
112 Matrix Jacobian_wrt_t0_Overall_;
113
114 std::optional<POSE> body_P_sensor_; // The pose of the sensor in the body frame
115
116public:
117
118 // Provide access to the Matrix& version of evaluateError:
119 using Base::evaluateError;
120
121 // shorthand for a smart pointer to a factor
122 typedef typename std::shared_ptr<EquivInertialNavFactor_GlobalVel_NoBias> shared_ptr;
123
125 EquivInertialNavFactor_GlobalVel_NoBias() {}
126
128 EquivInertialNavFactor_GlobalVel_NoBias(const Key& Pose1, const Key& Vel1, const Key& Pose2, const Key& Vel2,
129 const Vector& delta_pos_in_t0, const Vector& delta_vel_in_t0, const Vector3& delta_angles,
130 double dt12, const Vector world_g, const Vector world_rho,
131 const Vector& world_omega_earth, const noiseModel::Gaussian::shared_ptr& model_equivalent,
132 const Matrix& Jacobian_wrt_t0_Overall,
133 std::optional<POSE> body_P_sensor = {}) :
134 Base(model_equivalent, Pose1, Vel1, Pose2, Vel2),
135 delta_pos_in_t0_(delta_pos_in_t0), delta_vel_in_t0_(delta_vel_in_t0), delta_angles_(delta_angles),
136 dt12_(dt12), world_g_(world_g), world_rho_(world_rho), world_omega_earth_(world_omega_earth), Jacobian_wrt_t0_Overall_(Jacobian_wrt_t0_Overall),
137 body_P_sensor_(body_P_sensor) { }
138
139 virtual ~EquivInertialNavFactor_GlobalVel_NoBias() {}
140
142
144 virtual void print(
145 const std::string& s = "EquivInertialNavFactor_GlobalVel_NoBias",
146 const KeyFormatter& keyFormatter = DefaultKeyFormatter) const {
147 std::cout << s << "("
148 << keyFormatter(this->key<1>()) << ","
149 << keyFormatter(this->key<2>()) << ","
150 << keyFormatter(this->key<3>()) << ","
151 << keyFormatter(this->key<4>()) << "\n";
152 std::cout << "delta_pos_in_t0: " << this->delta_pos_in_t0_.transpose() << std::endl;
153 std::cout << "delta_vel_in_t0: " << this->delta_vel_in_t0_.transpose() << std::endl;
154 std::cout << "delta_angles: " << this->delta_angles_ << std::endl;
155 std::cout << "dt12: " << this->dt12_ << std::endl;
156 std::cout << "gravity (in world frame): " << this->world_g_.transpose() << std::endl;
157 std::cout << "craft rate (in world frame): " << this->world_rho_.transpose() << std::endl;
158 std::cout << "earth's rotation (in world frame): " << this->world_omega_earth_.transpose() << std::endl;
159 if(this->body_P_sensor_)
160 this->body_P_sensor_->print(" sensor pose in body frame: ");
161 this->noiseModel_->print(" noise model");
162 }
163
165 bool equals(const NonlinearFactor& expected, double tol=1e-9) const override {
166 const This *e = dynamic_cast<const This*> (&expected);
167 return e != nullptr && Base::equals(*e, tol)
168 && (delta_pos_in_t0_ - e->delta_pos_in_t0_).norm() < tol
169 && (delta_vel_in_t0_ - e->delta_vel_in_t0_).norm() < tol
170 && (delta_angles_ - e->delta_angles_).norm() < tol
171 && (dt12_ - e->dt12_) < tol
172 && (world_g_ - e->world_g_).norm() < tol
173 && (world_rho_ - e->world_rho_).norm() < tol
174 && (world_omega_earth_ - e->world_omega_earth_).norm() < tol
175 && ((!body_P_sensor_ && !e->body_P_sensor_) || (body_P_sensor_ && e->body_P_sensor_ && body_P_sensor_->equals(*e->body_P_sensor_)));
176 }
177
178
179 POSE predictPose(const POSE& Pose1, const VELOCITY& Vel1) const {
180
181 /* Position term */
182 Vector delta_pos_in_t0_corrected = delta_pos_in_t0_;
183
184 /* Rotation term */
185 Vector delta_angles_corrected = delta_angles_;
186
187 return predictPose_inertial(Pose1, Vel1,
188 delta_pos_in_t0_corrected, delta_angles_corrected,
189 dt12_, world_g_, world_rho_, world_omega_earth_);
190 }
191
192 static inline POSE predictPose_inertial(const POSE& Pose1, const VELOCITY& Vel1,
193 const Vector& delta_pos_in_t0, const Vector3& delta_angles,
194 const double dt12, const Vector& world_g, const Vector& world_rho, const Vector& world_omega_earth){
195
196 const POSE& world_P1_body = Pose1;
197 const VELOCITY& world_V1_body = Vel1;
198
199 /* Position term */
200 Vector body_deltaPos_body = delta_pos_in_t0;
201
202 Vector world_deltaPos_pls_body = world_P1_body.rotation().matrix() * body_deltaPos_body;
203 Vector world_deltaPos_body = world_V1_body * dt12 + 0.5*world_g*dt12*dt12 + world_deltaPos_pls_body;
204
205 // Incorporate earth-related terms. Note - these are assumed to be constant between t1 and t2.
206 world_deltaPos_body -= 2*skewSymmetric(world_rho + world_omega_earth)*world_V1_body * dt12*dt12;
207
208 /* TODO: the term dt12*dt12 in 0.5*world_g*dt12*dt12 is not entirely correct:
209 * the gravity should be canceled from the accelerometer measurements, bust since position
210 * is added with a delta velocity from a previous term, the actual delta time is more complicated.
211 * Need to figure out this in the future - currently because of this issue we'll get some more error
212 * in Z axis.
213 */
214
215 /* Rotation term */
216 Vector body_deltaAngles_body = delta_angles;
217
218 // Convert earth-related terms into the body frame
219 Matrix body_R_world(world_P1_body.rotation().inverse().matrix());
220 Vector body_rho = body_R_world * world_rho;
221 Vector body_omega_earth = body_R_world * world_omega_earth;
222
223 // Incorporate earth-related terms. Note - these are assumed to be constant between t1 and t2.
224 body_deltaAngles_body -= (body_rho + body_omega_earth)*dt12;
225
226 return POSE(Pose1.rotation() * POSE::Rotation::Expmap(body_deltaAngles_body), Pose1.translation() + typename POSE::Translation(world_deltaPos_body));
227
228 }
229
230 VELOCITY predictVelocity(const POSE& Pose1, const VELOCITY& Vel1) const {
231
232
233 Vector delta_vel_in_t0_corrected = delta_vel_in_t0_;
234
235 return predictVelocity_inertial(Pose1, Vel1,
236 delta_vel_in_t0_corrected,
237 dt12_, world_g_, world_rho_, world_omega_earth_);
238 }
239
240 static inline VELOCITY predictVelocity_inertial(const POSE& Pose1, const VELOCITY& Vel1,
241 const Vector& delta_vel_in_t0,
242 const double dt12, const Vector& world_g, const Vector& world_rho, const Vector& world_omega_earth) {
243
244 const POSE& world_P1_body = Pose1;
245 const VELOCITY& world_V1_body = Vel1;
246
247 Vector body_deltaVel_body = delta_vel_in_t0;
248 Vector world_deltaVel_body = world_P1_body.rotation().matrix() * body_deltaVel_body;
249
250 VELOCITY VelDelta( world_deltaVel_body + world_g * dt12 );
251
252 // Incorporate earth-related terms. Note - these are assumed to be constant between t1 and t2.
253 VelDelta -= 2*skewSymmetric(world_rho + world_omega_earth)*world_V1_body * dt12;
254
255 // Predict
256 return Vel1.compose( VelDelta );
257
258 }
259
260 void predict(const POSE& Pose1, const VELOCITY& Vel1, POSE& Pose2, VELOCITY& Vel2) const {
261 Pose2 = predictPose(Pose1, Vel1);
262 Vel2 = predictVelocity(Pose1, Vel1);
263 }
264
265 POSE evaluatePoseError(const POSE& Pose1, const VELOCITY& Vel1, const POSE& Pose2, const VELOCITY& Vel2) const {
266 // Predict
267 POSE Pose2Pred = predictPose(Pose1, Vel1);
268
269 // Calculate error
270 return Pose2.between(Pose2Pred);
271 }
272
273 VELOCITY evaluateVelocityError(const POSE& Pose1, const VELOCITY& Vel1, const POSE& Pose2, const VELOCITY& Vel2) const {
274 // Predict
275 VELOCITY Vel2Pred = predictVelocity(Pose1, Vel1);
276
277 // Calculate error
278 return Vel2.between(Vel2Pred);
279 }
280
281 Vector evaluateError(const POSE& Pose1, const VELOCITY& Vel1, const POSE& Pose2, const VELOCITY& Vel2,
282 OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3,
283 OptionalMatrixType H4) const {
284
285 // TODO: Write analytical derivative calculations
286 // Jacobian w.r.t. Pose1
287 if (H1){
288 Matrix H1_Pose = numericalDerivative11<POSE, POSE>(std::bind(&EquivInertialNavFactor_GlobalVel_NoBias::evaluatePoseError, this, _1, Vel1, Pose2, Vel2), Pose1);
289 Matrix H1_Vel = numericalDerivative11<VELOCITY, POSE>(std::bind(&EquivInertialNavFactor_GlobalVel_NoBias::evaluateVelocityError, this, _1, Vel1, Pose2, Vel2), Pose1);
290 *H1 = stack(std::vector<Matrix>{H1_Pose, H1_Vel});
291 }
292
293 // Jacobian w.r.t. Vel1
294 if (H2){
295 Matrix H2_Pose = numericalDerivative11<POSE, VELOCITY>(std::bind(&EquivInertialNavFactor_GlobalVel_NoBias::evaluatePoseError, this, Pose1, _1, Pose2, Vel2), Vel1);
296 Matrix H2_Vel = numericalDerivative11<VELOCITY, VELOCITY>(std::bind(&EquivInertialNavFactor_GlobalVel_NoBias::evaluateVelocityError, this, Pose1, _1, Pose2, Vel2), Vel1);
297 *H2 = stack(std::vector<Matrix>{H2_Pose, H2_Vel});
298 }
299
300 // Jacobian w.r.t. Pose2
301 if (H3){
302 Matrix H3_Pose = numericalDerivative11<POSE, POSE>(std::bind(&EquivInertialNavFactor_GlobalVel_NoBias::evaluatePoseError, this, Pose1, Vel1, _1, Vel2), Pose2);
303 Matrix H3_Vel = numericalDerivative11<VELOCITY, POSE>(std::bind(&EquivInertialNavFactor_GlobalVel_NoBias::evaluateVelocityError, this, Pose1, Vel1, _1, Vel2), Pose2);
304 *H3 = stack(std::vector<Matrix>{H3_Pose, H3_Vel});
305 }
306
307 // Jacobian w.r.t. Vel2
308 if (H4){
309 Matrix H4_Pose = numericalDerivative11<POSE, VELOCITY>(std::bind(&EquivInertialNavFactor_GlobalVel_NoBias::evaluatePoseError, this, Pose1, Vel1, Pose2, _1), Vel2);
310 Matrix H4_Vel = numericalDerivative11<VELOCITY, VELOCITY>(std::bind(&EquivInertialNavFactor_GlobalVel_NoBias::evaluateVelocityError, this, Pose1, Vel1, Pose2, _1), Vel2);
311 *H4 = stack(std::vector<Matrix>{H4_Pose, H4_Vel});
312 }
313
314 Vector ErrPoseVector(POSE::Logmap(evaluatePoseError(Pose1, Vel1, Pose2, Vel2)));
315 Vector ErrVelVector(VELOCITY::Logmap(evaluateVelocityError(Pose1, Vel1, Pose2, Vel2)));
316
317 return concatVectors(std::list<Vector>{ErrPoseVector, ErrVelVector});
318 }
319
320
321
322 static inline POSE PredictPoseFromPreIntegration(const POSE& Pose1, const VELOCITY& Vel1,
323 const Vector& delta_pos_in_t0, const Vector3& delta_angles,
324 double dt12, const Vector world_g, const Vector world_rho,
325 const Vector& world_omega_earth, const Matrix& Jacobian_wrt_t0_Overall) {
326
327 /* Position term */
328 Vector delta_pos_in_t0_corrected = delta_pos_in_t0;
329
330 /* Rotation term */
331 Vector delta_angles_corrected = delta_angles;
332 // Another alternative:
333 // Vector delta_angles_corrected = Rot3::Logmap( Rot3::Expmap(delta_angles_)*Rot3::Expmap(J_angles_wrt_BiasGyro*delta_BiasGyro) );
334
335 return predictPose_inertial(Pose1, Vel1, delta_pos_in_t0_corrected, delta_angles_corrected, dt12, world_g, world_rho, world_omega_earth);
336 }
337
338 static inline VELOCITY PredictVelocityFromPreIntegration(const POSE& Pose1, const VELOCITY& Vel1,
339 const Vector& delta_vel_in_t0, double dt12, const Vector world_g, const Vector world_rho,
340 const Vector& world_omega_earth, const Matrix& Jacobian_wrt_t0_Overall) {
341
342 Vector delta_vel_in_t0_corrected = delta_vel_in_t0;
343
344 return predictVelocity_inertial(Pose1, Vel1, delta_vel_in_t0_corrected, dt12, world_g, world_rho, world_omega_earth);
345 }
346
347 static inline void PredictFromPreIntegration(const POSE& Pose1, const VELOCITY& Vel1, POSE& Pose2, VELOCITY& Vel2,
348 const Vector& delta_pos_in_t0, const Vector& delta_vel_in_t0, const Vector3& delta_angles,
349 double dt12, const Vector world_g, const Vector world_rho,
350 const Vector& world_omega_earth, const Matrix& Jacobian_wrt_t0_Overall) {
351
352 Pose2 = PredictPoseFromPreIntegration(Pose1, Vel1, delta_pos_in_t0, delta_angles, dt12, world_g, world_rho, world_omega_earth, Jacobian_wrt_t0_Overall);
353 Vel2 = PredictVelocityFromPreIntegration(Pose1, Vel1, delta_vel_in_t0, dt12, world_g, world_rho, world_omega_earth, Jacobian_wrt_t0_Overall);
354 }
355
356
357 static inline void PreIntegrateIMUObservations(const Vector& msr_acc_t, const Vector& msr_gyro_t, const double msr_dt,
358 Vector& delta_pos_in_t0, Vector3& delta_angles, Vector& delta_vel_in_t0, double& delta_t,
359 const noiseModel::Gaussian::shared_ptr& model_continuous_overall,
360 Matrix& EquivCov_Overall, Matrix& Jacobian_wrt_t0_Overall,
361 std::optional<POSE> p_body_P_sensor = {}){
362 // Note: all delta terms refer to an IMU\sensor system at t0
363 // Note: Earth-related terms are not accounted here but are incorporated in predict functions.
364
365 POSE body_P_sensor = POSE();
366 bool flag_use_body_P_sensor = false;
367 if (p_body_P_sensor){
368 body_P_sensor = *p_body_P_sensor;
369 flag_use_body_P_sensor = true;
370 }
371
372 delta_pos_in_t0 = PreIntegrateIMUObservations_delta_pos(msr_dt, delta_pos_in_t0, delta_vel_in_t0);
373 delta_vel_in_t0 = PreIntegrateIMUObservations_delta_vel(msr_gyro_t, msr_acc_t, msr_dt, delta_angles, delta_vel_in_t0, flag_use_body_P_sensor, body_P_sensor);
374 delta_angles = PreIntegrateIMUObservations_delta_angles(msr_gyro_t, msr_dt, delta_angles, flag_use_body_P_sensor, body_P_sensor);
375
376 delta_t += msr_dt;
377
378 // Update EquivCov_Overall
379 Matrix H_pos_pos = numericalDerivative11<Vector, Vector>(std::bind(&PreIntegrateIMUObservations_delta_pos, msr_dt, _1, delta_vel_in_t0), delta_pos_in_t0);
380 Matrix H_pos_vel = numericalDerivative11<Vector, Vector>(std::bind(&PreIntegrateIMUObservations_delta_pos, msr_dt, delta_pos_in_t0, _1), delta_vel_in_t0);
381 Matrix H_pos_angles = Z_3x3;
382
383 Matrix H_vel_vel = numericalDerivative11<Vector, Vector>(std::bind(&PreIntegrateIMUObservations_delta_vel, msr_gyro_t, msr_acc_t, msr_dt, delta_angles, _1, flag_use_body_P_sensor, body_P_sensor), delta_vel_in_t0);
384 Matrix H_vel_angles = numericalDerivative11<Vector, Vector>(std::bind(&PreIntegrateIMUObservations_delta_vel, msr_gyro_t, msr_acc_t, msr_dt, _1, delta_vel_in_t0, flag_use_body_P_sensor, body_P_sensor), delta_angles);
385 Matrix H_vel_pos = Z_3x3;
386
387 Matrix H_angles_angles = numericalDerivative11<Vector, Vector>(std::bind(&PreIntegrateIMUObservations_delta_angles, msr_gyro_t, msr_dt, _1, flag_use_body_P_sensor, body_P_sensor), delta_angles);
388 Matrix H_angles_pos = Z_3x3;
389 Matrix H_angles_vel = Z_3x3;
390
391 Matrix F_angles = collect(std::vector<const Matrix*>{
392 &H_angles_angles, &H_angles_pos, &H_angles_vel});
393 Matrix F_pos = collect(
394 std::vector<const Matrix*>{&H_pos_angles, &H_pos_pos, &H_pos_vel});
395 Matrix F_vel = collect(
396 std::vector<const Matrix*>{&H_vel_angles, &H_vel_pos, &H_vel_vel});
397 Matrix F = stack(std::vector<Matrix>{F_angles, F_pos, F_vel});
398
399 noiseModel::Gaussian::shared_ptr model_discrete_curr = calc_descrete_noise_model(model_continuous_overall, msr_dt );
400 Matrix Q_d = inverse(model_discrete_curr->R().transpose() * model_discrete_curr->R() );
401
402 EquivCov_Overall = F * EquivCov_Overall * F.transpose() + Q_d;
403
404 // Update Jacobian_wrt_t0_Overall
405 Jacobian_wrt_t0_Overall = F * Jacobian_wrt_t0_Overall;
406 }
407
408 static inline Vector PreIntegrateIMUObservations_delta_pos(const double msr_dt,
409 const Vector& delta_pos_in_t0, const Vector& delta_vel_in_t0){
410
411 // Note: all delta terms refer to an IMU\sensor system at t0
412 // Note: delta_vel_in_t0 is already in body frame, so no need to use the body_P_sensor transformation here.
413
414 return delta_pos_in_t0 + delta_vel_in_t0 * msr_dt;
415 }
416
417
418
419 static inline Vector PreIntegrateIMUObservations_delta_vel(const Vector& msr_gyro_t, const Vector& msr_acc_t, const double msr_dt,
420 const Vector3& delta_angles, const Vector& delta_vel_in_t0, const bool flag_use_body_P_sensor, const POSE& body_P_sensor){
421
422 // Note: all delta terms refer to an IMU\sensor system at t0
423
424 // Calculate the corrected measurements using the Bias object
425 Vector AccCorrected = msr_acc_t;
426 Vector body_t_a_body;
427 if (flag_use_body_P_sensor){
428 Matrix body_R_sensor = body_P_sensor.rotation().matrix();
429
430 Vector GyroCorrected(msr_gyro_t);
431
432 Vector body_omega_body = body_R_sensor * GyroCorrected;
433 Matrix body_omega_body__cross = skewSymmetric(body_omega_body);
434
435 body_t_a_body = body_R_sensor * AccCorrected - body_omega_body__cross * body_omega_body__cross * body_P_sensor.translation().vector();
436 } else{
437 body_t_a_body = AccCorrected;
438 }
439
440 Rot3 R_t_to_t0 = Rot3::Expmap(delta_angles);
441
442 return delta_vel_in_t0 + R_t_to_t0.matrix() * body_t_a_body * msr_dt;
443 }
444
445
446 static inline Vector PreIntegrateIMUObservations_delta_angles(const Vector& msr_gyro_t, const double msr_dt,
447 const Vector3& delta_angles, const bool flag_use_body_P_sensor, const POSE& body_P_sensor){
448
449 // Note: all delta terms refer to an IMU\sensor system at t0
450
451 // Calculate the corrected measurements using the Bias object
452 Vector GyroCorrected = msr_gyro_t;
453
454 Vector body_t_omega_body;
455 if (flag_use_body_P_sensor){
456 body_t_omega_body = body_P_sensor.rotation().matrix() * GyroCorrected;
457 } else {
458 body_t_omega_body = GyroCorrected;
459 }
460
461 Rot3 R_t_to_t0 = Rot3::Expmap(delta_angles);
462
463 R_t_to_t0 = R_t_to_t0 * Rot3::Expmap( body_t_omega_body*msr_dt );
464 return Rot3::Logmap(R_t_to_t0);
465 }
466
467 static inline noiseModel::Gaussian::shared_ptr CalcEquivalentNoiseCov(const noiseModel::Gaussian::shared_ptr& gaussian_acc, const noiseModel::Gaussian::shared_ptr& gaussian_gyro,
468 const noiseModel::Gaussian::shared_ptr& gaussian_process){
469
470 Matrix cov_acc = inverse( gaussian_acc->R().transpose() * gaussian_acc->R() );
471 Matrix cov_gyro = inverse( gaussian_gyro->R().transpose() * gaussian_gyro->R() );
472 Matrix cov_process = inverse( gaussian_process->R().transpose() * gaussian_process->R() );
473
474 cov_process.block(0,0, 3,3) += cov_gyro;
475 cov_process.block(6,6, 3,3) += cov_acc;
476
477 return noiseModel::Gaussian::Covariance(cov_process);
478 }
479
480 static inline void CalcEquivalentNoiseCov_DifferentParts(const noiseModel::Gaussian::shared_ptr& gaussian_acc, const noiseModel::Gaussian::shared_ptr& gaussian_gyro,
481 const noiseModel::Gaussian::shared_ptr& gaussian_process,
482 Matrix& cov_acc, Matrix& cov_gyro, Matrix& cov_process_without_acc_gyro){
483
484 cov_acc = inverse( gaussian_acc->R().transpose() * gaussian_acc->R() );
485 cov_gyro = inverse( gaussian_gyro->R().transpose() * gaussian_gyro->R() );
486 cov_process_without_acc_gyro = inverse( gaussian_process->R().transpose() * gaussian_process->R() );
487 }
488
489 static inline void Calc_g_rho_omega_earth_NED(const Vector& Pos_NED, const Vector& Vel_NED, const Vector& LatLonHeight_IC, const Vector& Pos_NED_Initial,
490 Vector& g_NED, Vector& rho_NED, Vector& omega_earth_NED) {
491 Matrix ENU_to_NED{//
492 {0.0, 1.0, 0.0},
493 {1.0, 0.0, 0.0},
494 {0.0, 0.0, -1.0}};
495
496 Matrix NED_to_ENU{//
497 {0.0, 1.0, 0.0},
498 {1.0, 0.0, 0.0},
499 {0.0, 0.0, -1.0}};
500
501 // Convert incoming parameters to ENU
502 Vector Pos_ENU = NED_to_ENU * Pos_NED;
503 Vector Vel_ENU = NED_to_ENU * Vel_NED;
504 Vector Pos_ENU_Initial = NED_to_ENU * Pos_NED_Initial;
505
506 // Call ENU version
507 Vector g_ENU;
508 Vector rho_ENU;
509 Vector omega_earth_ENU;
510 Calc_g_rho_omega_earth_ENU(Pos_ENU, Vel_ENU, LatLonHeight_IC, Pos_ENU_Initial, g_ENU, rho_ENU, omega_earth_ENU);
511
512 // Convert output to NED
513 g_NED = ENU_to_NED * g_ENU;
514 rho_NED = ENU_to_NED * rho_ENU;
515 omega_earth_NED = ENU_to_NED * omega_earth_ENU;
516 }
517
518 static inline void Calc_g_rho_omega_earth_ENU(const Vector& Pos_ENU, const Vector& Vel_ENU, const Vector& LatLonHeight_IC, const Vector& Pos_ENU_Initial,
519 Vector& g_ENU, Vector& rho_ENU, Vector& omega_earth_ENU){
520 double R0 = 6.378388e6;
521 double e = 1/297;
522 double Re( R0*( 1-e*(sin( LatLonHeight_IC(0) ))*(sin( LatLonHeight_IC(0) )) ) );
523
524 // Calculate current lat, lon
525 Vector delta_Pos_ENU(Pos_ENU - Pos_ENU_Initial);
526 double delta_lat(delta_Pos_ENU(1)/Re);
527 double delta_lon(delta_Pos_ENU(0)/(Re*cos(LatLonHeight_IC(0))));
528 double lat_new(LatLonHeight_IC(0) + delta_lat);
529 double lon_new(LatLonHeight_IC(1) + delta_lon);
530
531 // Rotation of lon about z axis
532 Rot3 C1(cos(lon_new), sin(lon_new), 0.0,
533 -sin(lon_new), cos(lon_new), 0.0,
534 0.0, 0.0, 1.0);
535
536 // Rotation of lat about y axis
537 Rot3 C2(cos(lat_new), 0.0, sin(lat_new),
538 0.0, 1.0, 0.0,
539 -sin(lat_new), 0.0, cos(lat_new));
540
541 Rot3 UEN_to_ENU(0, 1, 0,
542 0, 0, 1,
543 1, 0, 0);
544
545 Rot3 R_ECEF_to_ENU( UEN_to_ENU * C2 * C1 );
546
547 Vector omega_earth_ECEF{{0.0, 0.0, 7.292115e-5}};
548 omega_earth_ENU = R_ECEF_to_ENU.matrix() * omega_earth_ECEF;
549
550 // Calculating g
551 double height(LatLonHeight_IC(2));
552 double EQUA_RADIUS = 6378137.0; // equatorial radius of the earth; WGS-84
553 double ECCENTRICITY = 0.0818191908426; // eccentricity of the earth ellipsoid
554 double e2( pow(ECCENTRICITY,2) );
555 double den( 1-e2*pow(sin(lat_new),2) );
556 double Rm( (EQUA_RADIUS*(1-e2))/( pow(den,(3/2)) ) );
557 double Rp( EQUA_RADIUS/( sqrt(den) ) );
558 double Ro( sqrt(Rp*Rm) ); // mean earth radius of curvature
559 double g0( 9.780318*( 1 + 5.3024e-3 * pow(sin(lat_new),2) - 5.9e-6 * pow(sin(2*lat_new),2) ) );
560 double g_calc( g0/( pow(1 + height/Ro, 2) ) );
561 g_ENU = Vector{{0.0, 0.0, -g_calc}};
562
563 // Calculate rho
564 double Ve( Vel_ENU(0) );
565 double Vn( Vel_ENU(1) );
566 double rho_E = -Vn/(Rm + height);
567 double rho_N = Ve/(Rp + height);
568 double rho_U = Ve*tan(lat_new)/(Rp + height);
569 rho_ENU = Vector{{rho_E, rho_N, rho_U}};
570 }
571
572 static inline noiseModel::Gaussian::shared_ptr calc_descrete_noise_model(const noiseModel::Gaussian::shared_ptr& model, double delta_t){
573 /* Q_d (approx)= Q * delta_t */
574 /* In practice, square root of the information matrix is represented, so that:
575 * R_d (approx)= R / sqrt(delta_t)
576 * */
577 return noiseModel::Gaussian::SqrtInformation(model->R()/sqrt(delta_t));
578 }
579private:
580
581#if GTSAM_ENABLE_BOOST_SERIALIZATION
583 friend class boost::serialization::access;
584 template<class ARCHIVE>
585 void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
586 ar & boost::serialization::make_nvp("NonlinearFactor2",
587 boost::serialization::base_object<Base>(*this));
588 }
589#endif
590
591
592
593}; // \class EquivInertialNavFactor_GlobalVel_NoBias
594
595}
596
597#endif // GTSAM_ALLOW_DEPRECATED_SINCE_V43
typedef and functions to augment Eigen's MatrixXd
Macros for Matrix constants to avoid excessive template instantiation.
Numerical derivative helpers for manifold-valued functions.
T inverse(const T &t)
unary functions
Definition lieProxies.h:43
3D rotation represented as a rotation matrix or quaternion
Non-linear factor base classes.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
NoiseModelFactorT< Vector, ValueTypes... > NoiseModelFactorN
Noise model factor with N value types and dynamic-sized error vector.
Definition NoiseModelFactorN.h:561
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:143
Matrix3 skewSymmetric(double wx, double wy, double wz)
skew symmetric matrix returns this: 0 -wz wy wz 0 -wx -wy wx 0
Definition Matrix.h:365
Matrix collect(const std::vector< const Matrix * > &matrices, size_t m, size_t n)
create a matrix by concatenating Given a set of matrices: A1, A2, A3... If all matrices have the same...
Definition Matrix.cpp:435
Vector concatVectors(const std::list< Vector > &vs)
concatenate Vectors
Definition Vector.cpp:303