76 template<
class POSE,
class VELOCITY,
class IMUBIAS>
100 typedef typename std::shared_ptr<InertialNavFactor_GlobalVelocity>
shared_ptr;
119 std::cout <<
s <<
"(" 120 << keyFormatter(this->
key1()) <<
"," 121 << keyFormatter(this->
key2()) <<
"," 122 << keyFormatter(this->
key3()) <<
"," 123 << keyFormatter(this->
key4()) <<
"," 124 << keyFormatter(this->
key5()) <<
"\n";
125 std::cout <<
"acc measurement: " << this->measurement_acc_.transpose() << std::endl;
126 std::cout <<
"gyro measurement: " << this->measurement_gyro_.transpose() << std::endl;
127 std::cout <<
"dt: " << this->dt_ << std::endl;
128 std::cout <<
"gravity (in world frame): " << this->world_g_.transpose() << std::endl;
129 std::cout <<
"craft rate (in world frame): " << this->world_rho_.transpose() << std::endl;
130 std::cout <<
"earth's rotation (in world frame): " << this->world_omega_earth_.transpose() << std::endl;
131 if(this->body_P_sensor_)
132 this->body_P_sensor_->print(
" sensor pose in body frame: ");
138 const This *
e =
dynamic_cast<const This*
> (&
expected);
140 && (measurement_acc_ - e->measurement_acc_).norm() <
tol 141 && (measurement_gyro_ - e->measurement_gyro_).norm() <
tol 142 && (dt_ - e->dt_) <
tol 143 && (world_g_ - e->world_g_).norm() <
tol 144 && (world_rho_ - e->world_rho_).norm() <
tol 145 && (world_omega_earth_ - e->world_omega_earth_).norm() <
tol 146 && ((!body_P_sensor_ && !e->body_P_sensor_) || (body_P_sensor_ && e->body_P_sensor_ && body_P_sensor_->
equals(*e->body_P_sensor_)));
149 POSE
predictPose(
const POSE& Pose1,
const VELOCITY& Vel1,
const IMUBIAS& Bias1)
const {
151 Vector GyroCorrected(Bias1.correctGyroscope(measurement_gyro_));
153 const POSE& world_P1_body = Pose1;
154 const VELOCITY& world_V1_body = Vel1;
159 body_omega_body = body_P_sensor_->rotation().matrix() * GyroCorrected;
161 body_omega_body = GyroCorrected;
165 Matrix body_R_world(world_P1_body.rotation().inverse().matrix());
170 body_omega_body -= body_rho + body_omega_earth;
173 return POSE(Pose1.rotation() *
POSE::Rotation::Expmap(body_omega_body*dt_), Pose1.translation() +
typename POSE::Translation(world_V1_body*dt_));
176 VELOCITY
predictVelocity(
const POSE& Pose1,
const VELOCITY& Vel1,
const IMUBIAS& Bias1)
const {
178 Vector AccCorrected(Bias1.correctAccelerometer(measurement_acc_));
180 const POSE& world_P1_body = Pose1;
181 const VELOCITY& world_V1_body = Vel1;
184 Vector body_a_body, body_omega_body;
186 Matrix body_R_sensor = body_P_sensor_->rotation().matrix();
188 Vector GyroCorrected(Bias1.correctGyroscope(measurement_gyro_));
189 body_omega_body = body_R_sensor * GyroCorrected;
191 body_a_body = body_R_sensor * AccCorrected - body_omega_body__cross * body_omega_body__cross * body_P_sensor_->translation();
193 body_a_body = AccCorrected;
197 Vector world_a_body = world_P1_body.rotation().matrix() * body_a_body + world_g_ - 2*
skewSymmetric(world_rho_ + world_omega_earth_)*world_V1_body;
200 VELOCITY VelDelta(world_a_body*dt_);
203 return Vel1 + VelDelta;
206 void predict(
const POSE& Pose1,
const VELOCITY& Vel1,
const IMUBIAS& Bias1, POSE& Pose2, VELOCITY& Vel2)
const {
211 POSE
evaluatePoseError(
const POSE& Pose1,
const VELOCITY& Vel1,
const IMUBIAS& Bias1,
const POSE& Pose2,
const VELOCITY& Vel2)
const {
216 return Pose2.between(Pose2Pred);
219 VELOCITY
evaluateVelocityError(
const POSE& Pose1,
const VELOCITY& Vel1,
const IMUBIAS& Bias1,
const POSE& Pose2,
const VELOCITY& Vel2)
const {
224 return Vel2Pred - Vel2;
228 Vector evaluateError(
const POSE& Pose1,
const VELOCITY& Vel1,
const IMUBIAS& Bias1,
const POSE& Pose2,
const VELOCITY& Vel2,
235 Matrix H1_Pose = gtsam::numericalDerivative11<POSE, POSE>(
237 this, std::placeholders::_1, Vel1, Bias1, Pose2, Vel2),
239 Matrix H1_Vel = gtsam::numericalDerivative11<VELOCITY, POSE>(
241 this, std::placeholders::_1, Vel1, Bias1, Pose2, Vel2),
243 *H1 =
stack(2, &H1_Pose, &H1_Vel);
248 if (Vel1.size()!=3)
throw std::runtime_error(
"Frank's hack to make this compile will not work if size != 3");
249 Matrix H2_Pose = gtsam::numericalDerivative11<POSE, Vector3>(
251 this, Pose1, std::placeholders::_1, Bias1, Pose2, Vel2),
253 Matrix H2_Vel = gtsam::numericalDerivative11<Vector3, Vector3>(
255 this, Pose1, std::placeholders::_1, Bias1, Pose2, Vel2),
257 *H2 =
stack(2, &H2_Pose, &H2_Vel);
262 Matrix H3_Pose = gtsam::numericalDerivative11<POSE, IMUBIAS>(
264 this, Pose1, Vel1, std::placeholders::_1, Pose2, Vel2),
266 Matrix H3_Vel = gtsam::numericalDerivative11<VELOCITY, IMUBIAS>(
268 this, Pose1, Vel1, std::placeholders::_1, Pose2, Vel2),
270 *H3 =
stack(2, &H3_Pose, &H3_Vel);
275 Matrix H4_Pose = gtsam::numericalDerivative11<POSE, POSE>(
277 this, Pose1, Vel1, Bias1, std::placeholders::_1, Vel2),
279 Matrix H4_Vel = gtsam::numericalDerivative11<VELOCITY, POSE>(
281 this, Pose1, Vel1, Bias1, std::placeholders::_1, Vel2),
283 *H4 =
stack(2, &H4_Pose, &H4_Vel);
288 if (Vel2.size()!=3)
throw std::runtime_error(
"Frank's hack to make this compile will not work if size != 3");
289 Matrix H5_Pose = gtsam::numericalDerivative11<POSE, Vector3>(
291 this, Pose1, Vel1, Bias1, Pose2, std::placeholders::_1),
293 Matrix H5_Vel = gtsam::numericalDerivative11<Vector3, Vector3>(
295 this, Pose1, Vel1, Bias1, Pose2, std::placeholders::_1),
297 *H5 =
stack(2, &H5_Pose, &H5_Vel);
309 Matrix cov_acc = ( gaussian_acc->R().transpose() * gaussian_acc->R() ).
inverse();
310 Matrix cov_gyro = ( gaussian_gyro->R().transpose() * gaussian_gyro->R() ).
inverse();
311 Matrix cov_process = ( gaussian_process->R().transpose() * gaussian_process->R() ).
inverse();
313 cov_process.block(0,0, 3,3) += cov_gyro;
314 cov_process.block(6,6, 3,3) += cov_acc;
325 0.0, 0.0, -1.0).finished();
330 0.0, 0.0, -1.0).finished();
333 Vector Pos_ENU = NED_to_ENU * Pos_NED;
334 Vector Vel_ENU = NED_to_ENU * Vel_NED;
335 Vector Pos_ENU_Initial = NED_to_ENU * Pos_NED_Initial;
344 g_NED = ENU_to_NED * g_ENU;
345 rho_NED = ENU_to_NED * rho_ENU;
346 omega_earth_NED = ENU_to_NED * omega_earth_ENU;
351 double R0 = 6.378388e6;
353 double Re( R0*( 1-e*(
sin( LatLonHeight_IC(0) ))*(
sin( LatLonHeight_IC(0) )) ) );
356 Vector delta_Pos_ENU(Pos_ENU - Pos_ENU_Initial);
357 double delta_lat(delta_Pos_ENU(1)/Re);
358 double delta_lon(delta_Pos_ENU(0)/(Re*
cos(LatLonHeight_IC(0))));
359 double lat_new(LatLonHeight_IC(0) + delta_lat);
360 double lon_new(LatLonHeight_IC(1) + delta_lon);
364 -
sin(lon_new),
cos(lon_new), 0.0,
370 -
sin(lat_new), 0.0,
cos(lat_new));
372 Rot3 UEN_to_ENU(0, 1, 0,
376 Rot3 R_ECEF_to_ENU( UEN_to_ENU * C2 * C1 );
379 omega_earth_ENU = R_ECEF_to_ENU.
matrix() * omega_earth_ECEF;
382 double height(LatLonHeight_IC(2));
383 double EQUA_RADIUS = 6378137.0;
384 double ECCENTRICITY = 0.0818191908426;
385 double e2(
pow(ECCENTRICITY,2) );
386 double den( 1-e2*
pow(
sin(lat_new),2) );
387 double Rm( (EQUA_RADIUS*(1-e2))/(
pow(den,(3/2)) ) );
388 double Rp( EQUA_RADIUS/(
sqrt(den) ) );
389 double Ro(
sqrt(Rp*Rm) );
390 double g0( 9.780318*( 1 + 5.3024e-3 *
pow(
sin(lat_new),2) - 5.9e-6 *
pow(
sin(2*lat_new),2) ) );
391 double g_calc( g0/(
pow(1 + height/Ro, 2) ) );
392 g_ENU = (
Vector(3) << 0.0, 0.0, -g_calc).finished();
396 double Ve( Vel_ENU(0) );
397 double Vn( Vel_ENU(1) );
398 double rho_E = -Vn/(Rm + height);
399 double rho_N = Ve/(Rp + height);
400 double rho_U = Ve*
tan(lat_new)/(Rp + height);
401 rho_ENU = (
Vector(3) << rho_E, rho_N, rho_U).finished();
414 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION 416 friend class boost::serialization::access;
417 template<
class ARCHIVE>
418 void serialize(ARCHIVE & ar,
const unsigned int ) {
419 ar & boost::serialization::make_nvp(
"NonlinearFactor2",
420 boost::serialization::base_object<Base>(*
this));
427 template<
class POSE,
class VELOCITY,
class IMUBIAS>
429 public Testable<InertialNavFactor_GlobalVelocity<POSE, VELOCITY, IMUBIAS> > {
Jet< T, N > cos(const Jet< T, N > &f)
static shared_ptr Covariance(const Matrix &covariance, bool smart=true)
std::string serialize(const T &input)
serializes to a string
noiseModel::Diagonal::shared_ptr model
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
NoiseModelFactorN< POSE, VELOCITY, IMUBIAS, POSE, VELOCITY > Base
void predict(const POSE &Pose1, const VELOCITY &Vel1, const IMUBIAS &Bias1, POSE &Pose2, VELOCITY &Vel2) const
virtual Vector evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const=0
~InertialNavFactor_GlobalVelocity() override
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)
Pose2_ Expmap(const Vector3_ &xi)
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)
Some functions to compute numerical derivatives.
POSE predictPose(const POSE &Pose1, const VELOCITY &Vel1, const IMUBIAS &Bias1) const
static const KeyFormatter DefaultKeyFormatter
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
EIGEN_DEVICE_FUNC const InverseReturnType inverse() const
VELOCITY predictVelocity(const POSE &Pose1, const VELOCITY &Vel1, const IMUBIAS &Bias1) const
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)
Vector world_omega_earth_
static noiseModel::Gaussian::shared_ptr calc_descrete_noise_model(const noiseModel::Gaussian::shared_ptr &model, double delta_t)
gtsam::Vector world_omega_earth(world_R_ECEF.matrix() *ECEF_omega_earth)
Matrix * OptionalMatrixType
std::optional< POSE > body_P_sensor_
InertialNavFactor_GlobalVelocity(const Key &Pose1, const Key &Vel1, const Key &IMUBias1, const Key &Pose2, const Key &Vel2, const Vector &measurement_acc, const Vector &measurement_gyro, const double measurement_dt, const Vector world_g, const Vector world_rho, const Vector &world_omega_earth, const noiseModel::Gaussian::shared_ptr &model_continuous, std::optional< POSE > body_P_sensor={})
Matrix stack(size_t nrMatrices,...)
POSE evaluatePoseError(const POSE &Pose1, const VELOCITY &Vel1, const IMUBIAS &Bias1, const POSE &Pose2, const VELOCITY &Vel2) const
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Vector evaluateError(const POSE &Pose1, const VELOCITY &Vel1, const IMUBIAS &Bias1, const POSE &Pose2, const VELOCITY &Vel2, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3, OptionalMatrixType H4, OptionalMatrixType H5) const override
static const Vector3 world_g(0.0, 0.0, 9.81)
InertialNavFactor_GlobalVelocity< POSE, VELOCITY, IMUBIAS > This
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
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)
VELOCITY evaluateVelocityError(const POSE &Pose1, const VELOCITY &Vel1, const IMUBIAS &Bias1, const POSE &Pose2, const VELOCITY &Vel2) const
Matrix3 skewSymmetric(double wx, double wy, double wz)
SharedNoiseModel noiseModel_
Non-linear factor base classes.
InertialNavFactor_GlobalVelocity()
static const Vector3 world_rho(0.0, -1.5724e-05, 0.0)
EIGEN_DEVICE_FUNC const TanReturnType tan() const
Jet< T, N > sqrt(const Jet< T, N > &f)
void print(const std::string &s="InertialNavFactor_GlobalVelocity", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
static shared_ptr SqrtInformation(const Matrix &R, bool smart=true)
std::shared_ptr< Gaussian > shared_ptr
Jet< T, N > pow(const Jet< T, N > &f, double g)
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
Vector concatVectors(const std::list< Vector > &vs)
std::shared_ptr< InertialNavFactor_GlobalVelocity > shared_ptr
std::uint64_t Key
Integer nonlinear key type.
3D rotation represented as a rotation matrix or quaternion
bool equals(const This &other, double tol=1e-9) const
check equality