Pendulum.h
Go to the documentation of this file.
1 
10 #pragma once
11 
13 
14 namespace gtsam {
15 
16 //*************************************************************************
23 class PendulumFactor1: public NoiseModelFactorN<double, double, double> {
24 public:
25 
26 protected:
28 
31 
32  double h_; // time step
33 
34 public:
35 
36  // Provide access to the Matrix& version of evaluateError:
37  using Base::evaluateError;
38 
39  typedef std::shared_ptr<PendulumFactor1> shared_ptr;
40 
42  PendulumFactor1(Key k1, Key k, Key velKey, double h, double mu = 1000.0)
43  : Base(noiseModel::Constrained::All(1, std::abs(mu)), k1, k, velKey), h_(h) {}
44 
47  return std::static_pointer_cast<gtsam::NonlinearFactor>(
49 
51  Vector evaluateError(const double& qk1, const double& qk, const double& v,
53  OptionalMatrixType H3) const override {
54  const size_t p = 1;
55  if (H1) *H1 = -Matrix::Identity(p,p);
56  if (H2) *H2 = Matrix::Identity(p,p);
57  if (H3) *H3 = Matrix::Identity(p,p)*h_;
58  return (Vector(1) << qk+v*h_-qk1).finished();
59  }
60 
61 }; // \PendulumFactor1
62 
63 
64 //*************************************************************************
71 class PendulumFactor2: public NoiseModelFactorN<double, double, double> {
72 public:
73 
74 protected:
76 
79 
80  double h_;
81  double g_;
82  double r_;
83 
84 public:
85 
86  // Provide access to the Matrix& version of evaluateError:
87  using Base::evaluateError;
88 
89  typedef std::shared_ptr<PendulumFactor2 > shared_ptr;
90 
92  PendulumFactor2(Key vk1, Key vk, Key qkey, double h, double r = 1.0, double g = 9.81, double mu = 1000.0)
93  : Base(noiseModel::Constrained::All(1, std::abs(mu)), vk1, vk, qkey), h_(h), g_(g), r_(r) {}
94 
97  return std::static_pointer_cast<gtsam::NonlinearFactor>(
99 
101  Vector evaluateError(const double & vk1, const double & vk, const double & q,
103  OptionalMatrixType H3) const override {
104  const size_t p = 1;
105  if (H1) *H1 = -Matrix::Identity(p,p);
106  if (H2) *H2 = Matrix::Identity(p,p);
107  if (H3) *H3 = -Matrix::Identity(p,p)*h_*g_/r_*cos(q);
108  return (Vector(1) << vk - h_ * g_ / r_ * sin(q) - vk1).finished();
109  }
110 
111 }; // \PendulumFactor2
112 
113 
114 //*************************************************************************
120 class PendulumFactorPk: public NoiseModelFactorN<double, double, double> {
121 public:
122 
123 protected:
125 
128 
129  double h_;
130  double m_;
131  double r_;
132  double g_;
133  double alpha_;
134 
135 public:
136 
137  // Provide access to the Matrix& version of evaluateError:
138  using Base::evaluateError;
139 
140  typedef std::shared_ptr<PendulumFactorPk > shared_ptr;
141 
143  PendulumFactorPk(Key pKey, Key qKey, Key qKey1,
144  double h, double m = 1.0, double r = 1.0, double g = 9.81, double alpha = 0.0, double mu = 1000.0)
145  : Base(noiseModel::Constrained::All(1, std::abs(mu)), pKey, qKey, qKey1),
146  h_(h), m_(m), r_(r), g_(g), alpha_(alpha) {}
147 
150  return std::static_pointer_cast<gtsam::NonlinearFactor>(
152 
154  Vector evaluateError(const double & pk, const double & qk, const double & qk1,
156  OptionalMatrixType H3) const override {
157  const size_t p = 1;
158 
159  double qmid = (1-alpha_)*qk + alpha_*qk1;
160  double mr2_h = 1/h_*m_*r_*r_;
161  double mgrh = m_*g_*r_*h_;
162 
163  if (H1) *H1 = -Matrix::Identity(p,p);
164  if (H2) *H2 = Matrix::Identity(p,p)*(-mr2_h + mgrh*(1-alpha_)*(1-alpha_)*cos(qmid));
165  if (H3) *H3 = Matrix::Identity(p,p)*( mr2_h + mgrh*(1-alpha_)*(alpha_)*cos(qmid));
166 
167  return (Vector(1) << mr2_h * (qk1 - qk) + mgrh * (1 - alpha_) * sin(qmid) - pk).finished();
168  }
169 
170 }; // \PendulumFactorPk
171 
172 //*************************************************************************
178 class PendulumFactorPk1: public NoiseModelFactorN<double, double, double> {
179 public:
180 
181 protected:
183 
186 
187  double h_;
188  double m_;
189  double r_;
190  double g_;
191  double alpha_;
192 
193 public:
194 
195  // Provide access to the Matrix& version of evaluateError:
196  using Base::evaluateError;
197 
198  typedef std::shared_ptr<PendulumFactorPk1 > shared_ptr;
199 
201  PendulumFactorPk1(Key pKey1, Key qKey, Key qKey1,
202  double h, double m = 1.0, double r = 1.0, double g = 9.81, double alpha = 0.0, double mu = 1000.0)
203  : Base(noiseModel::Constrained::All(1, std::abs(mu)), pKey1, qKey, qKey1),
204  h_(h), m_(m), r_(r), g_(g), alpha_(alpha) {}
205 
208  return std::static_pointer_cast<gtsam::NonlinearFactor>(
210 
212  Vector evaluateError(const double & pk1, const double & qk, const double & qk1,
214  OptionalMatrixType H3) const override {
215  const size_t p = 1;
216 
217  double qmid = (1-alpha_)*qk + alpha_*qk1;
218  double mr2_h = 1/h_*m_*r_*r_;
219  double mgrh = m_*g_*r_*h_;
220 
221  if (H1) *H1 = -Matrix::Identity(p,p);
222  if (H2) *H2 = Matrix::Identity(p,p)*(-mr2_h - mgrh*(1-alpha_)*alpha_*cos(qmid));
223  if (H3) *H3 = Matrix::Identity(p,p)*( mr2_h - mgrh*alpha_*alpha_*cos(qmid));
224 
225  return (Vector(1) << mr2_h * (qk1 - qk) - mgrh * alpha_ * sin(qmid) - pk1).finished();
226  }
227 
228 }; // \PendulumFactorPk1
229 
230 }
double m_
time step
Definition: Pendulum.h:130
Matrix3f m
double alpha_
gravity
Definition: Pendulum.h:191
Jet< T, N > cos(const Jet< T, N > &f)
Definition: jet.h:426
double alpha_
gravity
Definition: Pendulum.h:133
double mu
virtual Vector evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const=0
Jet< T, N > sin(const Jet< T, N > &f)
Definition: jet.h:439
double g_
length
Definition: Pendulum.h:190
Definition: BFloat16.h:88
double g_
length
Definition: Pendulum.h:132
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: Pendulum.h:149
void g(const string &key, int i)
Definition: testBTree.cpp:41
NoiseModelFactorN< double, double, double > Base
Definition: Pendulum.h:75
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:201
double m_
time step
Definition: Pendulum.h:188
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:42
const SharedNoiseModel & noiseModel() const
access to the noise model
Matrix * OptionalMatrixType
Vector evaluateError(const double &pk1, const double &qk, const double &qk1, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3) const override
Definition: Pendulum.h:212
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&#39;s key depending on the chosen method, h: time step...
Definition: Pendulum.h:92
Eigen::VectorXd Vector
Definition: Vector.h:38
Vector evaluateError(const double &vk1, const double &vk, const double &q, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3) const override
Definition: Pendulum.h:101
Array< int, Dynamic, 1 > v
RealScalar alpha
EIGEN_DEVICE_FUNC const Scalar & q
NoiseModelFactorN< double, double, double > Base
Definition: Pendulum.h:124
Vector evaluateError(const double &qk1, const double &qk, const double &v, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3) const override
Definition: Pendulum.h:51
NoiseModelFactorN< double, double, double > Base
Definition: Pendulum.h:27
std::shared_ptr< PendulumFactor2 > shared_ptr
Definition: Pendulum.h:89
std::shared_ptr< PendulumFactor1 > shared_ptr
Definition: Pendulum.h:39
traits
Definition: chartTesting.h:28
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: Pendulum.h:207
const double h
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:143
Non-linear factor base classes.
NoiseModelFactorN< double, double, double > Base
Definition: Pendulum.h:182
std::shared_ptr< PendulumFactorPk > shared_ptr
Definition: Pendulum.h:140
std::shared_ptr< This > shared_ptr
float * p
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: Pendulum.h:96
#define abs(x)
Definition: datatypes.h:17
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102
Vector evaluateError(const double &pk, const double &qk, const double &qk1, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3) const override
Definition: Pendulum.h:154
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: Pendulum.h:46
std::shared_ptr< PendulumFactorPk1 > shared_ptr
Definition: Pendulum.h:198


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:35:13