Robotics Library  0.7.0
MotionVector.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_MOTIONVECTOR_H
28 #define RL_MATH_MOTIONVECTOR_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 
43  template<typename Scalar>
45  {
46  public:
47  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
48 
49  typedef Scalar ScalarType;
50 
51  typedef typename ::Eigen::Matrix<Scalar, 6, 1> MatrixType;
52 
53  typedef const MatrixType ConstMatrixType;
54 
55  typedef ::Eigen::Block<MatrixType, 3, 1> AngularType;
56 
57  typedef const ::Eigen::Block<ConstMatrixType, 3, 1> ConstAngularType;
58 
59  typedef ::Eigen::Block<MatrixType, 3, 1> LinearType;
60 
61  typedef const ::Eigen::Block<ConstMatrixType, 3, 1> ConstLinearType;
62 
64  {
65  }
66 
67  template<typename OtherDerived>
68  MotionVector(const ::Eigen::MatrixBase<OtherDerived>& other) :
69  data(other)
70  {
71  }
72 
73  virtual ~MotionVector()
74  {
75  }
76 
78  {
79  return data.template segment<3>(0);
80  }
81 
83  {
84  return data.template segment<3>(0);
85  }
86 
87  template<typename OtherScalar>
89 
90  MotionVector cross(const MotionVector& other) const
91  {
92  MotionVector res;
93  res.angular() = angular().cross(other.angular());
94  res.linear() = angular().cross(other.linear()) + linear().cross(other.angular());
95  return res;
96  }
97 
98  template<typename OtherScalar>
99  Scalar dot(const ForceVector<OtherScalar>& other) const;
100 
102  {
103  return data.template segment<3>(3);
104  }
105 
107  {
108  return data.template segment<3>(3);
109  }
110 
112  {
113  return data;
114  }
115 
116  template<typename OtherDerived>
117  MotionVector& operator=(const ::Eigen::MatrixBase<OtherDerived>& other)
118  {
119  data = other;
120  return *this;
121  }
122 
123  MotionVector operator+(const MotionVector& other) const
124  {
125  MotionVector res;
126  res.angular() = angular() + other.angular();
127  res.linear() = linear() + other.linear();
128  return res;
129  }
130 
131  MotionVector operator-(const MotionVector& other) const
132  {
133  MotionVector res;
134  res.angular() = angular() - other.angular();
135  res.linear() = linear() - other.linear();
136  return res;
137  }
138 
139  template<typename OtherScalar>
140  MotionVector operator*(const OtherScalar& other) const
141  {
142  MotionVector res;
143  res.angular() = angular() * other;
144  res.linear() = linear() * other;
145  return res;
146  }
147 
148  template<typename OtherScalar>
149  MotionVector operator/(const OtherScalar& other) const
150  {
151  MotionVector res;
152  res.angular() = angular() / other;
153  res.linear() = linear() / other;
154  return res;
155  }
156 
157  void setZero()
158  {
159  angular().setZero();
160  linear().setZero();
161  }
162 
163  protected:
164 
165  private:
167  };
168  }
169  }
170 }
171 
172 #endif // RL_MATH_MOTIONVECTOR_H
rl::math::spatial::MotionVector::operator-
MotionVector operator-(const MotionVector &other) const
Definition: MotionVector.h:131
rl::math::spatial::MotionVector::ConstMatrixType
const MatrixType ConstMatrixType
Definition: MotionVector.h:53
rl::math::spatial::MotionVector::dot
Scalar dot(const ForceVector< OtherScalar > &other) const
Definition: MotionVector.hxx:52
rl::math::spatial::MotionVector::linear
LinearType linear()
Definition: MotionVector.h:101
rl::math::spatial::MotionVector::AngularType
::Eigen::Block< MatrixType, 3, 1 > AngularType
Definition: MotionVector.h:55
rl::math::spatial::MotionVector::cross
ForceVector< OtherScalar > cross(const ForceVector< OtherScalar > &other) const
Definition: MotionVector.hxx:40
rl::math::spatial::MotionVector::operator=
MotionVector & operator=(const ::Eigen::MatrixBase< OtherDerived > &other)
Definition: MotionVector.h:117
rl::math::spatial::MotionVector::ScalarType
Scalar ScalarType
Definition: MotionVector.h:49
rl::math::spatial::MotionVector::cross
MotionVector cross(const MotionVector &other) const
Definition: MotionVector.h:90
rl::math::spatial::MotionVector::data
MatrixType data
Definition: MotionVector.h:166
rl::math::spatial::MotionVector::angular
ConstAngularType angular() const
Definition: MotionVector.h:82
rl::math::spatial::MotionVector::operator+
MotionVector operator+(const MotionVector &other) const
Definition: MotionVector.h:123
rl::math::spatial::MotionVector::linear
ConstLinearType linear() const
Definition: MotionVector.h:106
rl::math::spatial::MotionVector::angular
AngularType angular()
Definition: MotionVector.h:77
rl::math::spatial::MotionVector::ConstLinearType
const ::Eigen::Block< ConstMatrixType, 3, 1 > ConstLinearType
Definition: MotionVector.h:61
rl::math::spatial::MotionVector::operator/
MotionVector operator/(const OtherScalar &other) const
Definition: MotionVector.h:149
rl::math::spatial::MotionVector::MotionVector
MotionVector()
Definition: MotionVector.h:63
rl::math::spatial::MotionVector::setZero
void setZero()
Definition: MotionVector.h:157
rl::math::ForceVector
spatial::ForceVector< Real > ForceVector
Definition: Spatial.h:54
rl::math::spatial::MotionVector::MotionVector
MotionVector(const ::Eigen::MatrixBase< OtherDerived > &other)
Definition: MotionVector.h:68
rl::math::spatial::MotionVector::operator*
MotionVector operator*(const OtherScalar &other) const
Definition: MotionVector.h:140
rl::math::spatial::MotionVector::LinearType
::Eigen::Block< MatrixType, 3, 1 > LinearType
Definition: MotionVector.h:59
rl::math::spatial::MotionVector::~MotionVector
virtual ~MotionVector()
Definition: MotionVector.h:73
rl::math::spatial::ForceVector
Force vector.
Definition: ForceVector.h:46
rl::math::spatial::MotionVector::matrix
ConstMatrixType & matrix() const
Definition: MotionVector.h:111
rl::math::spatial::MotionVector::ConstAngularType
const ::Eigen::Block< ConstMatrixType, 3, 1 > ConstAngularType
Definition: MotionVector.h:57
rl::math::spatial::MotionVector
Motion vector.
Definition: MotionVector.h:45
rl::math::spatial::MotionVector::MatrixType
::Eigen::Matrix< Scalar, 6, 1 > MatrixType
Definition: MotionVector.h:51
rl
Robotics Library.
Definition: AnalogInput.cpp:30