88 template<
class POSE,
class VELOCITY>
115 typedef typename std::shared_ptr<EquivInertialNavFactor_GlobalVel_NoBias>
shared_ptr;
125 const Matrix& Jacobian_wrt_t0_Overall,
127 Base(model_equivalent, Pose1, Vel1,
Pose2, Vel2),
138 const std::string&
s =
"EquivInertialNavFactor_GlobalVel_NoBias",
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: ");
181 delta_pos_in_t0_corrected, delta_angles_corrected,
189 const POSE& world_P1_body = Pose1;
190 const VELOCITY& world_V1_body = Vel1;
193 Vector body_deltaPos_body = delta_pos_in_t0;
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;
209 Vector body_deltaAngles_body = delta_angles;
212 Matrix body_R_world(world_P1_body.rotation().inverse().matrix());
217 body_deltaAngles_body -= (body_rho + body_omega_earth)*dt12;
219 return POSE(Pose1.rotation() *
POSE::Rotation::Expmap(body_deltaAngles_body), Pose1.translation() +
typename POSE::Translation(world_deltaPos_body));
229 delta_vel_in_t0_corrected,
234 const Vector& delta_vel_in_t0,
237 const POSE& world_P1_body = Pose1;
238 const VELOCITY& world_V1_body = Vel1;
240 Vector body_deltaVel_body = delta_vel_in_t0;
241 Vector world_deltaVel_body = world_P1_body.rotation().matrix() * body_deltaVel_body;
243 VELOCITY VelDelta( world_deltaVel_body +
world_g * dt12 );
249 return Vel1.compose( VelDelta );
253 void predict(
const POSE& Pose1,
const VELOCITY& Vel1, POSE&
Pose2, VELOCITY& Vel2)
const {
271 return Vel2.between(Vel2Pred);
283 *H1 =
stack(2, &H1_Pose, &H1_Vel);
290 *H2 =
stack(2, &H2_Pose, &H2_Vel);
297 *H3 =
stack(2, &H3_Pose, &H3_Vel);
304 *H4 =
stack(2, &H4_Pose, &H4_Vel);
321 Vector delta_pos_in_t0_corrected = delta_pos_in_t0;
324 Vector delta_angles_corrected = delta_angles;
335 Vector delta_vel_in_t0_corrected = delta_vel_in_t0;
353 Matrix& EquivCov_Overall,
Matrix& Jacobian_wrt_t0_Overall,
354 std::optional<POSE> p_body_P_sensor = {}){
359 bool flag_use_body_P_sensor =
false;
360 if (p_body_P_sensor){
362 flag_use_body_P_sensor =
true;
377 Matrix H_pos_angles = Z_3x3;
384 Matrix H_angles_pos = Z_3x3;
385 Matrix H_angles_vel = Z_3x3;
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);
393 Matrix Q_d =
inverse(model_discrete_curr->R().transpose() * model_discrete_curr->R() );
395 EquivCov_Overall =
F * EquivCov_Overall *
F.transpose() + Q_d;
398 Jacobian_wrt_t0_Overall =
F * Jacobian_wrt_t0_Overall;
402 const Vector& delta_pos_in_t0,
const Vector& delta_vel_in_t0){
407 return delta_pos_in_t0 + delta_vel_in_t0 * msr_dt;
418 Vector AccCorrected = msr_acc_t;
420 if (flag_use_body_P_sensor){
423 Vector GyroCorrected(msr_gyro_t);
425 Vector body_omega_body = body_R_sensor * GyroCorrected;
428 body_t_a_body = body_R_sensor * AccCorrected - body_omega_body__cross * body_omega_body__cross *
body_P_sensor.translation().vector();
430 body_t_a_body = AccCorrected;
435 return delta_vel_in_t0 + R_t_to_t0.
matrix() * body_t_a_body * msr_dt;
445 Vector GyroCorrected = msr_gyro_t;
448 if (flag_use_body_P_sensor){
449 body_t_omega_body =
body_P_sensor.rotation().matrix() * GyroCorrected;
451 body_t_omega_body = GyroCorrected;
456 R_t_to_t0 = R_t_to_t0 *
Rot3::Expmap( body_t_omega_body*msr_dt );
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() );
467 cov_process.block(0,0, 3,3) += cov_gyro;
468 cov_process.block(6,6, 3,3) += cov_acc;
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() );
488 0.0, 0.0, -1.0).finished();
493 0.0, 0.0, -1.0).finished();
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;
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;
514 double R0 = 6.378388e6;
516 double Re(
R0*( 1-
e*(
sin( LatLonHeight_IC(0) ))*(
sin( LatLonHeight_IC(0) )) ) );
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);
527 -
sin(lon_new),
cos(lon_new), 0.0,
533 -
sin(lat_new), 0.0,
cos(lat_new));
535 Rot3 UEN_to_ENU(0, 1, 0,
539 Rot3 R_ECEF_to_ENU( UEN_to_ENU *
C2 *
C1 );
541 Vector omega_earth_ECEF((
Vector(3) << 0.0, 0.0, 7.292115
e-5));
542 omega_earth_ENU = R_ECEF_to_ENU.
matrix() * omega_earth_ECEF;
545 double height(LatLonHeight_IC(2));
546 double EQUA_RADIUS = 6378137.0;
547 double ECCENTRICITY = 0.0818191908426;
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) );
553 double g0( 9.780318*( 1 + 5.3024
e-3 *
pow(
sin(lat_new),2) - 5.9
e-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);
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);
576 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
578 friend class boost::serialization::access;
579 template<
class ARCHIVE>
580 void serialize(ARCHIVE & ar,
const unsigned int ) {
581 ar & boost::serialization::make_nvp(
"NonlinearFactor2",
582 boost::serialization::base_object<Base>(*
this));