36 typedef boost::shared_ptr<PendulumFactor1> shared_ptr;
40 :
Base(
noiseModel::Constrained::All(1, fabs(mu)), k1, k, velKey), h_(h) {}
43 virtual gtsam::NonlinearFactor::shared_ptr
clone()
const {
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 {
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, fabs(mu)), vk1, vk, qkey), h_(h), g_(g), r_(r) {}
91 virtual gtsam::NonlinearFactor::shared_ptr
clone()
const {
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 {
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, fabs(mu)), pKey, qKey, qKey1),
142 virtual gtsam::NonlinearFactor::shared_ptr
clone()
const {
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 {
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, fabs(mu)), pKey1, qKey, qKey1),
198 virtual gtsam::NonlinearFactor::shared_ptr
clone()
const {
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 {
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();
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
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
double m_
time step
Definition: Pendulum.h:126
This is the base class for all factor types.
Definition: Factor.h:54
PendulumFactorPk1()
default constructor to allow for serialization
Definition: Pendulum.h:179
virtual gtsam::NonlinearFactor::shared_ptr clone() const
Definition: Pendulum.h:91
This class implements the second constraint the.
Definition: Pendulum.h:69
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
PendulumFactor2()
default constructor to allow for serialization
Definition: Pendulum.h:76
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
double g_
length
Definition: Pendulum.h:128
This class implements the second position-momentum update rule p_k1 = D_2 L_d(q_k,...
Definition: Pendulum.h:172
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
v_k - h*g/L*sin(q) - v_k1 = 0, with optional derivatives
Definition: Pendulum.h:96
This class implements the first constraint.
Definition: Pendulum.h:23
double alpha_
gravity
Definition: Pendulum.h:129
const SharedNoiseModel & noiseModel() const
access to the noise model
Definition: NonlinearFactor.h:210
virtual gtsam::NonlinearFactor::shared_ptr clone() const
Definition: Pendulum.h:43
double r_
mass
Definition: Pendulum.h:183
A convenient base class for creating your own NoiseModelFactor with 3 variables.
Definition: NonlinearFactor.h:420
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
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
Non-linear factor base classes.
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
1/h mr^2 (qk1-qk) - mgrh a sin((1-a)pk + a*pk1) - pk1 = 0, with optional derivatives
Definition: Pendulum.h:203
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
q_k + h*v - q_k1 = 0, with optional derivatives
Definition: Pendulum.h:48
double alpha_
gravity
Definition: Pendulum.h:185
PendulumFactor1()
default constructor to allow for serialization
Definition: Pendulum.h:30
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
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
double r_
mass
Definition: Pendulum.h:127
virtual gtsam::NonlinearFactor::shared_ptr clone() const
Definition: Pendulum.h:198
double m_
time step
Definition: Pendulum.h:182
This class implements the first position-momentum update rule p_k = -D_1 L_d(q_k,q_{k+1},...
Definition: Pendulum.h:116
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
1/h mr^2 (qk1-qk)+mgrh (1-a) sin((1-a)pk + a*pk1) - pk = 0, with optional derivatives
Definition: Pendulum.h:147
virtual gtsam::NonlinearFactor::shared_ptr clone() const
Definition: Pendulum.h:142
PendulumFactorPk()
default constructor to allow for serialization
Definition: Pendulum.h:123
double g_
length
Definition: Pendulum.h:184