Ravelin
SpatialRBInertia.h
1 /****************************************************************************
2  * Copyright 2013 Evan Drumwright
3  * This library is distributed under the terms of the Apache V2.0
4  * License (obtainable from http://www.apache.org/licenses/LICENSE-2.0).
5  ****************************************************************************/
6 
7 #ifndef SPATIAL_RB_INERTIA
8 #error This class is not to be included by the user directly. Use SpatialRBInertiad.h or SpatialRBInertiaf.h instead.
9 #endif
10 
11 class POSE3;
12 
14 
26 {
27  public:
28  SPATIAL_RB_INERTIA(boost::shared_ptr<const POSE3> pose = boost::shared_ptr<const POSE3>());
29  SPATIAL_RB_INERTIA(boost::shared_ptr<POSE3> pose);
30  SPATIAL_RB_INERTIA(REAL m, const VECTOR3& h, const MATRIX3& J, boost::shared_ptr<const POSE3> pose = boost::shared_ptr<const POSE3>());
31  SPATIAL_RB_INERTIA(REAL m, const VECTOR3& h, const MATRIX3& J, boost::shared_ptr<POSE3> pose);
32  SPATIAL_RB_INERTIA(const SPATIAL_RB_INERTIA& source) { operator=(source); }
33  void set_zero();
34  static SPATIAL_RB_INERTIA zero() { SPATIAL_RB_INERTIA m; m.set_zero(); return m; }
35  SACCEL inverse_mult(const SFORCE& v) const;
36  SVELOCITY inverse_mult(const SMOMENTUM& m) const;
37  std::vector<SACCEL>& inverse_mult(const std::vector<SFORCE>& v, std::vector<SACCEL>& result) const;
41  SPATIAL_RB_INERTIA& operator*=(const SPATIAL_RB_INERTIA& m) { return *this = operator*(m); }
42  SPATIAL_RB_INERTIA& operator*=(REAL scalar);
43  SPATIAL_RB_INERTIA& operator/=(REAL scalar) { return operator*=((REAL) 1.0/scalar); }
46  SPATIAL_RB_INERTIA operator*(const SPATIAL_RB_INERTIA& m) const;
47  SPATIAL_RB_INERTIA operator*(REAL scalar) const { SPATIAL_RB_INERTIA m = *this; m *= scalar; return m; }
48  SPATIAL_RB_INERTIA operator/(REAL scalar) const { return operator*((REAL) 1.0/scalar); }
49  SFORCE operator*(const SACCEL& s) const;
50  std::vector<SFORCE>& mult(const std::vector<SACCEL>& s, std::vector<SFORCE>& result) const;
51  SMOMENTUM operator*(const SVELOCITY& s) const;
52  SMOMENTUM mult(const SVELOCITY& s) const { return operator*(s); }
53  std::vector<SMOMENTUM>& mult(const std::vector<SVELOCITY>& s, std::vector<SMOMENTUM>& result) const;
55 
57  REAL m;
58 
61 
64 
66  boost::shared_ptr<const POSE3> pose;
67 
69  template <class Mat>
70  Mat& to_matrix(Mat& M) const
71  {
72  const unsigned X = 0, Y = 1, Z = 2, SPATIAL_DIM = 6;
73 
74  // resize the matrix
75  M.resize(SPATIAL_DIM, SPATIAL_DIM);
76 
77  // precompute matrices
78  ORIGIN3 hm = h*m;
81 
82  // setup the 3x3 blocks
83  M.set_sub_mat(0,0, hxm, eTranspose);
84  M.set_sub_mat(3,0, J-hx*hxm);
85  M.set_sub_mat(0,3, MATRIX3(m, 0, 0, 0, m, 0, 0, 0, m));
86  M.set_sub_mat(3,3, hxm);
87 
88  return M;
89  }
90 
92  template <class Mat>
93  Mat& to_PD_matrix(Mat& M) const
94  {
95  const unsigned X = 0, Y = 1, Z = 2, SPATIAL_DIM = 6;
96 
97  // resize the matrix
98  M.resize(SPATIAL_DIM, SPATIAL_DIM);
99 
100  // precompute matrices
102  MATRIX3 mhx = MATRIX3::skew_symmetric(h*m);
103 
104  // setup the 3x3 blocks
105  M.set_sub_mat(0,3, mhx, eTranspose);
106  M.set_sub_mat(3,3, J - (mhx*hx));
107  M.set_sub_mat(0,0, MATRIX3(m, 0, 0, 0, m, 0, 0, 0, m));
108  M.set_sub_mat(3,0, mhx);
109 
110  return M;
111  }
112 
113  private:
114  void mult_spatial(const SVECTOR6& t, SVECTOR6& result) const;
115  void mult_spatial(const SVECTOR6& t, const MATRIX3& hxm, const MATRIX3& Jstar, SVECTOR6& result) const;
116  void inverse_mult_spatial(const SVECTOR6& w, SVECTOR6& result) const;
117  void inverse_mult_spatial(const SVECTOR6& w, const MATRIX3& iJ, const MATRIX3& hx, const MATRIX3& hxiJ, REAL m, SVECTOR6& result) const;
118 
119 }; // end class
120 
121 std::ostream& operator<<(std::ostream& out, const SPATIAL_RB_INERTIA& m);
122 
123 
SPATIAL_RB_INERTIA operator+(const SPATIAL_RB_INERTIA &m) const
Adds two spatial matrices.
Definition: SpatialRBInertia.cpp:246
SPATIAL_RB_INERTIA & operator-=(const SPATIAL_RB_INERTIA &m)
Subtracts m from this in place.
Definition: SpatialRBInertia.cpp:308
std::vector< SFORCE > & mult(const std::vector< SACCEL > &s, std::vector< SFORCE > &result) const
Multiplies this inertia by a vector of accelerations and returns a vector of forces.
Definition: SpatialRBInertia.cpp:320
boost::shared_ptr< const POSE3 > pose
The pose that this inertia is defined in.
Definition: SpatialRBInertia.h:66
SPATIAL_RB_INERTIA & operator+=(const SPATIAL_RB_INERTIA &m)
Adds m to this in place.
Definition: SpatialRBInertia.cpp:296
SACCEL inverse_mult(const SFORCE &v) const
Multiplies the inverse of this spatial matrix by a force.
Definition: SpatialRBInertia.cpp:137
A spatial (six dimensional) momentum.
Definition: SMomentum.h:12
SPATIAL_RB_INERTIA operator-() const
Returns the negation of this matrix.
Definition: SpatialRBInertia.cpp:235
MATRIX3 J
The rigid body moment of inertia matrix.
Definition: SpatialRBInertia.h:63
REAL m
The rigid body mass.
Definition: SpatialRBInertia.h:57
SPATIAL_RB_INERTIA & operator=(const SPATIAL_RB_INERTIA &source)
Copies a spatial matrix to this one.
Definition: SpatialRBInertia.cpp:46
A spatial velocity (a twist)
Definition: SVelocity.h:15
A rigid body pose.
Definition: Pose3.h:15
A 6-dimensional floating-point vector for use with spatial algebra.
Definition: SVector6.h:22
A 6x6 spatial algebra matrix used for dynamics calculations.
Definition: SpatialRBInertia.h:25
A spatial (six dimensional) acceleration.
Definition: SAccel.h:14
ORIGIN3 h
The position of the center-of-mass times the mass.
Definition: SpatialRBInertia.h:60
A three-dimensional floating point vector used for representing points and vectors in 3D with associa...
Definition: Vector3.h:15
A spatial force (a wrench)
Definition: SForce.h:14
A three-dimensional floating point vector used for representing points and vectors in 3D and without ...
Definition: Origin3.h:16
static MATRIX3 skew_symmetric(REAL a, REAL b, REAL c)
Constructs a skew-symmetric matrix from the given values.
Definition: Matrix3.cpp:260
Mat & to_matrix(Mat &M) const
Converts this to a matrix.
Definition: SpatialRBInertia.h:70
Mat & to_PD_matrix(Mat &M) const
Converts this to a positive-definite matrix.
Definition: SpatialRBInertia.h:93
A 3x3 matrix that may be used for orientation, inertia tensors, etc.
Definition: Matrix3.h:20
void set_zero()
Creates a zero matrix.
Definition: SpatialRBInertia.cpp:56