36 typedef boost::shared_ptr<PendulumFactor1> shared_ptr;
40 :
Base(
noiseModel::Constrained::All(1, std::abs(mu)), k1, k, velKey), h_(h) {}
43 gtsam::NonlinearFactor::shared_ptr
clone()
const override {
44 return boost::static_pointer_cast<gtsam::NonlinearFactor>(
48 Vector
evaluateError(
const double& qk1,
const double& qk,
const double& v,
49 boost::optional<Matrix&> H1 = boost::none,
50 boost::optional<Matrix&> H2 = boost::none,
51 boost::optional<Matrix&> H3 = boost::none)
const override {
53 if (H1) *H1 = -Matrix::Identity(p,p);
54 if (H2) *H2 = Matrix::Identity(p,p);
55 if (H3) *H3 = Matrix::Identity(p,p)*h_;
56 return (Vector(1) << qk+v*h_-qk1).finished();
84 typedef boost::shared_ptr<PendulumFactor2 > shared_ptr;
88 :
Base(
noiseModel::Constrained::All(1, std::abs(mu)), vk1, vk, qkey), h_(h), g_(g), r_(r) {}
91 gtsam::NonlinearFactor::shared_ptr
clone()
const override {
92 return boost::static_pointer_cast<gtsam::NonlinearFactor>(
96 Vector
evaluateError(
const double & vk1,
const double & vk,
const double & q,
97 boost::optional<Matrix&> H1 = boost::none,
98 boost::optional<Matrix&> H2 = boost::none,
99 boost::optional<Matrix&> H3 = boost::none)
const override {
101 if (H1) *H1 = -Matrix::Identity(p,p);
102 if (H2) *H2 = Matrix::Identity(p,p);
103 if (H3) *H3 = -Matrix::Identity(p,p)*h_*g_/r_*cos(q);
104 return (Vector(1) << vk - h_ * g_ / r_ * sin(q) - vk1).finished();
137 double h,
double m = 1.0,
double r = 1.0,
double g = 9.81,
double alpha = 0.0,
double mu = 1000.0)
138 :
Base(
noiseModel::Constrained::All(1, std::abs(mu)), pKey, qKey, qKey1),
142 gtsam::NonlinearFactor::shared_ptr
clone()
const override {
143 return boost::static_pointer_cast<gtsam::NonlinearFactor>(
147 Vector
evaluateError(
const double & pk,
const double & qk,
const double & qk1,
148 boost::optional<Matrix&> H1 = boost::none,
149 boost::optional<Matrix&> H2 = boost::none,
150 boost::optional<Matrix&> H3 = boost::none)
const override {
154 double mr2_h = 1/h_*
m_*
r_*
r_;
155 double mgrh =
m_*
g_*
r_*h_;
157 if (H1) *H1 = -Matrix::Identity(p,p);
158 if (H2) *H2 = Matrix::Identity(p,p)*(-mr2_h + mgrh*(1-
alpha_)*(1-
alpha_)*cos(qmid));
159 if (H3) *H3 = Matrix::Identity(p,p)*( mr2_h + mgrh*(1-
alpha_)*(
alpha_)*cos(qmid));
161 return (Vector(1) << mr2_h * (qk1 - qk) + mgrh * (1 -
alpha_) * sin(qmid) - pk).finished();
193 double h,
double m = 1.0,
double r = 1.0,
double g = 9.81,
double alpha = 0.0,
double mu = 1000.0)
194 :
Base(
noiseModel::Constrained::All(1, std::abs(mu)), pKey1, qKey, qKey1),
198 gtsam::NonlinearFactor::shared_ptr
clone()
const override {
199 return boost::static_pointer_cast<gtsam::NonlinearFactor>(
203 Vector
evaluateError(
const double & pk1,
const double & qk,
const double & qk1,
204 boost::optional<Matrix&> H1 = boost::none,
205 boost::optional<Matrix&> H2 = boost::none,
206 boost::optional<Matrix&> H3 = boost::none)
const override {
210 double mr2_h = 1/h_*
m_*
r_*
r_;
211 double mgrh =
m_*
g_*
r_*h_;
213 if (H1) *H1 = -Matrix::Identity(p,p);
214 if (H2) *H2 = Matrix::Identity(p,p)*(-mr2_h - mgrh*(1-
alpha_)*
alpha_*cos(qmid));
215 if (H3) *H3 = Matrix::Identity(p,p)*( mr2_h - mgrh*
alpha_*
alpha_*cos(qmid));
217 return (Vector(1) << mr2_h * (qk1 - qk) - mgrh *
alpha_ * sin(qmid) - pk1).finished();
Non-linear factor base classes.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:69
This is the base class for all factor types.
Definition: Factor.h:56
const SharedNoiseModel & noiseModel() const
access to the noise model
Definition: NonlinearFactor.h:211
A convenient base class for creating your own NoiseModelFactor with 3 variables.
Definition: NonlinearFactor.h:444
This class implements the first constraint.
Definition: Pendulum.h:23
PendulumFactor1()
default constructor to allow for serialization
Definition: Pendulum.h:30
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: Pendulum.h:43
Vector evaluateError(const double &qk1, const double &qk, const double &v, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none, boost::optional< Matrix & > H3=boost::none) const override
q_k + h*v - q_k1 = 0, with optional derivatives
Definition: Pendulum.h:48
PendulumFactor1(Key k1, Key k, Key velKey, double h, double mu=1000.0)
Constructor. k1: q_{k+1}, k: q_k, velKey: velocity variable depending on the chosen method,...
Definition: Pendulum.h:39
This class implements the second constraint the.
Definition: Pendulum.h:69
Vector evaluateError(const double &vk1, const double &vk, const double &q, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none, boost::optional< Matrix & > H3=boost::none) const override
v_k - h*g/L*sin(q) - v_k1 = 0, with optional derivatives
Definition: Pendulum.h:96
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: Pendulum.h:91
PendulumFactor2(Key vk1, Key vk, Key qkey, double h, double r=1.0, double g=9.81, double mu=1000.0)
Constructor. vk1: v_{k+1}, vk: v_k, qkey: q's key depending on the chosen method, h: time step.
Definition: Pendulum.h:87
PendulumFactor2()
default constructor to allow for serialization
Definition: Pendulum.h:76
This class implements the first position-momentum update rule p_k = -D_1 L_d(q_k,q_{k+1},...
Definition: Pendulum.h:116
PendulumFactorPk()
default constructor to allow for serialization
Definition: Pendulum.h:123
double alpha_
gravity
Definition: Pendulum.h:129
double g_
length
Definition: Pendulum.h:128
Vector evaluateError(const double &pk, const double &qk, const double &qk1, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none, boost::optional< Matrix & > H3=boost::none) const override
1/h mr^2 (qk1-qk)+mgrh (1-a) sin((1-a)pk + a*pk1) - pk = 0, with optional derivatives
Definition: Pendulum.h:147
boost::shared_ptr< PendulumFactorPk > shared_ptr
in [0,1], define the mid-point between [q_k,q_{k+1}] for approximation. The sympletic rule above can ...
Definition: Pendulum.h:133
PendulumFactorPk(Key pKey, Key qKey, Key qKey1, double h, double m=1.0, double r=1.0, double g=9.81, double alpha=0.0, double mu=1000.0)
Constructor.
Definition: Pendulum.h:136
double r_
mass
Definition: Pendulum.h:127
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: Pendulum.h:142
double m_
time step
Definition: Pendulum.h:126
This class implements the second position-momentum update rule p_k1 = D_2 L_d(q_k,...
Definition: Pendulum.h:172
double m_
time step
Definition: Pendulum.h:182
double alpha_
gravity
Definition: Pendulum.h:185
double g_
length
Definition: Pendulum.h:184
PendulumFactorPk1()
default constructor to allow for serialization
Definition: Pendulum.h:179
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: Pendulum.h:198
double r_
mass
Definition: Pendulum.h:183
boost::shared_ptr< PendulumFactorPk1 > shared_ptr
in [0,1], define the mid-point between [q_k,q_{k+1}] for approximation. The sympletic rule above can ...
Definition: Pendulum.h:189
PendulumFactorPk1(Key pKey1, Key qKey, Key qKey1, double h, double m=1.0, double r=1.0, double g=9.81, double alpha=0.0, double mu=1000.0)
Constructor.
Definition: Pendulum.h:192
Vector evaluateError(const double &pk1, const double &qk, const double &qk1, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none, boost::optional< Matrix & > H3=boost::none) const override
1/h mr^2 (qk1-qk) - mgrh a sin((1-a)pk + a*pk1) - pk1 = 0, with optional derivatives
Definition: Pendulum.h:203