23#include <gtsam/config.h>
25#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
45 typedef NoiseModelFactorT<Vector1, double, double, double> Base;
55 using Base::evaluateError;
57 typedef std::shared_ptr<PendulumFactor1> shared_ptr;
60 PendulumFactor1(Key k1, Key k, Key velKey,
double h,
double mu = 1000.0)
61 : Base(noiseModel::Constrained::All(1, std::abs(mu)), k1, k, velKey), h_(h) {}
64 gtsam::NonlinearFactor::shared_ptr clone()
const override {
65 return std::static_pointer_cast<gtsam::NonlinearFactor>(
66 gtsam::NonlinearFactor::shared_ptr(
new PendulumFactor1(*
this))); }
69 Vector1 evaluateError(
const double& qk1,
const double& qk,
const double& v,
70 OptionalMatrixType H1, OptionalMatrixType H2,
71 OptionalMatrixType H3)
const override {
73 if (H1) *H1 = -Matrix::Identity(p,p);
74 if (H2) *H2 = Matrix::Identity(p,p);
75 if (H3) *H3 = Matrix::Identity(p,p)*h_;
76 return Vector{{qk + v * h_ - qk1}};
95 typedef NoiseModelFactorT<Vector1, double, double, double> Base;
107 using Base::evaluateError;
109 typedef std::shared_ptr<PendulumFactor2 > shared_ptr;
112 PendulumFactor2(Key vk1, Key vk, Key qkey,
double h,
double r = 1.0,
double g = 9.81,
double mu = 1000.0)
113 : Base(noiseModel::Constrained::All(1, std::abs(mu)), vk1, vk, qkey), h_(h), g_(g), r_(r) {}
116 gtsam::NonlinearFactor::shared_ptr clone()
const override {
117 return std::static_pointer_cast<gtsam::NonlinearFactor>(
118 gtsam::NonlinearFactor::shared_ptr(
new PendulumFactor2(*
this))); }
121 Vector1 evaluateError(
const double & vk1,
const double & vk,
const double & q,
122 OptionalMatrixType H1, OptionalMatrixType H2,
123 OptionalMatrixType H3)
const override {
125 if (H1) *H1 = -Matrix::Identity(p,p);
126 if (H2) *H2 = Matrix::Identity(p,p);
127 if (H3) *H3 = -Matrix::Identity(p,p)*h_*g_/r_*cos(q);
128 return Vector{{vk - h_ * g_ / r_ * sin(q) - vk1}};
141class PendulumFactorPk
146 typedef NoiseModelFactorT<Vector1, double, double, double> Base;
149 PendulumFactorPk() {}
160 using Base::evaluateError;
162 typedef std::shared_ptr<PendulumFactorPk > shared_ptr;
165 PendulumFactorPk(Key pKey, Key qKey, Key qKey1,
166 double h,
double m = 1.0,
double r = 1.0,
double g = 9.81,
double alpha = 0.0,
double mu = 1000.0)
167 : Base(noiseModel::Constrained::All(1, std::abs(mu)), pKey, qKey, qKey1),
168 h_(h), m_(m), r_(r), g_(g), alpha_(alpha) {}
171 gtsam::NonlinearFactor::shared_ptr clone()
const override {
172 return std::static_pointer_cast<gtsam::NonlinearFactor>(
173 gtsam::NonlinearFactor::shared_ptr(
new PendulumFactorPk(*
this))); }
176 Vector1 evaluateError(
const double & pk,
const double & qk,
177 const double & qk1, OptionalMatrixType H1,
178 OptionalMatrixType H2,
179 OptionalMatrixType H3)
const override {
182 double qmid = (1-alpha_)*qk + alpha_*qk1;
183 double mr2_h = 1/h_*m_*r_*r_;
184 double mgrh = m_*g_*r_*h_;
186 if (H1) *H1 = -Matrix::Identity(p,p);
187 if (H2) *H2 = Matrix::Identity(p,p)*(-mr2_h + mgrh*(1-alpha_)*(1-alpha_)*cos(qmid));
188 if (H3) *H3 = Matrix::Identity(p,p)*( mr2_h + mgrh*(1-alpha_)*(alpha_)*cos(qmid));
190 return Vector{{mr2_h * (qk1 - qk) + mgrh * (1 - alpha_) * sin(qmid) - pk}};
202class PendulumFactorPk1
207 typedef NoiseModelFactorT<Vector1, double, double, double> Base;
210 PendulumFactorPk1() {}
221 using Base::evaluateError;
223 typedef std::shared_ptr<PendulumFactorPk1 > shared_ptr;
226 PendulumFactorPk1(Key pKey1, Key qKey, Key qKey1,
227 double h,
double m = 1.0,
double r = 1.0,
double g = 9.81,
double alpha = 0.0,
double mu = 1000.0)
228 : Base(noiseModel::Constrained::All(1, std::abs(mu)), pKey1, qKey, qKey1),
229 h_(h), m_(m), r_(r), g_(g), alpha_(alpha) {}
232 gtsam::NonlinearFactor::shared_ptr clone()
const override {
233 return std::static_pointer_cast<gtsam::NonlinearFactor>(
234 gtsam::NonlinearFactor::shared_ptr(
new PendulumFactorPk1(*
this))); }
237 Vector1 evaluateError(
const double & pk1,
const double & qk,
238 const double & qk1, OptionalMatrixType H1,
239 OptionalMatrixType H2,
240 OptionalMatrixType H3)
const override {
243 double qmid = (1-alpha_)*qk + alpha_*qk1;
244 double mr2_h = 1/h_*m_*r_*r_;
245 double mgrh = m_*g_*r_*h_;
247 if (H1) *H1 = -Matrix::Identity(p,p);
248 if (H2) *H2 = Matrix::Identity(p,p)*(-mr2_h - mgrh*(1-alpha_)*alpha_*cos(qmid));
249 if (H3) *H3 = Matrix::Identity(p,p)*( mr2_h - mgrh*alpha_*alpha_*cos(qmid));
251 return Vector{{mr2_h * (qk1 - qk) - mgrh * alpha_ * sin(qmid) - pk1}};
Base class for noise model factors with N variables.
Non-linear factor base classes.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
A convenient base class for creating your own NoiseModelFactor with n variables.
Definition NoiseModelFactorN.h:155