pinocchio  UNKNOWN
force-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_force_dense_hpp__
19 #define __se3_force_dense_hpp__
20 
21 namespace se3
22 {
23 
24  namespace internal
25  {
26  template<typename Derived>
27  struct SE3GroupAction< ForceDense<Derived> >
28  {
29  typedef typename SE3GroupAction< Derived >::ReturnType ReturnType;
30  };
31 
32  template<typename Derived, typename MotionDerived>
33  struct MotionAlgebraAction< ForceDense<Derived>, MotionDerived >
34  {
35  typedef typename MotionAlgebraAction< Derived, MotionDerived >::ReturnType ReturnType;
36  };
37  }
38 
39  template<typename Derived>
40  class ForceDense : public ForceBase<Derived>
41  {
42  public:
43  typedef ForceBase<Derived> Base;
44  FORCE_TYPEDEF_TPL(Derived);
45  typedef typename traits<Derived>::ForceRefType ForceRefType;
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  template<typename D2>
56  bool isEqual_impl(const ForceDense<D2> & other) const
57  { return linear() == other.linear() && angular() == other.angular(); }
58 
59  template<typename D2>
60  bool isEqual_impl(const ForceBase<D2> & other) const
61  { return other.derived() == derived(); }
62 
63  // Arithmetic operators
64  template<typename D2>
65  Derived & operator=(const ForceDense<D2> & other)
66  {
67  linear() = other.linear();
68  angular() = other.angular();
69  return derived();
70  }
71 
72  template<typename V6>
73  Derived & operator=(const Eigen::MatrixBase<V6> & v)
74  {
75  EIGEN_STATIC_ASSERT_VECTOR_ONLY(V6); assert(v.size() == 6);
76  linear() = v.template segment<3>(LINEAR);
77  angular() = v.template segment<3>(ANGULAR);
78  return derived();
79  }
80 
81  ForcePlain operator-() const { return derived().__opposite__(); }
82  template<typename M1>
83  ForcePlain operator+(const ForceDense<M1> & v) const { return derived().__plus__(v.derived()); }
84  template<typename M1>
85  ForcePlain operator-(const ForceDense<M1> & v) const { return derived().__minus__(v.derived()); }
86 
87  template<typename M1>
88  Derived & operator+=(const ForceDense<M1> & v) { return derived().__pequ__(v.derived()); }
89  template<typename M1>
90  Derived & operator+=(const ForceBase<M1> & v)
91  { v.derived().addTo(derived()); return derived(); }
92 
93  template<typename M1>
94  Derived & operator-=(const ForceDense<M1> & v) { return derived().__mequ__(v.derived()); }
95 
96  ForcePlain __opposite__() const { return ForcePlain(-linear(),-angular()); }
97 
98  template<typename M1>
99  ForcePlain __plus__(const ForceDense<M1> & v) const
100  { return ForcePlain(linear()+v.linear(), angular()+v.angular()); }
101 
102  template<typename M1>
103  ForcePlain __minus__(const ForceDense<M1> & v) const
104  { return ForcePlain(linear()-v.linear(), angular()-v.angular()); }
105 
106  template<typename M1>
107  Derived & __pequ__(const ForceDense<M1> & v)
108  { linear() += v.linear(); angular() += v.angular(); return derived(); }
109 
110  template<typename M1>
111  Derived & __mequ__(const ForceDense<M1> & v)
112  { linear() -= v.linear(); angular() -= v.angular(); return derived(); }
113 
114  template<typename OtherScalar>
115  ForcePlain __mult__(const OtherScalar & alpha) const
116  { return ForcePlain(alpha*linear(),alpha*angular()); }
117 
118  template<typename OtherScalar>
119  ForcePlain __div__(const OtherScalar & alpha) const
120  { return derived().__mult__((OtherScalar)(1)/alpha); }
121 
122  template<typename F1>
123  Scalar dot(const MotionDense<F1> & phi) const
124  { return phi.linear().dot(linear()) + phi.angular().dot(angular()); }
125 
126  template<typename M1, typename M2>
127  void motionAction(const MotionDense<M1> & v, ForceDense<M2> & fout) const
128  {
129  fout.linear() = v.angular().cross(linear());
130  fout.angular() = v.angular().cross(angular())+v.linear().cross(linear());
131  }
132 
133  template<typename M1>
134  ForcePlain motionAction(const MotionDense<M1> & v) const
135  {
136  ForcePlain res;
137  motionAction(v,res);
138  return res;
139  }
140 
141  template<typename M2>
142  bool isApprox(const ForceDense<M2> & f, const Scalar & prec = Eigen::NumTraits<Scalar>::dummy_precision()) const
143  { return derived().isApprox_impl(f, prec);}
144 
145  template<typename D2>
146  bool isApprox_impl(const ForceDense<D2> & f, const Scalar & prec = Eigen::NumTraits<Scalar>::dummy_precision()) const
147  {
148  return linear().isApprox(f.linear(), prec) && angular().isApprox(f.angular(), prec);
149  }
150 
151  template<typename S2, int O2, typename D2>
152  void se3Action_impl(const SE3Tpl<S2,O2> & m, ForceDense<D2> & f) const
153  {
154  f.linear() = m.rotation()*linear();
155  f.angular() = m.rotation()*angular() + m.translation().cross(f.linear());
156  }
157 
158  template<typename S2, int O2>
159  ForcePlain se3Action_impl(const SE3Tpl<S2,O2> & m) const
160  {
161  ForcePlain res;
162  se3Action_impl(m,res);
163  return res;
164  }
165 
166  template<typename S2, int O2, typename D2>
167  void se3ActionInverse_impl(const SE3Tpl<S2,O2> & m, ForceDense<D2> & f) const
168  {
169  f.linear() = angular()-m.translation().cross(linear());
170  f.angular() = m.rotation().transpose()*(f.linear());
171  f.linear() = m.rotation().transpose()*linear();
172  }
173 
174  template<typename S2, int O2>
175  ForcePlain se3ActionInverse_impl(const SE3Tpl<S2,O2> & m) const
176  {
177  ForcePlain res;
178  se3ActionInverse_impl(m,res);
179  return res;
180  }
181 
182  void disp_impl(std::ostream & os) const
183  {
184  os
185  << " f = " << linear().transpose () << std::endl
186  << "tau = " << angular().transpose () << std::endl;
187  }
188 
190  ForceRefType ref() { return derived().ref(); }
191 
192  }; // class ForceDense
193 
195  template<typename F1>
196  typename traits<F1>::ForcePlain operator*(const typename traits<F1>::Scalar alpha,
197  const ForceDense<F1> & f)
198  { return f.derived()*alpha; }
199 
200 } // namespace se3
201 
202 #endif // ifndef __se3_force_dense_hpp__
ForceRefType ref()
ConstAngularType angular() const
Return the angular part of the force vector.
Definition: force-base.hpp:53
ConstLinearType linear() const
Return the linear part of the force vector.
Definition: force-base.hpp:60
Base interface for forces representation.
Definition: force-base.hpp:40