25#include <gtsam/config.h>
27#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
54 typedef NoiseModelFactorT<Vector6, Pose3, Pose3, Vector6> Base;
58 using Base::evaluateError;
60 Reconstruction(Key gKey1, Key gKey, Key xiKey,
double h,
double mu = 1000.0) :
61 Base(noiseModel::Constrained::All(6, std::abs(mu)), gKey1, gKey,
64 ~Reconstruction()
override {}
67 gtsam::NonlinearFactor::shared_ptr clone()
const override {
68 return std::static_pointer_cast<gtsam::NonlinearFactor>(
69 gtsam::NonlinearFactor::shared_ptr(
new Reconstruction(*
this))); }
72 Vector6 evaluateError(
const Pose3& gk1,
const Pose3& gk,
73 const Vector6& xik, OptionalMatrixType H1,
74 OptionalMatrixType H2,
75 OptionalMatrixType H3)
const override {
78 Pose3 exphxi = Pose3::Expmap(h_ * xik, H3 ? &D_exphxi_xi : 0);
80 Matrix6 D_gkxi_gk, D_gkxi_exphxi;
81 Pose3 gkxi = gk.compose(exphxi, D_gkxi_gk, H3 ? &D_gkxi_exphxi : 0);
83 Matrix6 D_hx_gk1, D_hx_gkxi;
84 Pose3 hx = gkxi.between(gk1, (H2 || H3) ? &D_hx_gkxi : 0, H1 ? &D_hx_gk1 : 0);
87 Vector error = Pose3::Logmap(hx, D_log_hx);
89 if (H1) *H1 = D_log_hx * D_hx_gk1;
91 Matrix6 D_log_gkxi = D_log_hx * D_hx_gkxi;
92 if (H2) *H2 = D_log_gkxi * D_gkxi_gk;
93 if (H3) *H3 = D_log_gkxi * D_gkxi_exphxi * D_exphxi_xi * h_;
105class DiscreteEulerPoincareHelicopter
119 typedef NoiseModelFactorT<Vector6, Vector6, Vector6, Pose3> Base;
124 using Base::evaluateError;
126 DiscreteEulerPoincareHelicopter(Key xiKey1, Key xiKey_1, Key gKey,
127 double h,
const Matrix& Inertia,
const Vector& Fu,
double m,
128 double mu = 1000.0) :
129 Base(noiseModel::Constrained::All(6, std::abs(mu)), xiKey1, xiKey_1, gKey),
130 h_(h), Inertia_(Inertia), Fu_(Fu), m_(m) {
132 ~DiscreteEulerPoincareHelicopter()
override {}
135 gtsam::NonlinearFactor::shared_ptr clone()
const override {
136 return std::static_pointer_cast<gtsam::NonlinearFactor>(
137 gtsam::NonlinearFactor::shared_ptr(
new DiscreteEulerPoincareHelicopter(*
this))); }
144 Vector6 evaluateError(
const Vector6& xik,
const Vector6& xik_1,
145 const Pose3& gk, OptionalMatrixType H1,
146 OptionalMatrixType H2,
147 OptionalMatrixType H3)
const override {
149 Vector muk = Inertia_*xik;
150 Vector muk_1 = Inertia_*xik_1;
156 Matrix D_adjThxik_muk, D_adjThxik1_muk1;
157 Vector pk = muk - 0.5*Pose3::adjointTranspose(h_*xik, muk, D_adjThxik_muk);
158 Vector pk_1 = muk_1 - 0.5*Pose3::adjointTranspose(-h_*xik_1, muk_1, D_adjThxik1_muk1);
160 Matrix D_gravityBody_gk;
161 Point3 gravityBody = gk.rotation().unrotate(
Point3(0.0, 0.0, -9.81*m_), D_gravityBody_gk, {});
163 {0.0, 0.0, 0.0, gravityBody.x(), gravityBody.y(), gravityBody.z()}};
165 Vector hx = pk - pk_1 - h_*Fu_ - h_*f_ext;
168 Matrix D_pik_xi = Inertia_-0.5*(h_*D_adjThxik_muk + Pose3::adjointMap(h_*xik).transpose()*Inertia_);
173 Matrix D_pik1_xik1 = Inertia_-0.5*(-h_*D_adjThxik1_muk1 + Pose3::adjointMap(-h_*xik_1).transpose()*Inertia_);
179 H3->block<3, 3>(3, 0) = -h_ * D_gravityBody_gk;
186 Vector computeError(
const Vector6& xik,
const Vector6& xik_1,
const Pose3& gk)
const {
187 Vector pk = Pose3::dExpInv_exp(h_*xik).transpose()*Inertia_*xik;
188 Vector pk_1 = Pose3::dExpInv_exp(-h_*xik_1).transpose()*Inertia_*xik_1;
190 Point3 gravityBody = gk.rotation().unrotate(
Point3(0.0, 0.0, -9.81*m_));
191 Vector f_ext = (Vector(6) << 0.0, 0.0, 0.0, gravityBody.x(), gravityBody.y(), gravityBody.z());
193 Vector hx = pk - pk_1 - h_*Fu_ - h_*f_ext;
198 Vector evaluateError(
const Vector6& xik,
const Vector6& xik_1,
const Pose3& gk,
199 OptionalMatrixType H1, OptionalMatrixType H2,
200 OptionalMatrixType H3)
const {
203 std::function<Vector(
const Vector6&,
const Vector6&,
const Pose3&)>(
204 std::bind(&DiscreteEulerPoincareHelicopter::computeError, *
this, _1, _2, _3)
211 std::function<Vector(
const Vector6&,
const Vector6&,
const Pose3&)>(
212 std::bind(&DiscreteEulerPoincareHelicopter::computeError, *
this, _1, _2, _3)
219 std::function<Vector(
const Vector6&,
const Vector6&,
const Pose3&)>(
220 std::bind(&DiscreteEulerPoincareHelicopter::computeError, *
this, _1, _2, _3)
226 return computeError(xik, xik_1, gk);
Macros for Matrix constants to avoid excessive template instantiation.
Numerical derivative helpers for manifold-valued functions.
3D Pose manifold SO(3) x R^3 and group SE(3)
Base class for noise model factors with N variables.
Non-linear factor base classes.
internal::MatrixMN< traits< internal::OutputType< Y, F, X1, X2, X3 > >::dimension, N >::type numericalDerivative31(F &&h, const X1 &x1, const X2 &x2, const X3 &x3, double delta=1e-5)
Compute numerical derivative in argument 1 of ternary function.
Definition numericalDerivative.h:294
internal::MatrixMN< traits< internal::OutputType< Y, F, X1, X2, X3 > >::dimension, N >::type numericalDerivative32(F &&h, const X1 &x1, const X2 &x2, const X3 &x3, double delta=1e-5)
Compute numerical derivative in argument 2 of ternary function.
Definition numericalDerivative.h:324
internal::MatrixMN< traits< internal::OutputType< Y, F, X1, X2, X3 > >::dimension, N >::type numericalDerivative33(F &&h, const X1 &x1, const X2 &x2, const X3 &x3, double delta=1e-5)
Compute numerical derivative in argument 3 of ternary function.
Definition numericalDerivative.h:354
Global functions in a separate testing namespace.
Definition chartTesting.h:28
Vector3 Point3
As of GTSAM 4, in order to make GTSAM more lean, it is now possible to just typedef Point3 to Vector3...
Definition Point3.h:38
A convenient base class for creating your own NoiseModelFactor with n variables.
Definition NoiseModelFactorN.h:155