Robotics Library  0.6.2
ForceVector.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_FORCEVECTOR_H_
28 #define _RL_MATH_FORCEVECTOR_H_
29 
30 #include <Eigen/Core>
31 
32 namespace rl
33 {
34  namespace math
35  {
36  namespace spatial
37  {
38  template< typename Scalar > class ArticulatedBodyInertia;
39  template< typename Scalar > class MotionVector;
40 
41  template< typename Scalar >
43  {
44  public:
45  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
46 
47  typedef Scalar ScalarType;
48 
49  typedef typename ::Eigen::Matrix< Scalar, 6, 1 > MatrixType;
50 
51  typedef const MatrixType ConstMatrixType;
52 
53  typedef ::Eigen::Block< MatrixType, 3, 1 > MomentType;
54 
55  typedef const ::Eigen::Block< ConstMatrixType, 3, 1 > ConstMomentType;
56 
57  typedef ::Eigen::Block< MatrixType, 3, 1 > ForceType;
58 
59  typedef const ::Eigen::Block< ConstMatrixType, 3, 1 > ConstForceType;
60 
62  {
63  }
64 
65  template< typename OtherDerived >
66  ForceVector(const ::Eigen::MatrixBase< OtherDerived >& other) :
67  data(other)
68  {
69  }
70 
71  virtual ~ForceVector()
72  {
73  }
74 
75  template< typename OtherScalar >
76  Scalar dot(const MotionVector< OtherScalar >& other) const;
77 
79  {
80  return data.template segment< 3 >(3);
81  }
82 
84  {
85  return data.template segment< 3 >(3);
86  }
87 
89  {
90  return data;
91  }
92 
94  {
95  return data.template segment< 3 >(0);
96  }
97 
99  {
100  return data.template segment< 3 >(0);
101  }
102 
103  template< typename OtherDerived >
104  ForceVector& operator=(const ::Eigen::MatrixBase< OtherDerived >& other)
105  {
106  data = other;
107  return *this;
108  }
109 
110  ForceVector operator+(const ForceVector& other) const
111  {
112  ForceVector res;
113  res.moment() = moment() + other.moment();
114  res.force() = force() + other.force();
115  return res;
116  }
117 
118  ForceVector operator-(const ForceVector& other) const
119  {
120  ForceVector res;
121  res.moment() = moment() - other.moment();
122  res.force() = force() - other.force();
123  return res;
124  }
125 
126  template< typename OtherScalar >
127  ForceVector operator*(const OtherScalar& other) const
128  {
129  ForceVector res;
130  res.moment() = moment() * other;
131  res.force() = force() * other;
132  return res;
133  }
134 
135  template< typename OtherScalar >
136  ForceVector operator/(const OtherScalar& other) const
137  {
138  ForceVector res;
139  res.moment() = moment() / other;
140  res.force() = force() / other;
141  return res;
142  }
143 
145 
146  void setZero()
147  {
148  moment().setZero();
149  force().setZero();
150  }
151 
152  protected:
153 
154  private:
156  };
157  }
158  }
159 }
160 
161 #endif // _RL_MATH_FORCEVECTOR_H_
rl::math::spatial::ArticulatedBodyInertia
Definition: ArticulatedBodyInertia.h:44
rl::math::spatial::ForceVector::operator*
ArticulatedBodyInertia< Scalar > operator*(const ForceVector &other) const
rl::math::spatial::ForceVector::ForceType
::Eigen::Block< MatrixType, 3, 1 > ForceType
Definition: ForceVector.h:57
rl::math::spatial::ForceVector::moment
ConstMomentType moment() const
Definition: ForceVector.h:98
rl::math::spatial::ForceVector::ForceVector
ForceVector(const ::Eigen::MatrixBase< OtherDerived > &other)
Definition: ForceVector.h:66
rl::math::spatial::ForceVector::operator*
ForceVector operator*(const OtherScalar &other) const
Definition: ForceVector.h:127
rl::math::spatial::ForceVector::operator+
ForceVector operator+(const ForceVector &other) const
Definition: ForceVector.h:110
rl::math::spatial::ForceVector::MomentType
::Eigen::Block< MatrixType, 3, 1 > MomentType
Definition: ForceVector.h:53
rl::math::spatial::ForceVector::operator=
ForceVector & operator=(const ::Eigen::MatrixBase< OtherDerived > &other)
Definition: ForceVector.h:104
rl::math::spatial::ForceVector::MatrixType
::Eigen::Matrix< Scalar, 6, 1 > MatrixType
Definition: ForceVector.h:49
rl::math::spatial::ForceVector::ConstForceType
const ::Eigen::Block< ConstMatrixType, 3, 1 > ConstForceType
Definition: ForceVector.h:59
rl::math::spatial::ForceVector::matrix
ConstMatrixType & matrix() const
Definition: ForceVector.h:88
rl::math::spatial::ForceVector::dot
Scalar dot(const MotionVector< OtherScalar > &other) const
Definition: ForceVector.hxx:40
rl::math::spatial::ForceVector::ConstMomentType
const ::Eigen::Block< ConstMatrixType, 3, 1 > ConstMomentType
Definition: ForceVector.h:55
rl::math::spatial::ForceVector::force
ForceType force()
Definition: ForceVector.h:78
rl::math::MotionVector
spatial::MotionVector< Real > MotionVector
Definition: Spatial.h:55
rl::math::spatial::ForceVector::ScalarType
Scalar ScalarType
Definition: ForceVector.h:47
rl::math::spatial::ForceVector::data
MatrixType data
Definition: ForceVector.h:155
rl::math::spatial::ForceVector::ConstMatrixType
const MatrixType ConstMatrixType
Definition: ForceVector.h:51
rl::math::spatial::ForceVector::operator/
ForceVector operator/(const OtherScalar &other) const
Definition: ForceVector.h:136
rl::math::ArticulatedBodyInertia
spatial::ArticulatedBodyInertia< Real > ArticulatedBodyInertia
Definition: Spatial.h:51
rl::math::spatial::ForceVector
Definition: ForceVector.h:43
rl::math::spatial::ForceVector::~ForceVector
virtual ~ForceVector()
Definition: ForceVector.h:71
rl::math::spatial::MotionVector
Definition: MotionVector.h:42
rl::math::spatial::ForceVector::moment
MomentType moment()
Definition: ForceVector.h:93
rl::math::spatial::ForceVector::ForceVector
ForceVector()
Definition: ForceVector.h:61
rl::math::spatial::ForceVector::operator-
ForceVector operator-(const ForceVector &other) const
Definition: ForceVector.h:118
rl::math::spatial::ForceVector::setZero
void setZero()
Definition: ForceVector.h:146
rl::math::spatial::ForceVector::force
ConstForceType force() const
Definition: ForceVector.h:83
rl
Definition: Ati.cpp:35