30#include <boost/bind/bind.hpp>
31#include <boost/optional.hpp>
90template<
class POSE,
class VELOCITY,
class IMUBIAS>
98 Vector delta_pos_in_t0_;
99 Vector delta_vel_in_t0_;
100 Vector3 delta_angles_;
105 Vector world_omega_earth_;
107 Matrix Jacobian_wrt_t0_Overall_;
109 boost::optional<IMUBIAS> Bias_initial_;
110 boost::optional<POSE> body_P_sensor_;
115 typedef typename boost::shared_ptr<EquivInertialNavFactor_GlobalVel> shared_ptr;
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 boost::optional<IMUBIAS> Bias_initial = boost::none, boost::optional<POSE> body_P_sensor = boost::none) :
127 Base(model_equivalent, Pose1, Vel1, IMUBias1,
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),
130 Bias_initial_(Bias_initial), body_P_sensor_(body_P_sensor) { }
137 void print(
const std::string& s =
"EquivInertialNavFactor_GlobalVel",
const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const override {
138 std::cout << s <<
"("
139 << keyFormatter(this->
key1()) <<
","
140 << keyFormatter(this->key2()) <<
","
141 << keyFormatter(this->key3()) <<
","
142 << keyFormatter(this->key4()) <<
","
143 << keyFormatter(this->key5()) <<
"\n";
144 std::cout <<
"delta_pos_in_t0: " << this->delta_pos_in_t0_.transpose() << std::endl;
145 std::cout <<
"delta_vel_in_t0: " << this->delta_vel_in_t0_.transpose() << std::endl;
146 std::cout <<
"delta_angles: " << this->delta_angles_ << std::endl;
147 std::cout <<
"dt12: " << this->dt12_ << std::endl;
148 std::cout <<
"gravity (in world frame): " << this->world_g_.transpose() << std::endl;
149 std::cout <<
"craft rate (in world frame): " << this->world_rho_.transpose() << std::endl;
150 std::cout <<
"earth's rotation (in world frame): " << this->world_omega_earth_.transpose() << std::endl;
151 if(this->body_P_sensor_)
152 this->body_P_sensor_->print(
" sensor pose in body frame: ");
153 this->noiseModel_->print(
" noise model");
158 const This *e =
dynamic_cast<const This*
> (&expected);
160 && (delta_pos_in_t0_ - e->delta_pos_in_t0_).norm() < tol
161 && (delta_vel_in_t0_ - e->delta_vel_in_t0_).norm() < tol
162 && (delta_angles_ - e->delta_angles_).norm() < tol
163 && (dt12_ - e->dt12_) < tol
164 && (world_g_ - e->world_g_).norm() < tol
165 && (world_rho_ - e->world_rho_).norm() < tol
166 && (world_omega_earth_ - e->world_omega_earth_).norm() < tol
167 && ((!body_P_sensor_ && !e->body_P_sensor_) || (body_P_sensor_ && e->body_P_sensor_ && body_P_sensor_->
equals(*e->body_P_sensor_)));
171 POSE predictPose(
const POSE& Pose1,
const VELOCITY& Vel1,
const IMUBIAS& Bias1)
const {
174 Vector delta_BiasAcc = Bias1.accelerometer();
175 Vector delta_BiasGyro = Bias1.gyroscope();
177 delta_BiasAcc -= Bias_initial_->accelerometer();
178 delta_BiasGyro -= Bias_initial_->gyroscope();
181 Matrix J_Pos_wrt_BiasAcc = Jacobian_wrt_t0_Overall_.block(4,9,3,3);
182 Matrix J_Pos_wrt_BiasGyro = Jacobian_wrt_t0_Overall_.block(4,12,3,3);
183 Matrix J_angles_wrt_BiasGyro = Jacobian_wrt_t0_Overall_.block(0,12,3,3);
186 Vector delta_pos_in_t0_corrected = delta_pos_in_t0_ + J_Pos_wrt_BiasAcc*delta_BiasAcc + J_Pos_wrt_BiasGyro*delta_BiasGyro;
189 Vector delta_angles_corrected = delta_angles_ + J_angles_wrt_BiasGyro*delta_BiasGyro;
193 return predictPose_inertial(Pose1, Vel1,
194 delta_pos_in_t0_corrected, delta_angles_corrected,
195 dt12_, world_g_, world_rho_, world_omega_earth_);
198 static inline POSE predictPose_inertial(
const POSE& Pose1,
const VELOCITY& Vel1,
199 const Vector& delta_pos_in_t0,
const Vector3& delta_angles,
200 const double dt12,
const Vector& world_g,
const Vector& world_rho,
const Vector& world_omega_earth){
202 const POSE& world_P1_body = Pose1;
203 const VELOCITY& world_V1_body = Vel1;
206 Vector body_deltaPos_body = delta_pos_in_t0;
208 Vector world_deltaPos_pls_body = world_P1_body.rotation().matrix() * body_deltaPos_body;
209 Vector world_deltaPos_body = world_V1_body * dt12 + 0.5*world_g*dt12*dt12 + world_deltaPos_pls_body;
212 world_deltaPos_body -= 2*
skewSymmetric(world_rho + world_omega_earth)*world_V1_body * dt12*dt12;
222 Vector body_deltaAngles_body = delta_angles;
225 Matrix body_R_world(world_P1_body.rotation().inverse().matrix());
226 Vector body_rho = body_R_world * world_rho;
227 Vector body_omega_earth = body_R_world * world_omega_earth;
230 body_deltaAngles_body -= (body_rho + body_omega_earth)*dt12;
232 return POSE(Pose1.rotation() * POSE::Rotation::Expmap(body_deltaAngles_body), Pose1.translation() +
typename POSE::Translation(world_deltaPos_body));
236 VELOCITY predictVelocity(
const POSE& Pose1,
const VELOCITY& Vel1,
const IMUBIAS& Bias1)
const {
239 Vector delta_BiasAcc = Bias1.accelerometer();
240 Vector delta_BiasGyro = Bias1.gyroscope();
242 delta_BiasAcc -= Bias_initial_->accelerometer();
243 delta_BiasGyro -= Bias_initial_->gyroscope();
246 Matrix J_Vel_wrt_BiasAcc = Jacobian_wrt_t0_Overall_.block(6,9,3,3);
247 Matrix J_Vel_wrt_BiasGyro = Jacobian_wrt_t0_Overall_.block(6,12,3,3);
249 Vector delta_vel_in_t0_corrected = delta_vel_in_t0_ + J_Vel_wrt_BiasAcc*delta_BiasAcc + J_Vel_wrt_BiasGyro*delta_BiasGyro;
251 return predictVelocity_inertial(Pose1, Vel1,
252 delta_vel_in_t0_corrected,
253 dt12_, world_g_, world_rho_, world_omega_earth_);
256 static inline VELOCITY predictVelocity_inertial(
const POSE& Pose1,
const VELOCITY& Vel1,
257 const Vector& delta_vel_in_t0,
258 const double dt12,
const Vector& world_g,
const Vector& world_rho,
const Vector& world_omega_earth) {
260 const POSE& world_P1_body = Pose1;
261 const VELOCITY& world_V1_body = Vel1;
263 Vector body_deltaVel_body = delta_vel_in_t0;
264 Vector world_deltaVel_body = world_P1_body.rotation().matrix() * body_deltaVel_body;
266 VELOCITY VelDelta( world_deltaVel_body + world_g * dt12 );
269 VelDelta -= 2*
skewSymmetric(world_rho + world_omega_earth)*world_V1_body * dt12;
272 return Vel1 + VelDelta;
276 void predict(
const POSE& Pose1,
const VELOCITY& Vel1,
const IMUBIAS& Bias1, POSE& Pose2, VELOCITY& Vel2)
const {
277 Pose2 = predictPose(Pose1, Vel1, Bias1);
278 Vel2 = predictVelocity(Pose1, Vel1, Bias1);
281 POSE evaluatePoseError(
const POSE& Pose1,
const VELOCITY& Vel1,
const IMUBIAS& Bias1,
const POSE& Pose2,
const VELOCITY& Vel2)
const {
283 POSE Pose2Pred = predictPose(Pose1, Vel1, Bias1);
286 POSE DiffPose( Pose2.rotation().between(Pose2Pred.rotation()), Pose2Pred.translation() - Pose2.translation() );
293 VELOCITY evaluateVelocityError(
const POSE& Pose1,
const VELOCITY& Vel1,
const IMUBIAS& Bias1,
const POSE& Pose2,
const VELOCITY& Vel2)
const {
295 VELOCITY Vel2Pred = predictVelocity(Pose1, Vel1, Bias1);
298 return Vel2Pred-Vel2;
301 Vector
evaluateError(
const POSE& Pose1,
const VELOCITY& Vel1,
const IMUBIAS& Bias1,
const POSE&
Pose2,
const VELOCITY& Vel2,
302 boost::optional<Matrix&> H1 = boost::none,
303 boost::optional<Matrix&> H2 = boost::none,
304 boost::optional<Matrix&> H3 = boost::none,
305 boost::optional<Matrix&> H4 = boost::none,
306 boost::optional<Matrix&> H5 = boost::none)
const override {
311 Matrix H1_Pose = numericalDerivative11<POSE, POSE>(
312 std::bind(&EquivInertialNavFactor_GlobalVel::evaluatePoseError,
313 this, std::placeholders::_1, Vel1, Bias1,
Pose2, Vel2),
315 Matrix H1_Vel = numericalDerivative11<VELOCITY, POSE>(
316 std::bind(&EquivInertialNavFactor_GlobalVel::evaluateVelocityError,
317 this, std::placeholders::_1, Vel1, Bias1,
Pose2, Vel2),
319 *H1 =
stack(2, &H1_Pose, &H1_Vel);
324 if (Vel1.size()!=3)
throw std::runtime_error(
"Frank's hack to make this compile will not work if size != 3");
325 Matrix H2_Pose = numericalDerivative11<POSE, Vector3>(
326 std::bind(&EquivInertialNavFactor_GlobalVel::evaluatePoseError,
327 this, Pose1, std::placeholders::_1, Bias1,
Pose2, Vel2),
329 Matrix H2_Vel = numericalDerivative11<Vector3, Vector3>(
330 std::bind(&EquivInertialNavFactor_GlobalVel::evaluateVelocityError,
331 this, Pose1, std::placeholders::_1, Bias1,
Pose2, Vel2),
333 *H2 =
stack(2, &H2_Pose, &H2_Vel);
338 Matrix H3_Pose = numericalDerivative11<POSE, IMUBIAS>(
339 std::bind(&EquivInertialNavFactor_GlobalVel::evaluatePoseError,
340 this, Pose1, Vel1, std::placeholders::_1,
Pose2, Vel2),
342 Matrix H3_Vel = numericalDerivative11<VELOCITY, IMUBIAS>(
343 std::bind(&EquivInertialNavFactor_GlobalVel::evaluateVelocityError,
344 this, Pose1, Vel1, std::placeholders::_1,
Pose2, Vel2),
346 *H3 =
stack(2, &H3_Pose, &H3_Vel);
351 Matrix H4_Pose = numericalDerivative11<POSE, POSE>(
352 std::bind(&EquivInertialNavFactor_GlobalVel::evaluatePoseError,
353 this, Pose1, Vel1, Bias1, std::placeholders::_1, Vel2),
355 Matrix H4_Vel = numericalDerivative11<VELOCITY, POSE>(
356 std::bind(&EquivInertialNavFactor_GlobalVel::evaluateVelocityError,
357 this, Pose1, Vel1, Bias1, std::placeholders::_1, Vel2),
359 *H4 =
stack(2, &H4_Pose, &H4_Vel);
364 if (Vel2.size()!=3)
throw std::runtime_error(
"Frank's hack to make this compile will not work if size != 3");
365 Matrix H5_Pose = numericalDerivative11<POSE, Vector3>(
366 std::bind(&EquivInertialNavFactor_GlobalVel::evaluatePoseError,
367 this, Pose1, Vel1, Bias1,
Pose2, std::placeholders::_1),
369 Matrix H5_Vel = numericalDerivative11<Vector3, Vector3>(
370 std::bind(&EquivInertialNavFactor_GlobalVel::evaluateVelocityError,
371 this, Pose1, Vel1, Bias1,
Pose2, std::placeholders::_1),
373 *H5 =
stack(2, &H5_Pose, &H5_Vel);
376 Vector ErrPoseVector(POSE::Logmap(evaluatePoseError(Pose1, Vel1, Bias1,
Pose2, Vel2)));
377 Vector ErrVelVector(evaluateVelocityError(Pose1, Vel1, Bias1,
Pose2, Vel2));
384 static inline POSE PredictPoseFromPreIntegration(
const POSE& Pose1,
const VELOCITY& Vel1,
const IMUBIAS& Bias1,
385 const Vector& delta_pos_in_t0,
const Vector3& delta_angles,
386 double dt12,
const Vector world_g,
const Vector world_rho,
387 const Vector& world_omega_earth,
const Matrix& Jacobian_wrt_t0_Overall,
388 const boost::optional<IMUBIAS>& Bias_initial = boost::none) {
392 Vector delta_BiasAcc = Bias1.accelerometer();
393 Vector delta_BiasGyro = Bias1.gyroscope();
395 delta_BiasAcc -= Bias_initial->accelerometer();
396 delta_BiasGyro -= Bias_initial->gyroscope();
399 Matrix J_Pos_wrt_BiasAcc = Jacobian_wrt_t0_Overall.block(4,9,3,3);
400 Matrix J_Pos_wrt_BiasGyro = Jacobian_wrt_t0_Overall.block(4,12,3,3);
401 Matrix J_angles_wrt_BiasGyro = Jacobian_wrt_t0_Overall.block(0,12,3,3);
404 Vector delta_pos_in_t0_corrected = delta_pos_in_t0 + J_Pos_wrt_BiasAcc*delta_BiasAcc + J_Pos_wrt_BiasGyro*delta_BiasGyro;
407 Vector delta_angles_corrected = delta_angles + J_angles_wrt_BiasGyro*delta_BiasGyro;
411 return predictPose_inertial(Pose1, Vel1, delta_pos_in_t0_corrected, delta_angles_corrected, dt12, world_g, world_rho, world_omega_earth);
414 static inline VELOCITY PredictVelocityFromPreIntegration(
const POSE& Pose1,
const VELOCITY& Vel1,
const IMUBIAS& Bias1,
415 const Vector& delta_vel_in_t0,
double dt12,
const Vector world_g,
const Vector world_rho,
416 const Vector& world_omega_earth,
const Matrix& Jacobian_wrt_t0_Overall,
417 const boost::optional<IMUBIAS>& Bias_initial = boost::none) {
420 Vector delta_BiasAcc = Bias1.accelerometer();
421 Vector delta_BiasGyro = Bias1.gyroscope();
423 delta_BiasAcc -= Bias_initial->accelerometer();
424 delta_BiasGyro -= Bias_initial->gyroscope();
427 Matrix J_Vel_wrt_BiasAcc = Jacobian_wrt_t0_Overall.block(6,9,3,3);
428 Matrix J_Vel_wrt_BiasGyro = Jacobian_wrt_t0_Overall.block(6,12,3,3);
430 Vector delta_vel_in_t0_corrected = delta_vel_in_t0 + J_Vel_wrt_BiasAcc*delta_BiasAcc + J_Vel_wrt_BiasGyro*delta_BiasGyro;
432 return predictVelocity_inertial(Pose1, Vel1, delta_vel_in_t0_corrected, dt12, world_g, world_rho, world_omega_earth);
435 static inline void PredictFromPreIntegration(
const POSE& Pose1,
const VELOCITY& Vel1,
const IMUBIAS& Bias1, POSE& Pose2, VELOCITY& Vel2,
436 const Vector& delta_pos_in_t0,
const Vector& delta_vel_in_t0,
const Vector3& delta_angles,
437 double dt12,
const Vector world_g,
const Vector world_rho,
438 const Vector& world_omega_earth,
const Matrix& Jacobian_wrt_t0_Overall,
439 const boost::optional<IMUBIAS>& Bias_initial = boost::none) {
441 Pose2 = PredictPoseFromPreIntegration(Pose1, Vel1, Bias1, delta_pos_in_t0, delta_angles, dt12, world_g, world_rho, world_omega_earth, Jacobian_wrt_t0_Overall, Bias_initial);
442 Vel2 = PredictVelocityFromPreIntegration(Pose1, Vel1, Bias1, delta_vel_in_t0, dt12, world_g, world_rho, world_omega_earth, Jacobian_wrt_t0_Overall, Bias_initial);
446 static inline void PreIntegrateIMUObservations(
const Vector& msr_acc_t,
const Vector& msr_gyro_t,
const double msr_dt,
447 Vector& delta_pos_in_t0, Vector3& delta_angles, Vector& delta_vel_in_t0,
double& delta_t,
448 const noiseModel::Gaussian::shared_ptr& model_continuous_overall,
449 Matrix& EquivCov_Overall, Matrix& Jacobian_wrt_t0_Overall,
const IMUBIAS Bias_t0 = IMUBIAS(),
450 boost::optional<POSE> p_body_P_sensor = boost::none){
454 POSE body_P_sensor = POSE();
455 bool flag_use_body_P_sensor =
false;
456 if (p_body_P_sensor){
457 body_P_sensor = *p_body_P_sensor;
458 flag_use_body_P_sensor =
true;
461 delta_pos_in_t0 = PreIntegrateIMUObservations_delta_pos(msr_dt, delta_pos_in_t0, delta_vel_in_t0);
462 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, Bias_t0);
463 delta_angles = PreIntegrateIMUObservations_delta_angles(msr_gyro_t, msr_dt, delta_angles, flag_use_body_P_sensor, body_P_sensor, Bias_t0);
468 Matrix Z_3x3 = Z_3x3;
469 Matrix I_3x3 = I_3x3;
471 Matrix H_pos_pos = numericalDerivative11<Vector3, Vector3>(
472 std::bind(&PreIntegrateIMUObservations_delta_pos, msr_dt,
473 std::placeholders::_1, delta_vel_in_t0),
475 Matrix H_pos_vel = numericalDerivative11<Vector3, Vector3>(
476 std::bind(&PreIntegrateIMUObservations_delta_pos, msr_dt,
477 delta_pos_in_t0, std::placeholders::_1),
479 Matrix H_pos_angles = Z_3x3;
480 Matrix H_pos_bias =
collect(2, &Z_3x3, &Z_3x3);
482 Matrix H_vel_vel = numericalDerivative11<Vector3, Vector3>(
483 std::bind(&PreIntegrateIMUObservations_delta_vel, msr_gyro_t,
484 msr_acc_t, msr_dt, delta_angles, std::placeholders::_1,
485 flag_use_body_P_sensor, body_P_sensor, Bias_t0),
487 Matrix H_vel_angles = numericalDerivative11<Vector3, Vector3>(
488 std::bind(&PreIntegrateIMUObservations_delta_vel, msr_gyro_t,
489 msr_acc_t, msr_dt, std::placeholders::_1, delta_vel_in_t0,
490 flag_use_body_P_sensor, body_P_sensor, Bias_t0),
492 Matrix H_vel_bias = numericalDerivative11<Vector3, IMUBIAS>(
493 std::bind(&PreIntegrateIMUObservations_delta_vel, msr_gyro_t,
494 msr_acc_t, msr_dt, delta_angles, delta_vel_in_t0,
495 flag_use_body_P_sensor, body_P_sensor,
496 std::placeholders::_1),
498 Matrix H_vel_pos = Z_3x3;
500 Matrix H_angles_angles = numericalDerivative11<Vector3, Vector3>(
501 std::bind(&PreIntegrateIMUObservations_delta_angles, msr_gyro_t,
502 msr_dt, std::placeholders::_1, flag_use_body_P_sensor,
503 body_P_sensor, Bias_t0),
505 Matrix H_angles_bias = numericalDerivative11<Vector3, IMUBIAS>(
506 std::bind(&PreIntegrateIMUObservations_delta_angles, msr_gyro_t,
507 msr_dt, delta_angles, flag_use_body_P_sensor, body_P_sensor,
508 std::placeholders::_1),
510 Matrix H_angles_pos = Z_3x3;
511 Matrix H_angles_vel = Z_3x3;
513 Matrix F_angles =
collect(4, &H_angles_angles, &H_angles_pos, &H_angles_vel, &H_angles_bias);
514 Matrix F_pos =
collect(4, &H_pos_angles, &H_pos_pos, &H_pos_vel, &H_pos_bias);
515 Matrix F_vel =
collect(4, &H_vel_angles, &H_vel_pos, &H_vel_vel, &H_vel_bias);
516 Matrix F_bias_a =
collect(5, &Z_3x3, &Z_3x3, &Z_3x3, &I_3x3, &Z_3x3);
517 Matrix F_bias_g =
collect(5, &Z_3x3, &Z_3x3, &Z_3x3, &Z_3x3, &I_3x3);
518 Matrix F =
stack(5, &F_angles, &F_pos, &F_vel, &F_bias_a, &F_bias_g);
521 noiseModel::Gaussian::shared_ptr model_discrete_curr = calc_descrete_noise_model(model_continuous_overall, msr_dt );
522 Matrix Q_d = (model_discrete_curr->R().transpose() * model_discrete_curr->R()).
inverse();
524 EquivCov_Overall = F * EquivCov_Overall * F.transpose() + Q_d;
529 Jacobian_wrt_t0_Overall = F * Jacobian_wrt_t0_Overall;
532 static inline Vector PreIntegrateIMUObservations_delta_pos(
const double msr_dt,
533 const Vector& delta_pos_in_t0,
const Vector& delta_vel_in_t0){
538 return delta_pos_in_t0 + delta_vel_in_t0 * msr_dt;
543 static inline Vector PreIntegrateIMUObservations_delta_vel(
const Vector& msr_gyro_t,
const Vector& msr_acc_t,
const double msr_dt,
544 const Vector3& delta_angles,
const Vector& delta_vel_in_t0,
const bool flag_use_body_P_sensor,
const POSE& body_P_sensor,
545 IMUBIAS Bias_t0 = IMUBIAS()){
550 Vector AccCorrected = Bias_t0.correctAccelerometer(msr_acc_t);
551 Vector body_t_a_body;
552 if (flag_use_body_P_sensor){
553 Matrix body_R_sensor = body_P_sensor.rotation().matrix();
555 Vector GyroCorrected(Bias_t0.correctGyroscope(msr_gyro_t));
557 Vector body_omega_body = body_R_sensor * GyroCorrected;
558 Matrix body_omega_body__cross =
skewSymmetric(body_omega_body);
560 body_t_a_body = body_R_sensor * AccCorrected - body_omega_body__cross * body_omega_body__cross * body_P_sensor.translation().vector();
562 body_t_a_body = AccCorrected;
567 return delta_vel_in_t0 + R_t_to_t0.matrix() * body_t_a_body * msr_dt;
571 static inline Vector PreIntegrateIMUObservations_delta_angles(
const Vector& msr_gyro_t,
const double msr_dt,
572 const Vector3& delta_angles,
const bool flag_use_body_P_sensor,
const POSE& body_P_sensor,
573 IMUBIAS Bias_t0 = IMUBIAS()){
578 Vector GyroCorrected = Bias_t0.correctGyroscope(msr_gyro_t);
580 Vector body_t_omega_body;
581 if (flag_use_body_P_sensor){
582 body_t_omega_body = body_P_sensor.rotation().matrix() * GyroCorrected;
584 body_t_omega_body = GyroCorrected;
589 R_t_to_t0 = R_t_to_t0 *
Rot3::Expmap( body_t_omega_body*msr_dt );
594 static inline noiseModel::Gaussian::shared_ptr CalcEquivalentNoiseCov(
const noiseModel::Gaussian::shared_ptr& gaussian_acc,
const noiseModel::Gaussian::shared_ptr& gaussian_gyro,
595 const noiseModel::Gaussian::shared_ptr& gaussian_process){
597 Matrix cov_acc = ( gaussian_acc->R().transpose() * gaussian_acc->R() ).
inverse();
598 Matrix cov_gyro = ( gaussian_gyro->R().transpose() * gaussian_gyro->R() ).
inverse();
599 Matrix cov_process = ( gaussian_process->R().transpose() * gaussian_process->R() ).
inverse();
601 cov_process.block(0,0, 3,3) += cov_gyro;
602 cov_process.block(6,6, 3,3) += cov_acc;
607 static inline void CalcEquivalentNoiseCov_DifferentParts(
const noiseModel::Gaussian::shared_ptr& gaussian_acc,
const noiseModel::Gaussian::shared_ptr& gaussian_gyro,
608 const noiseModel::Gaussian::shared_ptr& gaussian_process,
609 Matrix& cov_acc, Matrix& cov_gyro, Matrix& cov_process_without_acc_gyro){
611 cov_acc = ( gaussian_acc->R().transpose() * gaussian_acc->R() ).
inverse();
612 cov_gyro = ( gaussian_gyro->R().transpose() * gaussian_gyro->R() ).
inverse();
613 cov_process_without_acc_gyro = ( gaussian_process->R().transpose() * gaussian_process->R() ).
inverse();
616 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,
617 Vector& g_NED, Vector& rho_NED, Vector& omega_earth_NED) {
619 Matrix ENU_to_NED = (Matrix(3, 3) <<
622 0.0, 0.0, -1.0).finished();
624 Matrix NED_to_ENU = (Matrix(3, 3) <<
627 0.0, 0.0, -1.0).finished();
630 Vector Pos_ENU = NED_to_ENU * Pos_NED;
631 Vector Vel_ENU = NED_to_ENU * Vel_NED;
632 Vector Pos_ENU_Initial = NED_to_ENU * Pos_NED_Initial;
637 Vector omega_earth_ENU;
638 Calc_g_rho_omega_earth_ENU(Pos_ENU, Vel_ENU, LatLonHeight_IC, Pos_ENU_Initial, g_ENU, rho_ENU, omega_earth_ENU);
641 g_NED = ENU_to_NED * g_ENU;
642 rho_NED = ENU_to_NED * rho_ENU;
643 omega_earth_NED = ENU_to_NED * omega_earth_ENU;
646 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,
647 Vector& g_ENU, Vector& rho_ENU, Vector& omega_earth_ENU){
648 double R0 = 6.378388e6;
650 double Re( R0*( 1-e*(sin( LatLonHeight_IC(0) ))*(sin( LatLonHeight_IC(0) )) ) );
653 Vector delta_Pos_ENU(Pos_ENU - Pos_ENU_Initial);
654 double delta_lat(delta_Pos_ENU(1)/Re);
655 double delta_lon(delta_Pos_ENU(0)/(Re*cos(LatLonHeight_IC(0))));
656 double lat_new(LatLonHeight_IC(0) + delta_lat);
657 double lon_new(LatLonHeight_IC(1) + delta_lon);
660 Rot3 C1(cos(lon_new), sin(lon_new), 0.0,
661 -sin(lon_new), cos(lon_new), 0.0,
665 Rot3 C2(cos(lat_new), 0.0, sin(lat_new),
667 -sin(lat_new), 0.0, cos(lat_new));
669 Rot3 UEN_to_ENU(0, 1, 0,
673 Rot3 R_ECEF_to_ENU( UEN_to_ENU * C2 * C1 );
675 Vector omega_earth_ECEF(Vector3(0.0, 0.0, 7.292115e-5));
676 omega_earth_ENU = R_ECEF_to_ENU.matrix() * omega_earth_ECEF;
679 double height(LatLonHeight_IC(2));
680 double EQUA_RADIUS = 6378137.0;
681 double ECCENTRICITY = 0.0818191908426;
682 double e2( pow(ECCENTRICITY,2) );
683 double den( 1-e2*pow(sin(lat_new),2) );
684 double Rm( (EQUA_RADIUS*(1-e2))/( pow(den,(3/2)) ) );
685 double Rp( EQUA_RADIUS/( sqrt(den) ) );
686 double Ro( sqrt(Rp*Rm) );
687 double g0( 9.780318*( 1 + 5.3024e-3 * pow(sin(lat_new),2) - 5.9e-6 * pow(sin(2*lat_new),2) ) );
688 double g_calc( g0/( pow(1 + height/Ro, 2) ) );
689 g_ENU = (Vector(3) << 0.0, 0.0, -g_calc).finished();
693 double Ve( Vel_ENU(0) );
694 double Vn( Vel_ENU(1) );
695 double rho_E = -Vn/(Rm + height);
696 double rho_N = Ve/(Rp + height);
697 double rho_U = Ve*tan(lat_new)/(Rp + height);
698 rho_ENU = (Vector(3) << rho_E, rho_N, rho_U).finished();
701 static inline noiseModel::Gaussian::shared_ptr calc_descrete_noise_model(
const noiseModel::Gaussian::shared_ptr& model,
double delta_t){
712 template<
class ARCHIVE>
713 void serialize(ARCHIVE & ar,
const unsigned int ) {
714 ar & boost::serialization::make_nvp(
"NonlinearFactor2",
715 boost::serialization::base_object<Base>(*
this));
typedef and functions to augment Eigen's MatrixXd
Some functions to compute numerical derivatives.
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
Matrix stack(size_t nrMatrices,...)
create a matrix by stacking other matrices Given a set of matrices: A1, A2, A3...
Definition: Matrix.cpp:396
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:404
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:442
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:69
Vector concatVectors(const std::list< Vector > &vs)
concatenate Vectors
Definition: Vector.cpp:302
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
static Vector3 Logmap(const Rot3 &R, OptionalJacobian< 3, 3 > H=boost::none)
Log map at identity - returns the canonical coordinates of this rotation.
Definition: Rot3M.cpp:158
static Rot3 Expmap(const Vector3 &v, OptionalJacobian< 3, 3 > H=boost::none)
Exponential map at identity - create a rotation from canonical coordinates using Rodrigues' formula.
Definition: Rot3.h:377
This is the base class for all factor types.
Definition: Factor.h:56
bool equals(const This &other, double tol=1e-9) const
check equality
Definition: Factor.cpp:42
static shared_ptr Covariance(const Matrix &covariance, bool smart=true)
A Gaussian noise model created by specifying a covariance matrix.
Definition: NoiseModel.cpp:116
static shared_ptr SqrtInformation(const Matrix &R, bool smart=true)
A Gaussian noise model created by specifying a square root information matrix.
Definition: NoiseModel.cpp:85
Nonlinear factor base class.
Definition: NonlinearFactor.h:43
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
Check if two factors are equal.
Definition: NonlinearFactor.cpp:71
A convenient base class for creating your own NoiseModelFactor with 5 variables.
Definition: NonlinearFactor.h:602
Key key1() const
methods to retrieve keys
Definition: NonlinearFactor.h:640
Definition: EquivInertialNavFactor_GlobalVel.h:91
void print(const std::string &s="EquivInertialNavFactor_GlobalVel", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
implement functions needed for Testable
Definition: EquivInertialNavFactor_GlobalVel.h:137
Vector evaluateError(const POSE &Pose1, const VELOCITY &Vel1, const IMUBIAS &Bias1, const POSE &Pose2, const VELOCITY &Vel2, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none, boost::optional< Matrix & > H3=boost::none, boost::optional< Matrix & > H4=boost::none, boost::optional< Matrix & > H5=boost::none) const override
Override this method to finish implementing a 5-way factor.
Definition: EquivInertialNavFactor_GlobalVel.h:301
EquivInertialNavFactor_GlobalVel(const Key &Pose1, const Key &Vel1, const Key &IMUBias1, 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, boost::optional< IMUBIAS > Bias_initial=boost::none, boost::optional< POSE > body_P_sensor=boost::none)
Constructor.
Definition: EquivInertialNavFactor_GlobalVel.h:121
friend class boost::serialization::access
Serialization function.
Definition: EquivInertialNavFactor_GlobalVel.h:711
EquivInertialNavFactor_GlobalVel()
default constructor - only use for serialization
Definition: EquivInertialNavFactor_GlobalVel.h:118
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
equals
Definition: EquivInertialNavFactor_GlobalVel.h:157