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 }
gtsam::PendulumFactorPk1::Base
NoiseModelFactorN< double, double, double > Base
Definition: Pendulum.h:182
gtsam::PendulumFactor1::PendulumFactor1
PendulumFactor1()
Definition: Pendulum.h:30
gtsam::PendulumFactor1::clone
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: Pendulum.h:46
gtsam::PendulumFactor2::PendulumFactor2
PendulumFactor2()
Definition: Pendulum.h:78
gtsam::NonlinearFactor::shared_ptr
std::shared_ptr< This > shared_ptr
Definition: NonlinearFactor.h:79
gtsam::PendulumFactorPk::PendulumFactorPk
PendulumFactorPk()
Definition: Pendulum.h:127
gtsam::PendulumFactorPk1::PendulumFactorPk1
PendulumFactorPk1()
Definition: Pendulum.h:185
alpha
RealScalar alpha
Definition: level1_cplx_impl.h:147
gtsam::PendulumFactorPk1::m_
double m_
time step
Definition: Pendulum.h:188
ceres::sin
Jet< T, N > sin(const Jet< T, N > &f)
Definition: jet.h:439
mu
double mu
Definition: testBoundingConstraint.cpp:37
gtsam::NoiseModelFactorN< double, double, double >::evaluateError
virtual Vector evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const=0
gtsam::PendulumFactorPk1::clone
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: Pendulum.h:207
gtsam::PendulumFactorPk::PendulumFactorPk
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
gtsam::PendulumFactorPk::r_
double r_
mass
Definition: Pendulum.h:131
gtsam::PendulumFactor2::h_
double h_
Definition: Pendulum.h:80
gtsam::PendulumFactorPk::clone
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: Pendulum.h:149
gtsam::PendulumFactorPk::evaluateError
Vector evaluateError(const double &pk, const double &qk, const double &qk1, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3) const override
Definition: Pendulum.h:154
gtsam::Factor
Definition: Factor.h:70
gtsam::PendulumFactor2::PendulumFactor2
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:92
gtsam::PendulumFactor1::h_
double h_
Definition: Pendulum.h:32
gtsam::PendulumFactor1::Base
NoiseModelFactorN< double, double, double > Base
Definition: Pendulum.h:27
h
const double h
Definition: testSimpleHelicopter.cpp:19
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:39
gtsam::PendulumFactor1::PendulumFactor1
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
ceres::cos
Jet< T, N > cos(const Jet< T, N > &f)
Definition: jet.h:426
gtsam::PendulumFactorPk::alpha_
double alpha_
gravity
Definition: Pendulum.h:133
gtsam::PendulumFactor2::r_
double r_
Definition: Pendulum.h:82
gtsam::PendulumFactor2::g_
double g_
Definition: Pendulum.h:81
gtsam::PendulumFactor2::shared_ptr
std::shared_ptr< PendulumFactor2 > shared_ptr
Definition: Pendulum.h:89
gtsam::PendulumFactorPk::g_
double g_
length
Definition: Pendulum.h:132
Eigen::numext::q
EIGEN_DEVICE_FUNC const Scalar & q
Definition: SpecialFunctionsImpl.h:1984
gtsam::NoiseModelFactor::noiseModel
const SharedNoiseModel & noiseModel() const
access to the noise model
Definition: NonlinearFactor.h:246
k1
double k1(double x)
Definition: k1.c:133
gtsam::PendulumFactorPk1::r_
double r_
mass
Definition: Pendulum.h:189
gtsam::NoiseModelFactorN
Definition: NonlinearFactor.h:432
gtsam::PendulumFactor1::shared_ptr
std::shared_ptr< PendulumFactor1 > shared_ptr
Definition: Pendulum.h:39
gtsam::PendulumFactor1::evaluateError
Vector evaluateError(const double &qk1, const double &qk, const double &v, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3) const override
Definition: Pendulum.h:51
gtsam::PendulumFactorPk1::PendulumFactorPk1
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
m
Matrix3f m
Definition: AngleAxis_mimic_euler.cpp:1
gtsam::PendulumFactorPk::shared_ptr
std::shared_ptr< PendulumFactorPk > shared_ptr
Definition: Pendulum.h:140
gtsam::PendulumFactorPk1::shared_ptr
std::shared_ptr< PendulumFactorPk1 > shared_ptr
Definition: Pendulum.h:198
g
void g(const string &key, int i)
Definition: testBTree.cpp:41
gtsam::PendulumFactorPk
Definition: Pendulum.h:120
gtsam::PendulumFactorPk1
Definition: Pendulum.h:178
NonlinearFactor.h
Non-linear factor base classes.
gtsam::PendulumFactor2
Definition: Pendulum.h:71
gtsam::PendulumFactor2::clone
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: Pendulum.h:96
gtsam::PendulumFactor2::Base
NoiseModelFactorN< double, double, double > Base
Definition: Pendulum.h:75
gtsam
traits
Definition: SFMdata.h:40
gtsam::PendulumFactorPk1::h_
double h_
Definition: Pendulum.h:187
gtsam::PendulumFactorPk1::evaluateError
Vector evaluateError(const double &pk1, const double &qk, const double &qk1, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3) const override
Definition: Pendulum.h:212
gtsam::PendulumFactorPk1::alpha_
double alpha_
gravity
Definition: Pendulum.h:191
std
Definition: BFloat16.h:88
gtsam::PendulumFactorPk::m_
double m_
time step
Definition: Pendulum.h:130
p
float * p
Definition: Tutorial_Map_using.cpp:9
v
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
gtsam::OptionalMatrixType
Matrix * OptionalMatrixType
Definition: NonlinearFactor.h:56
abs
#define abs(x)
Definition: datatypes.h:17
gtsam::PendulumFactorPk::h_
double h_
Definition: Pendulum.h:129
gtsam::PendulumFactor2::evaluateError
Vector evaluateError(const double &vk1, const double &vk, const double &q, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3) const override
Definition: Pendulum.h:101
gtsam::PendulumFactor1
Definition: Pendulum.h:23
gtsam::PendulumFactorPk::Base
NoiseModelFactorN< double, double, double > Base
Definition: Pendulum.h:124
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
gtsam::PendulumFactorPk1::g_
double g_
length
Definition: Pendulum.h:190


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:12:42