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


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:12