Momentum.hpp
Go to the documentation of this file.
1 /*
2  * RDL - Robot Dynamics Library
3  * Copyright (c) 2017 Jordan Lack <jlack1987@gmail.com>
4  *
5  * Licensed under the zlib license. See LICENSE for more details.
6  */
7 
8 #ifndef __RDL_MOMENTUM_HPP__
9 #define __RDL_MOMENTUM_HPP__
10 
18 
19 namespace RobotDynamics
20 {
21 namespace Math
22 {
27 class Momentum : public ForceVector
28 {
29  public:
31  {
32  }
33 
34  Momentum(const double kx, const double ky, const double kz, const double lx, const double ly, const double lz) : ForceVector(kx, ky, kz, lx, ly, lz)
35  {
36  }
37 
38  Momentum(const Vector3d& k, const Vector3d l) : ForceVector(k.x(), k.y(), k.z(), l.x(), l.y(), l.z())
39  {
40  }
41 
42  Momentum(const Momentum& momentum) : ForceVector(momentum)
43  {
44  }
45 
46  explicit Momentum(const ForceVector& forceVector) : ForceVector(forceVector)
47  {
48  }
49 
50  Momentum(const RigidBodyInertia& inertia, const MotionVector& vector) : ForceVector()
51  {
52  computeMomentum(inertia, vector);
53  }
54 
68  {
69  Momentum m = *this;
70  m.transform(X);
71  return m;
72  }
73 
79  inline void set(const RigidBodyInertia& inertia, const MotionVector& vector)
80  {
81  computeMomentum(inertia, vector);
82  }
83 
84  EIGEN_STRONG_INLINE double& kx()
85  {
86  return this->data()[0];
87  }
88 
89  EIGEN_STRONG_INLINE double& ky()
90  {
91  return this->data()[1];
92  }
93 
94  EIGEN_STRONG_INLINE double& kz()
95  {
96  return this->data()[2];
97  }
98 
99  EIGEN_STRONG_INLINE double kx() const
100  {
101  return this->data()[0];
102  }
103 
104  EIGEN_STRONG_INLINE double ky() const
105  {
106  return this->data()[1];
107  }
108 
109  EIGEN_STRONG_INLINE double kz() const
110  {
111  return this->data()[2];
112  }
113 
114  EIGEN_STRONG_INLINE double& lx()
115  {
116  return this->data()[3];
117  }
118 
119  EIGEN_STRONG_INLINE double& ly()
120  {
121  return this->data()[4];
122  }
123 
124  EIGEN_STRONG_INLINE double& lz()
125  {
126  return this->data()[5];
127  }
128 
129  EIGEN_STRONG_INLINE double lx() const
130  {
131  return this->data()[3];
132  }
133 
134  EIGEN_STRONG_INLINE double ly() const
135  {
136  return this->data()[4];
137  }
138 
139  EIGEN_STRONG_INLINE double lz() const
140  {
141  return this->data()[5];
142  }
143 
148  inline Momentum operator+=(const Momentum& v)
149  {
150  (*this) << (this->mx() += v.mx()), (this->my() += v.my()), (this->mz() += v.mz()), (this->fx() += v.fx()), (this->fy() += v.fy()), (this->fz() += v.fz());
151  return *this;
152  }
153 
158  inline Momentum operator-=(const Momentum& v)
159  {
160  (*this) << (this->mx() -= v.mx()), (this->my() -= v.my()), (this->mz() -= v.mz()), (this->fx() -= v.fx()), (this->fy() -= v.fy()), (this->fz() -= v.fz());
161  return *this;
162  }
163 
170  EIGEN_STRONG_INLINE double operator*(const MotionVector& vector)
171  {
172  return this->dot(vector) * 0.5;
173  }
174 
175  protected:
181  inline void computeMomentum(const RigidBodyInertia& I, const MotionVector& v)
182  {
183  (*this) << I.Ixx * v[0] + I.Iyx * v[1] + I.Izx * v[2] + I.h[1] * v[5] - I.h[2] * v[4], I.Iyx * v[0] + I.Iyy * v[1] + I.Izy * v[2] - I.h[0] * v[5] + I.h[2] * v[3],
184  I.Izx * v[0] + I.Izy * v[1] + I.Izz * v[2] + I.h[0] * v[4] - I.h[1] * v[3], -I.h[1] * v[2] + I.h[2] * v[1] + I.m * v[3],
185  I.h[0] * v[2] - I.h[2] * v[0] + I.m * v[4], -I.h[0] * v[1] + I.h[1] * v[0] + I.m * v[5];
186  }
187 };
188 
195 static inline Momentum operator*(const RigidBodyInertia& I, const MotionVector& v)
196 {
197  return Momentum(I, v);
198 }
199 
206 static inline Momentum operator+(Momentum m1, const Momentum& m2)
207 {
208  m1 += m2;
209  return m1;
210 }
211 
218 static inline Momentum operator-(Momentum m1, const Momentum& m2)
219 {
220  m1 -= m2;
221  return m1;
222 }
223 
224 } // namespace Math
225 } // namespace RobotDynamics
226 
227 #endif // ifndef __RDL_MOMENTUM_HPP__
Momentum(const ForceVector &forceVector)
Definition: Momentum.hpp:46
EIGEN_STRONG_INLINE double & ly()
Definition: Momentum.hpp:119
EIGEN_STRONG_INLINE double ly() const
Definition: Momentum.hpp:134
EIGEN_STRONG_INLINE double kz() const
Definition: Momentum.hpp:109
Momentum transform_copy(const SpatialTransform &X) const
Copy then transform a ForceVector by .
Definition: Momentum.hpp:67
A ForceVector is a SpatialVector containing 3 moments and 3 linear forces.
Definition: ForceVector.hpp:27
EIGEN_STRONG_INLINE double & fy()
Get reference to y-linear component.
Momentum(const double kx, const double ky, const double kz, const double lx, const double ly, const double lz)
Definition: Momentum.hpp:34
FramePoint operator+(FramePoint p, const FrameVector &v)
Definition: FramePoint.hpp:295
See V. Duindum p39-40 & Featherstone p32-33.
EIGEN_STRONG_INLINE double & kz()
Definition: Momentum.hpp:94
Momentum(const RigidBodyInertia &inertia, const MotionVector &vector)
Definition: Momentum.hpp:50
void computeMomentum(const RigidBodyInertia &I, const MotionVector &v)
Computes momentum from inertia and velocity.
Definition: Momentum.hpp:181
void transform(const SpatialTransform &X)
Performs the following in place transform .
EIGEN_STRONG_INLINE double & fx()
Get reference to x-linear component.
EIGEN_STRONG_INLINE double & fz()
Get reference to z-linear component.
Momentum operator+=(const Momentum &v)
Overloaded plus-equals operator.
Definition: Momentum.hpp:148
EIGEN_STRONG_INLINE double & my()
Get reference to y-angular component.
Momentum(const Momentum &momentum)
Definition: Momentum.hpp:42
Compact representation of spatial transformations.
Momentum is mass/inertia multiplied by velocity.
Definition: Momentum.hpp:27
This class stores a bodies mass, center of mass, and inertia information. The inertia elements are st...
EIGEN_STRONG_INLINE double & kx()
Definition: Momentum.hpp:84
Momentum(const Vector3d &k, const Vector3d l)
Definition: Momentum.hpp:38
EIGEN_STRONG_INLINE double lx() const
Definition: Momentum.hpp:129
EIGEN_STRONG_INLINE double & mz()
Get reference to z-angular component.
EIGEN_STRONG_INLINE double kx() const
Definition: Momentum.hpp:99
EIGEN_STRONG_INLINE double operator*(const MotionVector &vector)
Operator for computing kinetic energy. With momentum, and Math::MotionVector, this performs perform...
Definition: Momentum.hpp:170
EIGEN_STRONG_INLINE double & lx()
Definition: Momentum.hpp:114
EIGEN_STRONG_INLINE double lz() const
Definition: Momentum.hpp:139
Momentum operator-=(const Momentum &v)
Overloaded plus-equals operator.
Definition: Momentum.hpp:158
FramePoint operator-(FramePoint p, const FrameVector &v)
Definition: FramePoint.hpp:301
EIGEN_STRONG_INLINE double & mx()
Get reference to x-angular component.
Definition: ForceVector.hpp:96
EIGEN_STRONG_INLINE double & lz()
Definition: Momentum.hpp:124
EIGEN_STRONG_INLINE double ky() const
Definition: Momentum.hpp:104
EIGEN_STRONG_INLINE double & ky()
Definition: Momentum.hpp:89
Namespace for all structures of the RobotDynamics library.
Definition: Body.h:21


rdl_dynamics
Author(s):
autogenerated on Tue Apr 20 2021 02:25:27