Robot Dynamics Library
RigidBodyInertia.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_RIGID_BODY_INERTIA_HPP__
6 #define __RDL_RIGID_BODY_INERTIA_HPP__
7 
14 
15 namespace RobotDynamics
16 {
17 namespace Math
18 {
42 {
43  public:
47  RigidBodyInertia() : m(0.), h(Vector3d::Zero(3, 1)), Ixx(0.), Iyx(0.), Iyy(0.), Izx(0.), Izy(0.), Izz(0.)
48  {
49  }
50 
57  RigidBodyInertia(double mass, const Vector3d& com_mass, const Matrix3d& inertia)
58  : m(mass), h(com_mass), Ixx(inertia(0, 0)), Iyx(inertia(1, 0)), Iyy(inertia(1, 1)), Izx(inertia(2, 0)), Izy(inertia(2, 1)), Izz(inertia(2, 2))
59  {
60  }
61 
73  RigidBodyInertia(double m, const Vector3d& h, const double Ixx, const double Iyx, const double Iyy, const double Izx, const double Izy, const double Izz)
74  : m(m), h(h), Ixx(Ixx), Iyx(Iyx), Iyy(Iyy), Izx(Izx), Izy(Izy), Izz(Izz)
75  {
76  }
77 
83  : m(inertia.m), h(inertia.h), Ixx(inertia.Ixx), Iyx(inertia.Iyx), Iyy(inertia.Iyy), Izx(inertia.Izx), Izy(inertia.Izy), Izz(inertia.Izz)
84  {
85  }
86 
91  inline void set(const RigidBodyInertia& I)
92  {
93  this->set(I.m, I.h, I.Ixx, I.Iyx, I.Iyy, I.Izx, I.Izy, I.Izz);
94  }
95 
107  void set(double m, const Vector3d& h, const double Ixx, const double Iyx, const double Iyy, const double Izx, const double Izy, const double Izz)
108  {
109  this->m = m;
110  this->h = h;
111  this->Ixx = Ixx;
112  this->Iyx = Iyx;
113  this->Iyy = Iyy;
114  this->Izx = Izx;
115  this->Izy = Izy;
116  this->Izz = Izz;
117  }
118 
123  void operator+=(const RigidBodyInertia& rbi);
124 
130  void transform(const SpatialTransform& X);
131 
138  {
139  RigidBodyInertia I = *this;
140  I.transform(X);
141  return I;
142  }
143 
148  void createFromMatrix(const SpatialMatrix& Ic);
149 
154  SpatialMatrix toMatrix() const;
155 
160  void setSpatialMatrix(SpatialMatrix& mat) const;
161 
170  {
171  return SpatialMatrix(Ixx - m(0, 0), Iyx - m(0, 1), Izx - m(0, 2), -m(0, 3), -h[2] - m(0, 4), h[1] - m(0, 5), Iyx - m(1, 0), Iyy - m(1, 1), Izy - m(1, 2),
172  h[2] - m(1, 3), -m(1, 4), -h[0] - m(1, 5), Izx - m(2, 0), Izy - m(2, 1), Izz - m(2, 2), -h[1] - m(2, 3), h[0] - m(2, 4), -m(2, 5), -m(3, 0),
173  h[2] - m(3, 1), -h[1] - m(3, 2), this->m - m(3, 3), -m(3, 4), -m(3, 5), -h[2] - m(4, 0), -m(4, 1), h[0] - m(4, 2), -m(4, 3),
174  this->m - m(4, 4), -m(4, 5), h[1] - m(5, 0), -h[0] - m(5, 1), -m(5, 2), -m(5, 3), -m(5, 4), this->m - m(5, 5));
175  }
176 
184  {
185  return SpatialVector(Ixx * v[0] + Iyx * v[1] + Izx * v[2] + h[1] * v[5] - h[2] * v[4], Iyx * v[0] + Iyy * v[1] + Izy * v[2] - h[0] * v[5] + h[2] * v[3],
186  Izx * v[0] + Izy * v[1] + Izz * v[2] + h[0] * v[4] - h[1] * v[3], -h[1] * v[2] + h[2] * v[1] + m * v[3],
187  h[0] * v[2] - h[2] * v[0] + m * v[4], -h[0] * v[1] + h[1] * v[0] + m * v[5]);
188  }
189 
196  {
197  m.col(0) = this->timesSpatialVector(m.col(0));
198  m.col(1) = this->timesSpatialVector(m.col(1));
199  m.col(2) = this->timesSpatialVector(m.col(2));
200  return m;
201  }
202 
204  {
205  m = I.m;
206  h = I.h;
207  Ixx = I.Ixx;
208  Iyx = I.Iyx;
209  Iyy = I.Iyy;
210  Izx = I.Izx;
211  Izy = I.Izy;
212  Izz = I.Izz;
213  return *this;
214  }
215 
216  double m;
220  double Ixx;
221  double Iyx;
222  double Iyy;
223  double Izx;
224  double Izy;
225  double Izz;
226 };
227 
235 {
236  rbi_in += rbi;
237  return rbi_in;
238 }
239 
247 {
248  return I.timesSpatialVector(v);
249 }
250 
257 inline Matrix63 operator*(const RigidBodyInertia& I, const Matrix63& m)
258 {
259  return I.multiplyMatrix63(m);
260 }
261 
269 static inline RigidBodyInertia createFromMassComInertiaC(double mass, const Vector3d& com, const Matrix3d& inertia_C)
270 {
271  RigidBodyInertia result;
272 
273  result.m = mass;
274  result.h = com * mass;
275  Matrix3d I = inertia_C + com.toTildeForm() * com.toTildeForm().transpose() * mass;
276  result.Ixx = I(0, 0);
277  result.Iyx = I(1, 0);
278  result.Iyy = I(1, 1);
279  result.Izx = I(2, 0);
280  result.Izy = I(2, 1);
281  result.Izz = I(2, 2);
282 
283  return RigidBodyInertia(mass, com * mass, inertia_C + com.toTildeForm() * com.toTildeForm().transpose() * mass);
284 }
285 typedef std::vector<RigidBodyInertia, Eigen::aligned_allocator<RigidBodyInertia>> RigidBodyInertiaV;
286 } // namespace Math
287 } // namespace RobotDynamics
288 
289 #endif //__SPATIAL_INERTIA_HPP__
Definition: rdl_eigenmath.hpp:104
This class stores a bodies mass, center of mass, and inertia information. The inertia elements are st...
Definition: RigidBodyInertia.hpp:42
void createFromMatrix(const SpatialMatrix &Ic)
Create a Math::RigidBodyInertia object from a 6x6 Math::SpatialMatrix.
Definition: RigidBodyInertia.cpp:87
RigidBodyInertia(double mass, const Vector3d &com_mass, const Matrix3d &inertia)
Constructor.
Definition: RigidBodyInertia.hpp:57
Matrix63 multiplyMatrix63(Matrix63 m) const
A helper method that returns a 6x3 matrix that is a Math::RigidBodyInertia multiplied by a 6x3 matrix...
Definition: RigidBodyInertia.hpp:195
void setSpatialMatrix(SpatialMatrix &mat) const
Store a Math::RigidBodyInertia in the Math::SpatialMatrix.
Definition: RigidBodyInertia.cpp:119
RigidBodyInertia(double m, const Vector3d &h, const double Ixx, const double Iyx, const double Iyy, const double Izx, const double Izy, const double Izz)
Constructor.
Definition: RigidBodyInertia.hpp:73
void set(const RigidBodyInertia &I)
Setter.
Definition: RigidBodyInertia.hpp:91
SpatialMatrix subtractSpatialMatrix(const SpatialMatrix &m) const
Given Math::RigidBodyInertia ad Math::SpatialMatrix , returns Math::SpatialMatrix such that .
Definition: RigidBodyInertia.hpp:169
SpatialVector timesSpatialVector(const SpatialVector &v) const
Multiply a Math::RigidBodyInertia by a Math::SpatialVector and return the result as a new Math::Spati...
Definition: RigidBodyInertia.hpp:183
void operator+=(const RigidBodyInertia &rbi)
Overloaded plus-equals operator. Adds two inertia matrices.
Definition: RigidBodyInertia.cpp:11
Vector3d h
Definition: RigidBodyInertia.hpp:218
SpatialMatrix toMatrix() const
Definition: RigidBodyInertia.cpp:99
double Iyx
Definition: RigidBodyInertia.hpp:221
double Izz
Definition: RigidBodyInertia.hpp:225
void transform(const SpatialTransform &X)
Transform a Math::RigidBodyInertia matrix.
Definition: RigidBodyInertia.cpp:23
RigidBodyInertia(const RigidBodyInertia &inertia)
Copy constructor.
Definition: RigidBodyInertia.hpp:82
double m
Definition: RigidBodyInertia.hpp:216
RigidBodyInertia()
Constructor.
Definition: RigidBodyInertia.hpp:47
double Izy
Definition: RigidBodyInertia.hpp:224
double Iyy
Definition: RigidBodyInertia.hpp:222
double Izx
Definition: RigidBodyInertia.hpp:223
RigidBodyInertia & operator=(const RigidBodyInertia &I)
Definition: RigidBodyInertia.hpp:203
RigidBodyInertia transform_copy(const SpatialTransform &X) const
Copy, transform, and return a Math::RigidBodyInertia.
Definition: RigidBodyInertia.hpp:137
void set(double m, const Vector3d &h, const double Ixx, const double Iyx, const double Iyy, const double Izx, const double Izy, const double Izz)
Setter.
Definition: RigidBodyInertia.hpp:107
double Ixx
Definition: RigidBodyInertia.hpp:220
Definition: rdl_eigenmath.hpp:354
Definition: rdl_eigenmath.hpp:187
The TransformableGeometricObject class is an essential interface because it forces all geometric obje...
Definition: rdl_eigenmath.hpp:43
Definition: rdl_eigenmath.hpp:54
Matrix3d toTildeForm() const
Definition: rdl_eigenmath.cpp:118
FramePoint operator+(FramePoint p, const FrameVector &v)
Definition: FramePoint.hpp:404
static RigidBodyInertia createFromMassComInertiaC(double mass, const Vector3d &com, const Matrix3d &inertia_C)
Definition: RigidBodyInertia.hpp:269
std::vector< RigidBodyInertia, Eigen::aligned_allocator< RigidBodyInertia > > RigidBodyInertiaV
Definition: RigidBodyInertia.hpp:285
ForceVector operator*(const SpatialTransform &X, ForceVector f)
Operator for transforming a ForceVector. Calls the ForceVector::transform method.
Definition: ForceVector.hpp:248
Eigen::Matrix< double, 6, 3 > Matrix63
Definition: rdl_eigenmath.hpp:19
Namespace for all structures of the RobotDynamics library.
Definition: examples.hpp:19
Compact representation of spatial transformations.
Definition: rdl_eigenmath.hpp:412