Robotics Library  0.6.2
RigidBodyInertia.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2009, Markus Rickert
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 // POSSIBILITY OF SUCH DAMAGE.
25 //
26 
27 #ifndef _RL_MATH_RIGIDBODYINERTIA_H_
28 #define _RL_MATH_RIGIDBODYINERTIA_H_
29 
30 #include <Eigen/Core>
31 
32 namespace rl
33 {
34  namespace math
35  {
36  namespace spatial
37  {
38  template< typename Scalar > class ForceVector;
39 
40  template< typename Scalar > class MotionVector;
41 
42  template< typename Scalar >
44  {
45  public:
46  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
47 
48  typedef Scalar ScalarType;
49 
50  typedef ::Eigen::Matrix< Scalar, 6, 6 > MatrixType;
51 
52  typedef ::Eigen::Matrix< Scalar, 3, 1 > CenterOfGravityType;
53 
55 
56  typedef ::Eigen::Matrix< Scalar, 3, 3 > InertiaType;
57 
59 
60  typedef Scalar MassType;
61 
62  typedef const MassType ConstMassType;
63 
65  {
66  }
67 
68  template< typename OtherDerived >
69  RigidBodyInertia(const ::Eigen::DenseBase< OtherDerived >& other) :
70  centerOfGravityData(other.template topRightCorner< 3, 3 >().cross3()),
71  inertiaData(other.template topLeftCorner< 3, 3 >()),
72  massData(other.template bottomRightCorner< 3, 3 >().diagonal().mean())
73  {
74  }
75 
77  {
78  }
79 
81  {
82  return centerOfGravityData;
83  }
84 
86  {
87  return centerOfGravityData;
88  }
89 
91  {
92  return inertiaData;
93  }
94 
96  {
97  return inertiaData;
98  }
99 
101  {
102  return massData;
103  }
104 
106  {
107  return massData;
108  }
109 
111  {
112  MatrixType res;
113  res.template topLeftCorner< 3, 3 >() = inertia();
114  res.template topRightCorner< 3, 3 >() = cog().cross33();
115  res.template bottomLeftCorner< 3, 3 >() = -cog().cross33();
116  res.template bottomRightCorner< 3, 3 >() = ::Eigen::Matrix< Scalar, 3, 3 >::Identity() * mass();
117  return res;
118  }
119 
120  template< typename OtherDerived >
121  RigidBodyInertia& operator=(const ::Eigen::MatrixBase< OtherDerived >& other)
122  {
123  cog() = other.template topRightCorner< 3, 3 >().cross3();
124  inertia() = other.template topLeftCorner< 3, 3 >();
125  mass() = other.template bottomRightCorner< 3, 3 >().diagonal().mean();
126  return *this;
127  }
128 
130  {
131  RigidBodyInertia res;
132  res.cog() = cog() + other.cog();
133  res.inertia() = inertia() + other.inertia();
134  res.mass() = mass() + other.mass();
135  return res;
136  }
137 
139  {
140  RigidBodyInertia res;
141  res.cog() = cog() - other.cog();
142  res.inertia() = inertia() - other.inertia();
143  res.mass() = mass() - other.mass();
144  return res;
145  }
146 
147  template< typename OtherScalar >
148  RigidBodyInertia operator*(const OtherScalar& other) const
149  {
150  RigidBodyInertia res;
151  res.cog() = cog() * other;
152  res.inertia() = inertia() * other;
153  res.mass() = mass() * other;
154  return res;
155  }
156 
157  template< typename OtherScalar >
159 
160  template< typename OtherScalar >
161  RigidBodyInertia operator/(const OtherScalar& other) const
162  {
163  RigidBodyInertia res;
164  res.cog() = cog() / other;
165  res.inertia() = inertia() / other;
166  res.mass() = mass() / other;
167  return res;
168  }
169 
170  void setIdentity()
171  {
172  cog().setZero();
173  inertia().setIdentity();
174  mass() = 1;
175  }
176 
177  void setZero()
178  {
179  cog().setZero();
180  inertia().setZero();
181  mass() = 0;
182  }
183 
184  protected:
185 
186  private:
188 
190 
192  };
193  }
194  }
195 }
196 
197 #endif // _RL_MATH_RIGIDBODYINERTIA_H_
rl::math::spatial::RigidBodyInertia::operator*
RigidBodyInertia operator*(const OtherScalar &other) const
Definition: RigidBodyInertia.h:148
rl::math::spatial::RigidBodyInertia::MatrixType
::Eigen::Matrix< Scalar, 6, 6 > MatrixType
Definition: RigidBodyInertia.h:50
rl::math::spatial::RigidBodyInertia::operator+
RigidBodyInertia operator+(const RigidBodyInertia &other) const
Definition: RigidBodyInertia.h:129
rl::math::spatial::RigidBodyInertia::inertia
ConstInertiaType & inertia() const
Definition: RigidBodyInertia.h:95
rl::math::spatial::RigidBodyInertia::operator=
RigidBodyInertia & operator=(const ::Eigen::MatrixBase< OtherDerived > &other)
Definition: RigidBodyInertia.h:121
rl::math::spatial::RigidBodyInertia::centerOfGravityData
CenterOfGravityType centerOfGravityData
Definition: RigidBodyInertia.h:187
rl::math::spatial::RigidBodyInertia
Definition: RigidBodyInertia.h:44
rl::math::spatial::RigidBodyInertia::operator-
RigidBodyInertia operator-(const RigidBodyInertia &other) const
Definition: RigidBodyInertia.h:138
rl::math::spatial::RigidBodyInertia::ConstMassType
const MassType ConstMassType
Definition: RigidBodyInertia.h:62
rl::math::spatial::RigidBodyInertia::RigidBodyInertia
RigidBodyInertia()
Definition: RigidBodyInertia.h:64
rl::math::spatial::RigidBodyInertia::ScalarType
Scalar ScalarType
Definition: RigidBodyInertia.h:48
rl::math::spatial::RigidBodyInertia::CenterOfGravityType
::Eigen::Matrix< Scalar, 3, 1 > CenterOfGravityType
Definition: RigidBodyInertia.h:52
rl::math::spatial::RigidBodyInertia::mass
MassType & mass()
Definition: RigidBodyInertia.h:100
rl::math::spatial::RigidBodyInertia::inertia
InertiaType & inertia()
Definition: RigidBodyInertia.h:90
rl::math::spatial::RigidBodyInertia::RigidBodyInertia
RigidBodyInertia(const ::Eigen::DenseBase< OtherDerived > &other)
Definition: RigidBodyInertia.h:69
rl::math::ForceVector
spatial::ForceVector< Real > ForceVector
Definition: Spatial.h:53
rl::math::spatial::RigidBodyInertia::ConstCenterOfGravityType
const CenterOfGravityType ConstCenterOfGravityType
Definition: RigidBodyInertia.h:54
rl::math::MotionVector
spatial::MotionVector< Real > MotionVector
Definition: Spatial.h:55
rl::math::spatial::RigidBodyInertia::InertiaType
::Eigen::Matrix< Scalar, 3, 3 > InertiaType
Definition: RigidBodyInertia.h:56
rl::math::spatial::RigidBodyInertia::setIdentity
void setIdentity()
Definition: RigidBodyInertia.h:170
rl::math::spatial::RigidBodyInertia::inertiaData
InertiaType inertiaData
Definition: RigidBodyInertia.h:189
rl::math::spatial::RigidBodyInertia::cog
CenterOfGravityType & cog()
Definition: RigidBodyInertia.h:80
rl::math::spatial::RigidBodyInertia::operator/
RigidBodyInertia operator/(const OtherScalar &other) const
Definition: RigidBodyInertia.h:161
rl::math::spatial::RigidBodyInertia::setZero
void setZero()
Definition: RigidBodyInertia.h:177
rl::math::spatial::RigidBodyInertia::ConstInertiaType
const InertiaType ConstInertiaType
Definition: RigidBodyInertia.h:58
rl::math::spatial::RigidBodyInertia::matrix
MatrixType matrix() const
Definition: RigidBodyInertia.h:110
rl::math::spatial::RigidBodyInertia::MassType
Scalar MassType
Definition: RigidBodyInertia.h:60
rl::math::spatial::ForceVector
Definition: ForceVector.h:43
cross3
Matrix< Scalar, 3, 1 > cross3() const
Definition: MatrixBaseAddons.h:31
rl::math::spatial::RigidBodyInertia::~RigidBodyInertia
virtual ~RigidBodyInertia()
Definition: RigidBodyInertia.h:76
rl::math::spatial::RigidBodyInertia::massData
MassType massData
Definition: RigidBodyInertia.h:191
rl::math::spatial::MotionVector
Definition: MotionVector.h:42
rl::math::spatial::RigidBodyInertia::mass
ConstMassType & mass() const
Definition: RigidBodyInertia.h:105
rl::math::spatial::RigidBodyInertia::cog
ConstCenterOfGravityType & cog() const
Definition: RigidBodyInertia.h:85
rl
Definition: Ati.cpp:35