Robot Dynamics Library
Momentum.hpp
Go to the documentation of this file.
1 // Copyright (c) 2017 Jordan Lack <jlack1987@gmail.com>
2 // RDL - Robot Dynamics Library
3 // Licensed under the zlib license. See LICENSE for more details.
4 
5 #ifndef __RDL_MOMENTUM_HPP__
6 #define __RDL_MOMENTUM_HPP__
7 
15 
16 namespace RobotDynamics
17 {
18 namespace Math
19 {
24 class Momentum : public ForceVector
25 {
26  public:
28  {
29  }
30 
31  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)
32  {
33  }
34 
35  Momentum(const Vector3d& k, const Vector3d l) : ForceVector(k.x(), k.y(), k.z(), l.x(), l.y(), l.z())
36  {
37  }
38 
39  Momentum(const Momentum& momentum) : ForceVector(momentum)
40  {
41  }
42 
43  explicit Momentum(const ForceVector& forceVector) : ForceVector(forceVector)
44  {
45  }
46 
48  {
50  return *this;
51  }
52 
53  Momentum(const RigidBodyInertia& inertia, const MotionVector& vector) : Momentum(computeMomentum(inertia, vector))
54  {
55  }
56 
70  {
71  Momentum m = *this;
72  m.transform(X);
73  return m;
74  }
75 
76  EIGEN_STRONG_INLINE double& kx()
77  {
78  return this->operator[](0);
79  }
80 
81  EIGEN_STRONG_INLINE double& ky()
82  {
83  return this->operator[](1);
84  }
85 
86  EIGEN_STRONG_INLINE double& kz()
87  {
88  return this->operator[](2);
89  }
90 
91  EIGEN_STRONG_INLINE double kx() const
92  {
93  return this->operator[](0);
94  }
95 
96  EIGEN_STRONG_INLINE double ky() const
97  {
98  return this->operator[](1);
99  }
100 
101  EIGEN_STRONG_INLINE double kz() const
102  {
103  return this->operator[](2);
104  }
105 
106  EIGEN_STRONG_INLINE double& lx()
107  {
108  return this->operator[](3);
109  }
110 
111  EIGEN_STRONG_INLINE double& ly()
112  {
113  return this->operator[](4);
114  }
115 
116  EIGEN_STRONG_INLINE double& lz()
117  {
118  return this->operator[](5);
119  }
120 
121  EIGEN_STRONG_INLINE double lx() const
122  {
123  return this->operator[](3);
124  }
125 
126  EIGEN_STRONG_INLINE double ly() const
127  {
128  return this->operator[](4);
129  }
130 
131  EIGEN_STRONG_INLINE double lz() const
132  {
133  return this->operator[](5);
134  }
135 
140  inline Momentum operator+=(const Momentum& v)
141  {
142  (*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());
143  return *this;
144  }
145 
150  inline Momentum operator-=(const Momentum& v)
151  {
152  (*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());
153  return *this;
154  }
155 
162  EIGEN_STRONG_INLINE double operator*(const MotionVector& vector)
163  {
164  return this->dot(vector) * 0.5;
165  }
166 
172  static inline Momentum computeMomentum(const RigidBodyInertia& I, const MotionVector& v)
173  {
174  return Momentum(I.Ixx * v[0] + I.Iyx * v[1] + I.Izx * v[2] + I.h[1] * v[5] - I.h[2] * v[4],
175  I.Iyx * v[0] + I.Iyy * v[1] + I.Izy * v[2] - I.h[0] * v[5] + I.h[2] * v[3],
176  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],
177  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]);
178  }
179 };
180 
187 static inline Momentum operator*(const RigidBodyInertia& I, const MotionVector& v)
188 {
189  return Momentum::computeMomentum(I, v);
190 }
191 
198 static inline Momentum operator+(Momentum m1, const Momentum& m2)
199 {
200  m1 += m2;
201  return m1;
202 }
203 
210 static inline Momentum operator-(Momentum m1, const Momentum& m2)
211 {
212  m1 -= m2;
213  return m1;
214 }
215 
216 } // namespace Math
217 } // namespace RobotDynamics
218 
219 #endif // ifndef __RDL_MOMENTUM_HPP__
Contains various geometric objects that have methods for transforming themselves into different frame...
Contains various geometric objects that have methods for transforming themselves into different frame...
See V. Duindum p39-40 & Featherstone p32-33.
A ForceVector is a SpatialVector containing 3 moments and 3 linear forces.
Definition: ForceVector.hpp:23
EIGEN_STRONG_INLINE double & fx()
Get reference to x-linear component.
Definition: ForceVector.hpp:145
EIGEN_STRONG_INLINE double & my()
Get reference to y-angular component.
Definition: ForceVector.hpp:100
EIGEN_STRONG_INLINE double & fy()
Get reference to y-linear component.
Definition: ForceVector.hpp:154
EIGEN_STRONG_INLINE double & mz()
Get reference to z-angular component.
Definition: ForceVector.hpp:109
EIGEN_STRONG_INLINE double & fz()
Get reference to z-linear component.
Definition: ForceVector.hpp:163
void transform(const SpatialTransform &X)
Performs the following in place transform.
Definition: ForceVector.hpp:206
EIGEN_STRONG_INLINE double & mx()
Get reference to x-angular component.
Definition: ForceVector.hpp:91
Momentum is mass/inertia multiplied by velocity.
Definition: Momentum.hpp:25
Momentum & operator=(const Momentum &m)
Definition: Momentum.hpp:47
Momentum(const double kx, const double ky, const double kz, const double lx, const double ly, const double lz)
Definition: Momentum.hpp:31
Momentum operator-=(const Momentum &v)
Overloaded plus-equals operator.
Definition: Momentum.hpp:150
EIGEN_STRONG_INLINE double kx() const
Definition: Momentum.hpp:91
EIGEN_STRONG_INLINE double & kz()
Definition: Momentum.hpp:86
EIGEN_STRONG_INLINE double & lz()
Definition: Momentum.hpp:116
static Momentum computeMomentum(const RigidBodyInertia &I, const MotionVector &v)
Computes momentum from inertia and velocity.
Definition: Momentum.hpp:172
EIGEN_STRONG_INLINE double operator*(const MotionVector &vector)
Operator for computing kinetic energy. With momentum, and Math::MotionVector, this performs perform...
Definition: Momentum.hpp:162
Momentum(const ForceVector &forceVector)
Definition: Momentum.hpp:43
EIGEN_STRONG_INLINE double & lx()
Definition: Momentum.hpp:106
EIGEN_STRONG_INLINE double ky() const
Definition: Momentum.hpp:96
Momentum(const RigidBodyInertia &inertia, const MotionVector &vector)
Definition: Momentum.hpp:53
Momentum operator+=(const Momentum &v)
Overloaded plus-equals operator.
Definition: Momentum.hpp:140
Momentum(const Vector3d &k, const Vector3d l)
Definition: Momentum.hpp:35
Momentum()
Definition: Momentum.hpp:27
EIGEN_STRONG_INLINE double lz() const
Definition: Momentum.hpp:131
EIGEN_STRONG_INLINE double & kx()
Definition: Momentum.hpp:76
Momentum(const Momentum &momentum)
Definition: Momentum.hpp:39
Momentum transform_copy(const SpatialTransform &X) const
Copy then transform a ForceVector by.
Definition: Momentum.hpp:69
EIGEN_STRONG_INLINE double & ky()
Definition: Momentum.hpp:81
EIGEN_STRONG_INLINE double lx() const
Definition: Momentum.hpp:121
EIGEN_STRONG_INLINE double & ly()
Definition: Momentum.hpp:111
EIGEN_STRONG_INLINE double kz() const
Definition: Momentum.hpp:101
EIGEN_STRONG_INLINE double ly() const
Definition: Momentum.hpp:126
Definition: MotionVector.hpp:21
This class stores a bodies mass, center of mass, and inertia information. The inertia elements are st...
Definition: RigidBodyInertia.hpp:42
Vector3d h
Definition: RigidBodyInertia.hpp:218
double Iyx
Definition: RigidBodyInertia.hpp:221
double Izz
Definition: RigidBodyInertia.hpp:225
double m
Definition: RigidBodyInertia.hpp:216
double Izy
Definition: RigidBodyInertia.hpp:224
double Iyy
Definition: RigidBodyInertia.hpp:222
double Izx
Definition: RigidBodyInertia.hpp:223
double Ixx
Definition: RigidBodyInertia.hpp:220
SpatialVector & operator=(const Eigen::MatrixBase< OtherDerived > &other)
Definition: rdl_eigenmath.hpp:198
Definition: rdl_eigenmath.hpp:54
FramePoint operator-(FramePoint p, const FrameVector &v)
Definition: FramePoint.hpp:410
FramePoint operator+(FramePoint p, const FrameVector &v)
Definition: FramePoint.hpp:404
ForceVector operator*(const SpatialTransform &X, ForceVector f)
Operator for transforming a ForceVector. Calls the ForceVector::transform method.
Definition: ForceVector.hpp:248
Namespace for all structures of the RobotDynamics library.
Definition: examples.hpp:19
Compact representation of spatial transformations.
Definition: rdl_eigenmath.hpp:412