pinocchio  UNKNOWN
force-tpl.hpp
1 //
2 // Copyright (c) 2015-2018 CNRS
3 // Copyright (c) 2015-2016 Wandercraft, 86 rue de Paris 91400 Orsay, France.
4 //
5 // This file is part of Pinocchio
6 // Pinocchio is free software: you can redistribute it
7 // and/or modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation, either version
9 // 3 of the License, or (at your option) any later version.
10 //
11 // Pinocchio is distributed in the hope that it will be
12 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Lesser Public License for more details. You should have
15 // received a copy of the GNU Lesser General Public License along with
16 // Pinocchio If not, see
17 // <http://www.gnu.org/licenses/>.
18 
19 #ifndef __se3_force_tpl_hpp__
20 #define __se3_force_tpl_hpp__
21 
22 namespace se3
23 {
24  template<typename _Scalar, int _Options>
25  struct traits< ForceTpl<_Scalar, _Options> >
26  {
27  typedef _Scalar Scalar;
28  typedef Eigen::Matrix<Scalar,3,1,_Options> Vector3;
29  typedef Eigen::Matrix<Scalar,6,1,_Options> Vector6;
30  typedef Eigen::Matrix<Scalar,6,6,_Options> Matrix6;
31  typedef typename EIGEN_REF_CONSTTYPE(Vector6) ToVectorConstReturnType;
32  typedef typename EIGEN_REF_TYPE(Vector6) ToVectorReturnType;
33  typedef typename Vector6::template FixedSegmentReturnType<3>::Type LinearType;
34  typedef typename Vector6::template FixedSegmentReturnType<3>::Type AngularType;
35  typedef typename Vector6::template ConstFixedSegmentReturnType<3>::Type ConstLinearType;
36  typedef typename Vector6::template ConstFixedSegmentReturnType<3>::Type ConstAngularType;
38  enum {
39  LINEAR = 0,
40  ANGULAR = 3,
41  Options = _Options
42  };
43 
45  }; // traits ForceTpl
46 
47  template<typename _Scalar, int _Options>
48  class ForceTpl : public ForceDense< ForceTpl<_Scalar, _Options> >
49  {
50  public:
51  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
52  typedef ForceDense<ForceTpl> Base;
53  FORCE_TYPEDEF_TPL(ForceTpl);
54 
55  using Base::operator=;
56  using Base::linear;
57  using Base::angular;
58 
59  // Constructors
60  ForceTpl() : data() {}
61 
62  template<typename V1,typename V2>
63  ForceTpl(const Eigen::MatrixBase<V1> & v, const Eigen::MatrixBase<V2> & w)
64  {
65  assert(v.size() == 3);
66  assert(w.size() == 3);
67  data << v, w;
68  }
69 
70  template<typename V6>
71  explicit ForceTpl(const Eigen::MatrixBase<V6> & v)
72  : data(v)
73  {
74  EIGEN_STATIC_ASSERT_VECTOR_ONLY(V6);
75  assert(v.size() == 6);
76  }
77 
78  template<typename S2,int O2>
79  explicit ForceTpl(const ForceTpl<S2,O2> & clone)
80  : data(clone.toVector())
81  {}
82 
83  template<typename M2>
84  explicit ForceTpl(const ForceDense<M2> & clone)
85  { linear() = clone.linear(); angular() = clone.angular(); }
86 
87  // initializers
88  static ForceTpl Zero() { return ForceTpl(Vector6::Zero()); }
89  static ForceTpl Random() { return ForceTpl(Vector6::Random()); }
90 
91  ToVectorConstReturnType toVector_impl() const { return data; }
92  ToVectorReturnType toVector_impl() { return data; }
93 
94  // Getters
95  ConstAngularType angular_impl() const { return data.template segment<3> (ANGULAR); }
96  ConstLinearType linear_impl() const { return data.template segment<3> (LINEAR); }
97  AngularType angular_impl() { return data.template segment<3> (ANGULAR); }
98  LinearType linear_impl() { return data.template segment<3> (LINEAR); }
99 
100  template<typename V3>
101  void angular_impl(const Eigen::MatrixBase<V3> & w)
102  {
103  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3,3);
104  angular_impl()=w;
105  }
106  template<typename V3>
107  void linear_impl(const Eigen::MatrixBase<V3> & v)
108  {
109  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3,3);
110  linear_impl()=v;
111  }
112 
113  ForceRef<Vector6> ref() { return ForceRef<Vector6>(data); }
114 
115  protected:
116  Vector6 data;
117 
118  }; // class ForceTpl
119 
120 } // namespace se3
121 
122 #endif // ifndef __se3_force_tpl_hpp__
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
ToVectorConstReturnType toVector() const
Return the force as an Eigen vector.
Definition: force-base.hpp:99