pinocchio  UNKNOWN
motion-dense.hpp
1 //
2 // Copyright (c) 2017-2018 CNRS
3 //
4 // This file is part of Pinocchio
5 // Pinocchio is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // Pinocchio is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // Pinocchio If not, see
16 // <http://www.gnu.org/licenses/>.
17 
18 #ifndef __se3_motion_dense_hpp__
19 #define __se3_motion_dense_hpp__
20 
21 namespace se3
22 {
23 
24  namespace internal
25  {
26  template<typename Derived>
27  struct SE3GroupAction< MotionDense<Derived> >
28  {
29  typedef typename SE3GroupAction< Derived >::ReturnType ReturnType;
30  };
31 
32  template<typename Derived, typename MotionDerived>
33  struct MotionAlgebraAction< MotionDense<Derived>, MotionDerived >
34  {
35  typedef typename MotionAlgebraAction< Derived, MotionDerived >::ReturnType ReturnType;
36  };
37  }
38 
39  template<typename Derived>
40  class MotionDense : public MotionBase<Derived>
41  {
42  public:
43  typedef MotionBase<Derived> Base;
44  MOTION_TYPEDEF_TPL(Derived);
45  typedef typename traits<Derived>::MotionRefType MotionRefType;
46 
47  using Base::linear;
48  using Base::angular;
49  using Base::derived;
50  using Base::isApprox;
51 
52  Derived & setZero() { linear().setZero(); angular().setZero(); return derived(); }
53  Derived & setRandom() { linear().setZero(); angular().setZero(); return derived(); }
54 
55  ActionMatrixType toActionMatrix_impl() const
56  {
57  ActionMatrixType X;
58  X.template block <3,3> (ANGULAR, ANGULAR) = X.template block <3,3> (LINEAR, LINEAR) = skew(angular());
59  X.template block <3,3> (LINEAR, ANGULAR) = skew(linear());
60  X.template block <3,3> (ANGULAR, LINEAR).setZero();
61 
62  return X;
63  }
64 
65  ActionMatrixType toDualActionMatrix_impl() const
66  {
67  ActionMatrixType X;
68  X.template block <3,3> (ANGULAR, ANGULAR) = X.template block <3,3> (LINEAR, LINEAR) = skew(angular());
69  X.template block <3,3> (ANGULAR, LINEAR) = skew(linear());
70  X.template block <3,3> (LINEAR, ANGULAR).setZero();
71 
72  return X;
73  }
74 
75  template<typename D2>
76  bool isEqual_impl(const MotionDense<D2> & other) const
77  { return linear() == other.linear() && angular() == other.angular(); }
78 
79  template<typename D2>
80  bool isEqual_impl(const MotionBase<D2> & other) const
81  { return other.derived() == derived(); }
82 
83  // Arithmetic operators
84  template<typename D2>
85  Derived & operator=(const MotionDense<D2> & other)
86  {
87  linear() = other.linear();
88  angular() = other.angular();
89  return derived();
90  }
91 
92  template<typename V6>
93  Derived & operator=(const Eigen::MatrixBase<V6> & v)
94  {
95  EIGEN_STATIC_ASSERT_VECTOR_ONLY(V6); assert(v.size() == 6);
96  linear() = v.template segment<3>(LINEAR);
97  angular() = v.template segment<3>(ANGULAR);
98  return derived();
99  }
100 
101  MotionPlain operator-() const { return derived().__opposite__(); }
102  template<typename M1>
103  MotionPlain operator+(const MotionDense<M1> & v) const { return derived().__plus__(v.derived()); }
104  template<typename M1>
105  MotionPlain operator-(const MotionDense<M1> & v) const { return derived().__minus__(v.derived()); }
106 
107  template<typename M1>
108  Derived & operator+=(const MotionDense<M1> & v) { return derived().__pequ__(v.derived()); }
109  template<typename M1>
110  Derived & operator+=(const MotionBase<M1> & v)
111  { v.derived().addTo(derived()); return derived(); }
112 
113  template<typename M1>
114  Derived & operator-=(const MotionDense<M1> & v) { return derived().__mequ__(v.derived()); }
115 
116  MotionPlain __opposite__() const { return MotionPlain(-linear(),-angular()); }
117 
118  template<typename M1>
119  MotionPlain __plus__(const MotionDense<M1> & v) const
120  { return MotionPlain(linear()+v.linear(), angular()+v.angular()); }
121 
122  template<typename M1>
123  MotionPlain __minus__(const MotionDense<M1> & v) const
124  { return MotionPlain(linear()-v.linear(), angular()-v.angular()); }
125 
126  template<typename M1>
127  Derived & __pequ__(const MotionDense<M1> & v)
128  { linear() += v.linear(); angular() += v.angular(); return derived(); }
129 
130  template<typename M1>
131  Derived & __mequ__(const MotionDense<M1> & v)
132  { linear() -= v.linear(); angular() -= v.angular(); return derived(); }
133 
134  template<typename OtherScalar>
135  MotionPlain __mult__(const OtherScalar & alpha) const
136  { return MotionPlain(alpha*linear(),alpha*angular()); }
137 
138  template<typename OtherScalar>
139  MotionPlain __div__(const OtherScalar & alpha) const
140  { return derived().__mult__((OtherScalar)(1)/alpha); }
141 
142  template<typename F1>
143  Scalar dot(const ForceBase<F1> & phi) const
144  { return phi.linear().dot(linear()) + phi.angular().dot(angular()); }
145 
146  template<typename D>
147  typename internal::MotionAlgebraAction<D,Derived>::ReturnType cross_impl(const D & d) const
148  {
149  return d.motionAction(derived());
150  }
151 
152  template<typename M1, typename M2>
153  void motionAction(const MotionDense<M1> & v, MotionDense<M2> & mout) const
154  {
155  mout.linear() = v.linear().cross(angular())+v.angular().cross(linear());
156  mout.angular() = v.angular().cross(angular());
157  }
158 
159  template<typename M1>
160  MotionPlain motionAction(const MotionDense<M1> & v) const
161  {
162  MotionPlain res;
163  motionAction(v,res);
164  return res;
165  }
166 
167  template<typename M2>
168  bool isApprox(const MotionDense<M2> & m2, const Scalar & prec = Eigen::NumTraits<Scalar>::dummy_precision()) const
169  { return derived().isApprox_impl(m2, prec);}
170 
171  template<typename D2>
172  bool isApprox_impl(const MotionDense<D2> & m2, const Scalar & prec = Eigen::NumTraits<Scalar>::dummy_precision()) const
173  {
174  return linear().isApprox(m2.linear(), prec) && angular().isApprox(m2.angular(), prec);
175  }
176 
177  template<typename S2, int O2, typename D2>
178  void se3Action_impl(const SE3Tpl<S2,O2> & m, MotionDense<D2> & v) const
179  {
180  v.angular() = m.rotation()*angular();
181  v.linear() = m.rotation()*linear() + m.translation().cross(v.angular());
182  }
183 
184  template<typename S2, int O2>
185  MotionPlain se3Action_impl(const SE3Tpl<S2,O2> & m) const
186  {
187  MotionPlain res;
188  se3Action_impl(m,res);
189  return res;
190  }
191 
192  template<typename S2, int O2, typename D2>
193  void se3ActionInverse_impl(const SE3Tpl<S2,O2> & m, MotionDense<D2> & v) const
194  {
195  v.linear() = m.rotation().transpose()*(linear()-m.translation().cross(angular()));
196  v.angular() = m.rotation().transpose()*angular();
197  }
198 
199  template<typename S2, int O2>
200  MotionPlain se3ActionInverse_impl(const SE3Tpl<S2,O2> & m) const
201  {
202  MotionPlain res;
203  se3ActionInverse_impl(m,res);
204  return res;
205  }
206 
207  void disp_impl(std::ostream & os) const
208  {
209  os
210  << " v = " << linear().transpose () << std::endl
211  << " w = " << angular().transpose () << std::endl;
212  }
213 
215  MotionRefType ref() { return derived().ref(); }
216 
217  }; // class MotionDense
218 
220  template<typename M1, typename M2>
221  typename traits<M1>::MotionPlain operator^(const MotionDense<M1> & v1,
222  const MotionDense<M2> & v2)
223  { return v1.derived().cross(v2.derived()); }
224 
225  template<typename M1, typename F1>
226  typename traits<F1>::ForcePlain operator^(const MotionDense<M1> & v,
227  const ForceBase<F1> & f)
228  { return v.derived().cross(f.derived()); }
229 
230  template<typename M1>
231  typename traits<M1>::MotionPlain operator*(const typename traits<M1>::Scalar alpha,
232  const MotionDense<M1> & v)
233  { return v*alpha; }
234 
235 } // namespace se3
236 
237 #endif // ifndef __se3_motion_dense_hpp__
MotionRefType ref()
void skew(const Eigen::MatrixBase< Vector3 > &v, const Eigen::MatrixBase< Matrix3 > &M)
Computes the skew representation of a given 3d vector, i.e. the antisymmetric matrix representation o...
Definition: skew.hpp:34
Base interface for forces representation.
Definition: force-base.hpp:40