Robotics Library  0.7.0
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 
45  template<typename Scalar>
47  {
48  public:
49  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
50 
51  typedef Scalar ScalarType;
52 
53  typedef ::Eigen::Matrix<Scalar, 6, 6> MatrixType;
54 
55  typedef ::Eigen::Matrix<Scalar, 3, 1> CenterOfGravityType;
56 
58 
59  typedef ::Eigen::Matrix<Scalar, 3, 3> InertiaType;
60 
62 
63  typedef Scalar MassType;
64 
65  typedef const MassType ConstMassType;
66 
68  {
69  }
70 
71  template<typename OtherDerived>
72  RigidBodyInertia(const ::Eigen::DenseBase<OtherDerived>& other) :
73  centerOfGravityData(other.template topRightCorner<3, 3>().cross3()),
74  inertiaData(other.template topLeftCorner<3, 3>()),
75  massData(other.template bottomRightCorner<3, 3>().diagonal().mean())
76  {
77  }
78 
80  {
81  }
82 
84  {
85  return centerOfGravityData;
86  }
87 
89  {
90  return centerOfGravityData;
91  }
92 
94  {
95  return inertiaData;
96  }
97 
99  {
100  return inertiaData;
101  }
102 
104  {
105  return massData;
106  }
107 
109  {
110  return massData;
111  }
112 
114  {
115  MatrixType res;
116  res.template topLeftCorner<3, 3>() = inertia();
117  res.template topRightCorner<3, 3>() = cog().cross33();
118  res.template bottomLeftCorner<3, 3>() = -cog().cross33();
119  res.template bottomRightCorner<3, 3>() = ::Eigen::Matrix<Scalar, 3, 3>::Identity() * mass();
120  return res;
121  }
122 
123  template<typename OtherDerived>
124  RigidBodyInertia& operator=(const ::Eigen::MatrixBase<OtherDerived>& other)
125  {
126  cog() = other.template topRightCorner<3, 3>().cross3();
127  inertia() = other.template topLeftCorner<3, 3>();
128  mass() = other.template bottomRightCorner<3, 3>().diagonal().mean();
129  return *this;
130  }
131 
133  {
134  RigidBodyInertia res;
135  res.cog() = cog() + other.cog();
136  res.inertia() = inertia() + other.inertia();
137  res.mass() = mass() + other.mass();
138  return res;
139  }
140 
142  {
143  RigidBodyInertia res;
144  res.cog() = cog() - other.cog();
145  res.inertia() = inertia() - other.inertia();
146  res.mass() = mass() - other.mass();
147  return res;
148  }
149 
150  template<typename OtherScalar>
151  RigidBodyInertia operator*(const OtherScalar& other) const
152  {
153  RigidBodyInertia res;
154  res.cog() = cog() * other;
155  res.inertia() = inertia() * other;
156  res.mass() = mass() * other;
157  return res;
158  }
159 
160  template<typename OtherScalar>
162 
163  template<typename OtherScalar>
164  RigidBodyInertia operator/(const OtherScalar& other) const
165  {
166  RigidBodyInertia res;
167  res.cog() = cog() / other;
168  res.inertia() = inertia() / other;
169  res.mass() = mass() / other;
170  return res;
171  }
172 
173  void setIdentity()
174  {
175  cog().setZero();
176  inertia().setIdentity();
177  mass() = 1;
178  }
179 
180  void setZero()
181  {
182  cog().setZero();
183  inertia().setZero();
184  mass() = 0;
185  }
186 
187  protected:
188 
189  private:
191 
193 
195  };
196  }
197  }
198 }
199 
200 #endif // RL_MATH_RIGIDBODYINERTIA_H
rl::math::spatial::RigidBodyInertia::CenterOfGravityType
::Eigen::Matrix< Scalar, 3, 1 > CenterOfGravityType
Definition: RigidBodyInertia.h:55
rl::math::spatial::RigidBodyInertia::operator*
RigidBodyInertia operator*(const OtherScalar &other) const
Definition: RigidBodyInertia.h:151
rl::math::spatial::RigidBodyInertia::operator+
RigidBodyInertia operator+(const RigidBodyInertia &other) const
Definition: RigidBodyInertia.h:132
rl::math::spatial::RigidBodyInertia::inertia
ConstInertiaType & inertia() const
Definition: RigidBodyInertia.h:98
rl::math::spatial::RigidBodyInertia::operator=
RigidBodyInertia & operator=(const ::Eigen::MatrixBase< OtherDerived > &other)
Definition: RigidBodyInertia.h:124
rl::math::spatial::RigidBodyInertia::centerOfGravityData
CenterOfGravityType centerOfGravityData
Definition: RigidBodyInertia.h:190
rl::math::spatial::RigidBodyInertia
Rigid-body inertia.
Definition: RigidBodyInertia.h:47
rl::math::spatial::RigidBodyInertia::operator-
RigidBodyInertia operator-(const RigidBodyInertia &other) const
Definition: RigidBodyInertia.h:141
rl::math::spatial::RigidBodyInertia::ConstMassType
const MassType ConstMassType
Definition: RigidBodyInertia.h:65
rl::math::spatial::RigidBodyInertia::RigidBodyInertia
RigidBodyInertia()
Definition: RigidBodyInertia.h:67
rl::math::spatial::RigidBodyInertia::ScalarType
Scalar ScalarType
Definition: RigidBodyInertia.h:51
rl::math::MotionVector
spatial::MotionVector< Real > MotionVector
Definition: Spatial.h:56
rl::math::spatial::RigidBodyInertia::mass
MassType & mass()
Definition: RigidBodyInertia.h:103
rl::math::spatial::RigidBodyInertia::inertia
InertiaType & inertia()
Definition: RigidBodyInertia.h:93
rl::math::spatial::RigidBodyInertia::RigidBodyInertia
RigidBodyInertia(const ::Eigen::DenseBase< OtherDerived > &other)
Definition: RigidBodyInertia.h:72
rl::math::spatial::RigidBodyInertia::ConstCenterOfGravityType
const CenterOfGravityType ConstCenterOfGravityType
Definition: RigidBodyInertia.h:57
rl::math::spatial::RigidBodyInertia::setIdentity
void setIdentity()
Definition: RigidBodyInertia.h:173
rl::math::spatial::RigidBodyInertia::inertiaData
InertiaType inertiaData
Definition: RigidBodyInertia.h:192
rl::math::spatial::RigidBodyInertia::MatrixType
::Eigen::Matrix< Scalar, 6, 6 > MatrixType
Definition: RigidBodyInertia.h:53
rl::math::ForceVector
spatial::ForceVector< Real > ForceVector
Definition: Spatial.h:54
rl::math::spatial::RigidBodyInertia::cog
CenterOfGravityType & cog()
Definition: RigidBodyInertia.h:83
rl::math::spatial::RigidBodyInertia::operator/
RigidBodyInertia operator/(const OtherScalar &other) const
Definition: RigidBodyInertia.h:164
rl::math::spatial::RigidBodyInertia::setZero
void setZero()
Definition: RigidBodyInertia.h:180
rl::math::spatial::RigidBodyInertia::ConstInertiaType
const InertiaType ConstInertiaType
Definition: RigidBodyInertia.h:61
rl::math::spatial::RigidBodyInertia::matrix
MatrixType matrix() const
Definition: RigidBodyInertia.h:113
rl::math::spatial::RigidBodyInertia::MassType
Scalar MassType
Definition: RigidBodyInertia.h:63
rl::math::spatial::ForceVector
Force vector.
Definition: ForceVector.h:46
rl::math::spatial::RigidBodyInertia::~RigidBodyInertia
virtual ~RigidBodyInertia()
Definition: RigidBodyInertia.h:79
rl::math::spatial::RigidBodyInertia::massData
MassType massData
Definition: RigidBodyInertia.h:194
rl::math::spatial::MotionVector
Motion vector.
Definition: MotionVector.h:45
cross3
Matrix< Scalar, 3, 1 > cross3() const
Definition: MatrixBaseAddons.h:31
rl::math::spatial::RigidBodyInertia::mass
ConstMassType & mass() const
Definition: RigidBodyInertia.h:108
rl::math::spatial::RigidBodyInertia::cog
ConstCenterOfGravityType & cog() const
Definition: RigidBodyInertia.h:88
rl::math::spatial::RigidBodyInertia::InertiaType
::Eigen::Matrix< Scalar, 3, 3 > InertiaType
Definition: RigidBodyInertia.h:59
rl
Robotics Library.
Definition: AnalogInput.cpp:30