RigidBodyInertia.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_RIGID_BODY_INERTIA_HPP__
9 #define __RDL_RIGID_BODY_INERTIA_HPP__
10 
18 
19 namespace RobotDynamics
20 {
21 namespace Math
22 {
46 {
47  public:
51  RigidBodyInertia() : m(0.), h(Vector3d::Zero(3, 1)), Ixx(0.), Iyx(0.), Iyy(0.), Izx(0.), Izy(0.), Izz(0.)
52  {
53  }
54 
61  RigidBodyInertia(double mass, const Vector3d& com_mass, const Matrix3d& inertia)
62  : 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))
63  {
64  }
65 
77  RigidBodyInertia(double m, const Vector3d& h, const double Ixx, const double Iyx, const double Iyy, const double Izx, const double Izy, const double Izz)
78  : m(m), h(h), Ixx(Ixx), Iyx(Iyx), Iyy(Iyy), Izx(Izx), Izy(Izy), Izz(Izz)
79  {
80  }
81 
87  : m(inertia.m), h(inertia.h), Ixx(inertia.Ixx), Iyx(inertia.Iyx), Iyy(inertia.Iyy), Izx(inertia.Izx), Izy(inertia.Izy), Izz(inertia.Izz)
88  {
89  }
90 
95  inline void set(const RigidBodyInertia& I)
96  {
97  this->set(I.m, I.h, I.Ixx, I.Iyx, I.Iyy, I.Izx, I.Izy, I.Izz);
98  }
99 
111  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)
112  {
113  this->m = m;
114  this->h = h;
115  this->Ixx = Ixx;
116  this->Iyx = Iyx;
117  this->Iyy = Iyy;
118  this->Izx = Izx;
119  this->Izy = Izy;
120  this->Izz = Izz;
121  }
122 
127  void operator+=(const RigidBodyInertia& rbi);
128 
134  void transform(const SpatialTransform& X);
135 
142  {
143  RigidBodyInertia I = *this;
144  I.transform(X);
145  return I;
146  }
147 
152  void createFromMatrix(const SpatialMatrix& Ic);
153 
158  SpatialMatrix toMatrix() const;
159 
164  void setSpatialMatrix(SpatialMatrix& mat) const;
165 
174  {
175  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),
176  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),
177  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),
178  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));
179  }
180 
188  {
189  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],
190  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],
191  h[0] * v[2] - h[2] * v[0] + m * v[4], -h[0] * v[1] + h[1] * v[0] + m * v[5]);
192  }
193 
200  {
201  m.col(0) = this->timesSpatialVector(m.col(0));
202  m.col(1) = this->timesSpatialVector(m.col(1));
203  m.col(2) = this->timesSpatialVector(m.col(2));
204  return m;
205  }
206 
208  {
209  m = other.m;
210  h = other.h;
211  Ixx = other.Ixx;
212  Iyx = other.Iyx;
213  Iyy = other.Iyy;
214  Izx = other.Izx;
215  Izy = other.Izy;
216  Izz = other.Izz;
217  return *this;
218  }
219 
220  double m;
224  double Ixx;
225  double Iyx;
226  double Iyy;
227  double Izx;
228  double Izy;
229  double Izz;
230 };
231 
239 {
240  rbi_in += rbi;
241  return rbi_in;
242 }
243 
251 {
252  return I.timesSpatialVector(v);
253 }
254 
261 inline Matrix63 operator*(const RigidBodyInertia& I, const Matrix63& m)
262 {
263  return I.multiplyMatrix63(m);
264 }
265 
273 static inline RigidBodyInertia createFromMassComInertiaC(double mass, const Vector3d& com, const Matrix3d& inertia_C)
274 {
275  RigidBodyInertia result;
276 
277  result.m = mass;
278  result.h = com * mass;
279  Matrix3d I = inertia_C + toTildeForm(com) * toTildeForm(com).transpose() * mass;
280  result.Ixx = I(0, 0);
281  result.Iyx = I(1, 0);
282  result.Iyy = I(1, 1);
283  result.Izx = I(2, 0);
284  result.Izy = I(2, 1);
285  result.Izz = I(2, 2);
286 
287  // RigidBodyInertia B(mass,com*mass,inertia_C + toTildeForm(com) * toTildeForm(com).transpose() * mass);
288  return RigidBodyInertia(mass, com * mass, inertia_C + toTildeForm(com) * toTildeForm(com).transpose() * mass);
289 }
290 typedef std::vector<RigidBodyInertia, Eigen::aligned_allocator<RigidBodyInertia>> RigidBodyInertiaV;
291 } // namespace Math
292 } // namespace RobotDynamics
293 
294 #endif //__SPATIAL_INERTIA_HPP__
RigidBodyInertia transform_copy(const SpatialTransform &X) const
Copy, transform, and return a Math::RigidBodyInertia.
Matrix63 multiplyMatrix63(Matrix63 m) const
A helper method that returns a 6x3 matrix that is a Math::RigidBodyInertia multiplied by a 6x3 matrix...
RigidBodyInertia(double mass, const Vector3d &com_mass, const Matrix3d &inertia)
Constructor.
ForceVector operator*(const SpatialTransform &X, ForceVector f)
Operator for transforming a ForceVector. Calls the ForceVector::transform method. ...
void operator+=(const RigidBodyInertia &rbi)
Overloaded plus-equals operator. Adds two inertia matrices.
FramePoint operator+(FramePoint p, const FrameVector &v)
Definition: FramePoint.hpp:295
static Matrix3d toTildeForm(const Point3d &p)
Definition: Point3.hpp:370
RigidBodyInertia & operator=(const RigidBodyInertia &other)
void createFromMatrix(const SpatialMatrix &Ic)
Create a Math::RigidBodyInertia object from a 6x6 Math::SpatialMatrix.
The TransformableGeometricObject class is an essential interface because it forces all geometric obje...
Definition: rdl_eigenmath.h:43
Compact representation of spatial transformations.
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.
This class stores a bodies mass, center of mass, and inertia information. The inertia elements are st...
SpatialMatrix subtractSpatialMatrix(const SpatialMatrix &m) const
Given Math::RigidBodyInertia ad Math::SpatialMatrix , returns Math::SpatialMatrix such that ...
void transform(const SpatialTransform &X)
Transform a Math::RigidBodyInertia matrix.
Eigen::Matrix< double, 6, 3 > Matrix63
Definition: rdl_eigenmath.h:24
RigidBodyInertia(const RigidBodyInertia &inertia)
Copy constructor.
void setSpatialMatrix(SpatialMatrix &mat) const
Store a Math::RigidBodyInertia in the Math::SpatialMatrix.
Namespace for all structures of the RobotDynamics library.
Definition: Body.h:21
std::vector< RigidBodyInertia, Eigen::aligned_allocator< RigidBodyInertia > > RigidBodyInertiaV
static RigidBodyInertia createFromMassComInertiaC(double mass, const Vector3d &com, const Matrix3d &inertia_C)
SpatialVector timesSpatialVector(const SpatialVector &v) const
Multiply a Math::RigidBodyInertia by a Math::SpatialVector and return the result as a new Math::Spati...


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