Ravelin
SpatialABInertia.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_AB_INERTIA
8 #error This class is not to be included by the user directly. Use SPATIAL_AB_INERTIAd.h or SPATIAL_AB_INERTIAf.h instead.
9 #endif
10 
11 class POSE3;
12 
14 
21 {
22  public:
23  SPATIAL_AB_INERTIA(boost::shared_ptr<const POSE3> pose = boost::shared_ptr<const POSE3>());
24  SPATIAL_AB_INERTIA(boost::shared_ptr<POSE3> pose);
25  SPATIAL_AB_INERTIA(const MATRIX3& M, const MATRIX3& H, const MATRIX3& J, boost::shared_ptr<const POSE3> pose = boost::shared_ptr<const POSE3>());
26  SPATIAL_AB_INERTIA(const MATRIX3& M, const MATRIX3& H, const MATRIX3& J, boost::shared_ptr<POSE3> pose = boost::shared_ptr<POSE3>());
27  SPATIAL_AB_INERTIA(const SPATIAL_AB_INERTIA& source) { operator=(source); }
28  SPATIAL_AB_INERTIA(const SPATIAL_RB_INERTIA& source) { operator=(source); }
29  void set_zero();
30  static SPATIAL_AB_INERTIA zero() { SPATIAL_AB_INERTIA m; m.set_zero(); return m; }
31  SACCEL inverse_mult(const SFORCE& f) const;
32  SVELOCITY inverse_mult(const SMOMENTUM& m) const;
33  std::vector<SACCEL>& inverse_mult(const std::vector<SFORCE>& w, std::vector<SACCEL>& result) const;
38  SPATIAL_AB_INERTIA& operator*=(const SPATIAL_AB_INERTIA& m) { return *this = operator*(m); }
39  SPATIAL_AB_INERTIA& operator*=(REAL scalar);
40  SPATIAL_AB_INERTIA& operator/=(REAL scalar) { return operator*=(1.0/scalar); }
43  SPATIAL_AB_INERTIA& operator+=(const SPATIAL_RB_INERTIA& m) { return *this = *this + m; }
46  SPATIAL_AB_INERTIA operator*(const SPATIAL_AB_INERTIA& m) const;
47  SPATIAL_AB_INERTIA operator*(REAL scalar) const { SPATIAL_AB_INERTIA m = *this; m *= scalar; return m; }
48  SPATIAL_AB_INERTIA operator/(REAL scalar) const { return operator*((REAL) 1.0/scalar); }
49  SFORCE operator*(const SACCEL& s) const { return mult(s); }
50  SFORCE mult(const SACCEL& s) const;
51  std::vector<SFORCE>& mult(const std::vector<SACCEL>& s, std::vector<SFORCE>& result) const;
52  SMOMENTUM operator*(const SVELOCITY& s) const { return mult(s); }
53  SMOMENTUM mult(const SVELOCITY& s) const;
54  std::vector<SMOMENTUM>& mult(const std::vector<SVELOCITY>& s, std::vector<SMOMENTUM>& result) const;
56  static SPATIAL_AB_INERTIA inverse_inertia(const SPATIAL_AB_INERTIA& I);
57 
58  template <class Mat>
59  static SPATIAL_AB_INERTIA from_matrix(const Mat& m, boost::shared_ptr<const POSE3> pose = boost::shared_ptr<const POSE3>())
60  {
61  SPATIAL_AB_INERTIA I(pose);
62 
63  #ifndef NEXCEPT
64  if (m.rows() != 6 || m.columns() != 6)
65  throw MissizeException();
66  #endif
67  m.get_sub_mat(3, 6, 3, 6, I.H);
68  m.get_sub_mat(0, 3, 0, 3, I.M); // note: using M=H' here temporarily
69  I.H += MATRIX3::transpose(I.M); // to compute mean of the two
70  I.H *= (REAL) 0.5; // matrices
71  m.get_sub_mat(0, 3, 3, 6, I.M);
72  m.get_sub_mat(3, 6, 0, 3, I.J);
73  return I;
74  }
75 
76  template <class Mat>
77  static SPATIAL_AB_INERTIA from_matrix(const Mat& m, boost::shared_ptr<POSE3> pose = boost::shared_ptr<POSE3>())
78  {
79  return from_matrix(m, boost::const_pointer_cast<const POSE3>(pose));
80  }
81 
82  template <class Mat>
83  Mat& to_matrix(Mat& m) const
84  {
85  m.resize(6,6);
86  m.set_sub_mat(0, 0, MATRIX3::transpose(H));
87  m.set_sub_mat(0, 3, M);
88  m.set_sub_mat(3, 3, H);
89  m.set_sub_mat(3, 0, J);
90  return m;
91  }
92 
95 
98 
101 
103  boost::shared_ptr<const POSE3> pose;
104 
105  private:
106  void mult_spatial(const SVECTOR6& v, SVECTOR6& result) const;
107  void inverse_mult_spatial(const SFORCE& w, SVECTOR6& result) const;
108  void inverse_mult_spatial(const SFORCE& w, const MATRIX3& UL, const MATRIX3& UR, const MATRIX3& LL, SVECTOR6& result) const;
109 }; // end class
110 
111 std::ostream& operator<<(std::ostream& out, const SPATIAL_AB_INERTIA& m);
112 
SPATIAL_AB_INERTIA & operator=(const SPATIAL_RB_INERTIA &source)
Copies a spatial RB inertia to this one.
Definition: SpatialABInertia.cpp:57
SPATIAL_AB_INERTIA & operator-=(const SPATIAL_AB_INERTIA &m)
Subtracts m from this in place.
Definition: SpatialABInertia.cpp:287
A spatial (six dimensional) momentum.
Definition: SMomentum.h:12
SPATIAL_AB_INERTIA operator-() const
Returns the negation of this matrix.
Definition: SpatialABInertia.cpp:204
boost::shared_ptr< const POSE3 > pose
The pose that this inertia is defined in.
Definition: SpatialABInertia.h:103
MATRIX3 M
The upper right matrix.
Definition: SpatialABInertia.h:100
M & get_sub_mat(unsigned row_start, unsigned row_end, unsigned col_start, unsigned col_end, M &m, Transposition trans=eNoTranspose) const
Gets the specified sub matrix.
Definition: Matrix3.h:263
A spatial velocity (a twist)
Definition: SVelocity.h:15
SPATIAL_RB_INERTIA to_rb_inertia() const
Converts this matrix to a spatial RB inertia.
Definition: SpatialABInertia.cpp:71
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 typically used for dynamics calculations.
Definition: SpatialABInertia.h:20
A 6x6 spatial algebra matrix used for dynamics calculations.
Definition: SpatialRBInertia.h:25
A spatial (six dimensional) acceleration.
Definition: SAccel.h:14
SACCEL inverse_mult(const SFORCE &f) const
Multiplies the inverse of this spatial AB inertia by a force to yield an acceleration.
Definition: SpatialABInertia.cpp:301
SFORCE mult(const SACCEL &s) const
Multiplies this matrix by an acceleration and returns the result in a force.
Definition: SpatialABInertia.cpp:131
A spatial force (a wrench)
Definition: SForce.h:14
SPATIAL_AB_INERTIA operator+(const SPATIAL_RB_INERTIA &m) const
Adds a spatial articulated body inertia and a spatial rigid body inertia.
Definition: SpatialABInertia.cpp:215
void transpose()
Sets this matrix to its transpose.
Definition: Matrix3.cpp:522
MATRIX3 J
The lower left matrix.
Definition: SpatialABInertia.h:97
void set_zero()
Creates a zero matrix.
Definition: SpatialABInertia.cpp:82
SPATIAL_AB_INERTIA & operator+=(const SPATIAL_AB_INERTIA &m)
Adds m to this in place.
Definition: SpatialABInertia.cpp:273
A 3x3 matrix that may be used for orientation, inertia tensors, etc.
Definition: Matrix3.h:20
MATRIX3 H
The lower right hand matrix 'H' (and transpose of upper left matrix)
Definition: SpatialABInertia.h:94