29 #include <boost/optional.hpp> 78 template<
class POSE,
class VELOCITY,
class IMUBIAS>
99 typedef typename boost::shared_ptr<InertialNavFactor_GlobalVelocity>
shared_ptr;
109 Pose1, Vel1, IMUBias1, Pose2, Vel2), measurement_acc_(measurement_acc), measurement_gyro_(measurement_gyro),
110 dt_(measurement_dt), world_g_(world_g), world_rho_(world_rho), world_omega_earth_(world_omega_earth), body_P_sensor_(body_P_sensor) { }
118 std::cout <<
s <<
"(" 119 << keyFormatter(this->
key1()) <<
"," 120 << keyFormatter(this->
key2()) <<
"," 121 << keyFormatter(this->
key3()) <<
"," 122 << keyFormatter(this->
key4()) <<
"," 123 << keyFormatter(this->
key5()) <<
"\n";
124 std::cout <<
"acc measurement: " << this->measurement_acc_.transpose() << std::endl;
125 std::cout <<
"gyro measurement: " << this->measurement_gyro_.transpose() << std::endl;
126 std::cout <<
"dt: " << this->dt_ << std::endl;
127 std::cout <<
"gravity (in world frame): " << this->world_g_.transpose() << std::endl;
128 std::cout <<
"craft rate (in world frame): " << this->world_rho_.transpose() << std::endl;
129 std::cout <<
"earth's rotation (in world frame): " << this->world_omega_earth_.transpose() << std::endl;
130 if(this->body_P_sensor_)
131 this->body_P_sensor_->print(
" sensor pose in body frame: ");
137 const This *
e =
dynamic_cast<const This*
> (&
expected);
139 && (measurement_acc_ - e->measurement_acc_).norm() <
tol 140 && (measurement_gyro_ - e->measurement_gyro_).norm() <
tol 141 && (dt_ - e->dt_) <
tol 142 && (world_g_ - e->world_g_).norm() <
tol 143 && (world_rho_ - e->world_rho_).norm() <
tol 144 && (world_omega_earth_ - e->world_omega_earth_).norm() <
tol 145 && ((!body_P_sensor_ && !e->body_P_sensor_) || (body_P_sensor_ && e->body_P_sensor_ && body_P_sensor_->
equals(*e->body_P_sensor_)));
148 POSE
predictPose(
const POSE& Pose1,
const VELOCITY& Vel1,
const IMUBIAS& Bias1)
const {
150 Vector GyroCorrected(Bias1.correctGyroscope(measurement_gyro_));
152 const POSE& world_P1_body = Pose1;
153 const VELOCITY& world_V1_body = Vel1;
158 body_omega_body = body_P_sensor_->rotation().matrix() * GyroCorrected;
160 body_omega_body = GyroCorrected;
164 Matrix body_R_world(world_P1_body.rotation().inverse().matrix());
169 body_omega_body -= body_rho + body_omega_earth;
172 return POSE(Pose1.rotation() *
POSE::Rotation::Expmap(body_omega_body*dt_), Pose1.translation() +
typename POSE::Translation(world_V1_body*dt_));
175 VELOCITY
predictVelocity(
const POSE& Pose1,
const VELOCITY& Vel1,
const IMUBIAS& Bias1)
const {
177 Vector AccCorrected(Bias1.correctAccelerometer(measurement_acc_));
179 const POSE& world_P1_body = Pose1;
180 const VELOCITY& world_V1_body = Vel1;
183 Vector body_a_body, body_omega_body;
185 Matrix body_R_sensor = body_P_sensor_->rotation().matrix();
187 Vector GyroCorrected(Bias1.correctGyroscope(measurement_gyro_));
188 body_omega_body = body_R_sensor * GyroCorrected;
190 body_a_body = body_R_sensor * AccCorrected - body_omega_body__cross * body_omega_body__cross * body_P_sensor_->translation();
192 body_a_body = AccCorrected;
196 Vector world_a_body = world_P1_body.rotation().matrix() * body_a_body + world_g_ - 2*
skewSymmetric(world_rho_ + world_omega_earth_)*world_V1_body;
199 VELOCITY VelDelta(world_a_body*dt_);
202 return Vel1 + VelDelta;
205 void predict(
const POSE& Pose1,
const VELOCITY& Vel1,
const IMUBIAS& Bias1, POSE&
Pose2, VELOCITY& Vel2)
const {
210 POSE
evaluatePoseError(
const POSE& Pose1,
const VELOCITY& Vel1,
const IMUBIAS& Bias1,
const POSE&
Pose2,
const VELOCITY& Vel2)
const {
215 return Pose2.between(Pose2Pred);
218 VELOCITY
evaluateVelocityError(
const POSE& Pose1,
const VELOCITY& Vel1,
const IMUBIAS& Bias1,
const POSE&
Pose2,
const VELOCITY& Vel2)
const {
223 return Vel2Pred - Vel2;
228 boost::optional<Matrix&> H1 = boost::none,
229 boost::optional<Matrix&> H2 = boost::none,
230 boost::optional<Matrix&> H3 = boost::none,
231 boost::optional<Matrix&> H4 = boost::none,
232 boost::optional<Matrix&> H5 = boost::none)
const override {
239 *H1 =
stack(2, &H1_Pose, &H1_Vel);
244 if (Vel1.size()!=3)
throw std::runtime_error(
"Frank's hack to make this compile will not work if size != 3");
247 *H2 =
stack(2, &H2_Pose, &H2_Vel);
254 *H3 =
stack(2, &H3_Pose, &H3_Vel);
261 *H4 =
stack(2, &H4_Pose, &H4_Vel);
266 if (Vel2.size()!=3)
throw std::runtime_error(
"Frank's hack to make this compile will not work if size != 3");
269 *H5 =
stack(2, &H5_Pose, &H5_Vel);
281 Matrix cov_acc = ( gaussian_acc->R().transpose() * gaussian_acc->R() ).
inverse();
282 Matrix cov_gyro = ( gaussian_gyro->R().transpose() * gaussian_gyro->R() ).
inverse();
283 Matrix cov_process = ( gaussian_process->R().transpose() * gaussian_process->R() ).
inverse();
285 cov_process.block(0,0, 3,3) += cov_gyro;
286 cov_process.block(6,6, 3,3) += cov_acc;
297 0.0, 0.0, -1.0).finished();
302 0.0, 0.0, -1.0).finished();
305 Vector Pos_ENU = NED_to_ENU * Pos_NED;
306 Vector Vel_ENU = NED_to_ENU * Vel_NED;
307 Vector Pos_ENU_Initial = NED_to_ENU * Pos_NED_Initial;
316 g_NED = ENU_to_NED * g_ENU;
317 rho_NED = ENU_to_NED * rho_ENU;
318 omega_earth_NED = ENU_to_NED * omega_earth_ENU;
323 double R0 = 6.378388e6;
325 double Re( R0*( 1-e*(
sin( LatLonHeight_IC(0) ))*(
sin( LatLonHeight_IC(0) )) ) );
328 Vector delta_Pos_ENU(Pos_ENU - Pos_ENU_Initial);
329 double delta_lat(delta_Pos_ENU(1)/Re);
330 double delta_lon(delta_Pos_ENU(0)/(Re*
cos(LatLonHeight_IC(0))));
331 double lat_new(LatLonHeight_IC(0) + delta_lat);
332 double lon_new(LatLonHeight_IC(1) + delta_lon);
336 -
sin(lon_new),
cos(lon_new), 0.0,
342 -
sin(lat_new), 0.0,
cos(lat_new));
344 Rot3 UEN_to_ENU(0, 1, 0,
348 Rot3 R_ECEF_to_ENU( UEN_to_ENU * C2 * C1 );
351 omega_earth_ENU = R_ECEF_to_ENU.
matrix() * omega_earth_ECEF;
354 double height(LatLonHeight_IC(2));
355 double EQUA_RADIUS = 6378137.0;
356 double ECCENTRICITY = 0.0818191908426;
357 double e2(
pow(ECCENTRICITY,2) );
358 double den( 1-e2*
pow(
sin(lat_new),2) );
359 double Rm( (EQUA_RADIUS*(1-e2))/(
pow(den,(3/2)) ) );
360 double Rp( EQUA_RADIUS/(
sqrt(den) ) );
361 double Ro(
sqrt(Rp*Rm) );
362 double g0( 9.780318*( 1 + 5.3024e-3 *
pow(
sin(lat_new),2) - 5.9e-6 *
pow(
sin(2*lat_new),2) ) );
363 double g_calc( g0/(
pow(1 + height/Ro, 2) ) );
364 g_ENU = (
Vector(3) << 0.0, 0.0, -g_calc).finished();
368 double Ve( Vel_ENU(0) );
369 double Vn( Vel_ENU(1) );
370 double rho_E = -Vn/(Rm + height);
371 double rho_N = Ve/(Rp + height);
372 double rho_U = Ve*
tan(lat_new)/(Rp + height);
373 rho_ENU = (
Vector(3) << rho_E, rho_N, rho_U).finished();
388 template<
class ARCHIVE>
390 ar & boost::serialization::make_nvp(
"NonlinearFactor2",
391 boost::serialization::base_object<Base>(*
this));
397 template<
class POSE,
class VELOCITY,
class IMUBIAS>
399 public Testable<InertialNavFactor_GlobalVelocity<POSE, VELOCITY, IMUBIAS> > {
bool equals(const This &other, double tol=1e-9) const
check equality
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
static shared_ptr Covariance(const Matrix &covariance, bool smart=true)
noiseModel::Diagonal::shared_ptr model
~InertialNavFactor_GlobalVelocity() override
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
Pose2_ Expmap(const Vector3_ &xi)
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, boost::optional< POSE > body_P_sensor=boost::none)
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.
NoiseModelFactor5< POSE, VELOCITY, IMUBIAS, POSE, VELOCITY > Base
friend class boost::serialization::access
static const KeyFormatter DefaultKeyFormatter
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_
EIGEN_DEVICE_FUNC const CosReturnType cos() const
static noiseModel::Gaussian::shared_ptr calc_descrete_noise_model(const noiseModel::Gaussian::shared_ptr &model, double delta_t)
static const Vector3 world_rho(0.0,-1.5724e-05, 0.0)
POSE predictPose(const POSE &Pose1, const VELOCITY &Vel1, const IMUBIAS &Bias1) const
boost::shared_ptr< InertialNavFactor_GlobalVelocity > shared_ptr
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
boost::optional< POSE > body_P_sensor_
EIGEN_DEVICE_FUNC const TanReturnType tan() const
VELOCITY predictVelocity(const POSE &Pose1, const VELOCITY &Vel1, const IMUBIAS &Bias1) const
static const Vector3 world_g(0.0, 0.0, 9.81)
InertialNavFactor_GlobalVelocity< POSE, VELOCITY, IMUBIAS > This
VELOCITY evaluateVelocityError(const POSE &Pose1, const VELOCITY &Vel1, const IMUBIAS &Bias1, const POSE &Pose2, const VELOCITY &Vel2) const
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)
void serialize(ARCHIVE &ar, const unsigned int)
Matrix3 skewSymmetric(double wx, double wy, double wz)
SharedNoiseModel noiseModel_
Non-linear factor base classes.
InertialNavFactor_GlobalVelocity()
Matrix stack(size_t nrMatrices,...)
POSE evaluatePoseError(const POSE &Pose1, const VELOCITY &Vel1, const IMUBIAS &Bias1, const POSE &Pose2, const VELOCITY &Vel2) const
gtsam::Vector world_omega_earth(world_R_ECEF.matrix()*ECEF_omega_earth)
boost::shared_ptr< Gaussian > shared_ptr
EIGEN_DEVICE_FUNC const SinReturnType sin() const
void print(const std::string &s="InertialNavFactor_GlobalVelocity", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
static shared_ptr SqrtInformation(const Matrix &R, bool smart=true)
void predict(const POSE &Pose1, const VELOCITY &Vel1, const IMUBIAS &Bias1, POSE &Pose2, VELOCITY &Vel2) const
Jet< T, N > pow(const Jet< T, N > &f, double g)
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
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
EIGEN_DEVICE_FUNC const InverseReturnType inverse() const
std::uint64_t Key
Integer nonlinear key type.
Vector concatVectors(const std::list< Vector > &vs)
3D rotation represented as a rotation matrix or quaternion