pinocchio  UNKNOWN
All Classes Namespaces Functions Variables Typedefs Enumerations Modules Pages
force-set.hpp
1 //
2 // Copyright (c) 2015 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_set_hpp__
19 #define __se3_force_set_hpp__
20 
21 #include <Eigen/Core>
22 #include <Eigen/Geometry>
23 #include "pinocchio/spatial/fwd.hpp"
24 
25 namespace se3
26 {
27  template<typename _Scalar, int _Options>
29  {
30  public:
31  typedef _Scalar Scalar;
32  enum { Options = _Options };
33  typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
34  typedef Eigen::Matrix<Scalar,3,3,Options> Matrix3;
35  typedef Eigen::Matrix<Scalar,6,1,Options> Vector6;
36  typedef Eigen::Matrix<Scalar,6,6,Options> Matrix6;
38 
39  typedef Eigen::Matrix<Scalar,3,Eigen::Dynamic,Options> Matrix3x;
40  typedef Eigen::Matrix<Scalar,6,Eigen::Dynamic,Options> Matrix6x;
41 
42  public:
43  // Constructors
44  ForceSetTpl(const int & ncols ) : size(ncols),m_f(3,ncols), m_n(3,ncols)
45  { m_f.fill(NAN); m_n.fill(NAN); }
46  ForceSetTpl(const Matrix3x & linear, const Matrix3x & angular)
47  : size((int)linear.cols()),m_f(linear), m_n(angular)
48  { assert( linear.cols() == angular.cols() ); }
49 
50  Matrix6x matrix() const
51  {
52  Matrix6x F(6,size); F << m_f, m_n;
53  // F.template topRows<3>() = m_f;
54  // F.template bottomRows<3>() = m_n;
55  return F;
56  }
57  operator Matrix6x () const { return matrix(); }
58 
59  // Getters
60  const Matrix3x & linear() const { return m_f; }
61  const Matrix3x & angular() const { return m_n; }
62 
64  ForceSetTpl se3Action(const SE3 & m) const
65  {
66  Matrix3x Rf (m.rotation()*linear());
67  return ForceSetTpl(Rf,skew(m.translation())*Rf+m.rotation()*angular());
68  // TODO check if nothing better than explicitely calling skew
69  }
71  ForceSetTpl se3ActionInverse(const SE3 & m) const
72  {
73  return ForceSetTpl(m.rotation().transpose()*linear(),
74  m.rotation().transpose()*(angular() - skew(m.translation())*linear()) );
75  // TODO check if nothing better than explicitely calling skew
76  }
77 
78  friend std::ostream & operator << (std::ostream & os, const ForceSetTpl & phi)
79  {
80  os
81  << "F =\n" << phi.linear() << std::endl
82  << "Tau =\n" << phi.angular() << std::endl;
83  return os;
84  }
85 
86  /* --- BLOCK ------------------------------------------------------------ */
87  struct Block
88  {
89  ForceSetTpl & ref;
90  int idx,len;
91  Block( ForceSetTpl & ref, const int & idx, const int & len )
92  : ref(ref), idx(idx), len(len) {}
93 
94  Eigen::Block<ForceSetTpl::Matrix3x> linear() { return ref.m_f.block(0,idx,3,len); }
95  Eigen::Block<ForceSetTpl::Matrix3x> angular() { return ref.m_n.block(0,idx,3,len); }
96  Eigen::Block<const ForceSetTpl::Matrix3x> linear() const
97  { return ((const ForceSetTpl::Matrix3x &)(ref.m_f)).block(0,idx,3,len); }
98  Eigen::Block<const ForceSetTpl::Matrix3x> angular() const
99  { return ((const ForceSetTpl::Matrix3x &)(ref.m_n)).block(0,idx,3,len); }
100 
101  ForceSetTpl::Matrix6x matrix() const
102  {
103  ForceSetTpl::Matrix6x res(6,len); res << linear(),angular();
104  return res;
105  }
106 
107  Block& operator= (const ForceSetTpl & copy)
108  {
109  assert(copy.size == len);
110  linear() = copy.linear(); //ref.m_f.block(0,idx,3,len) = copy.m_f;
111  angular() = copy.angular(); //ref.m_n.block(0,idx,3,len) = copy.m_n;
112  return *this;
113  }
114 
115  Block& operator= (const ForceSetTpl::Block & copy)
116  {
117  assert(copy.len == len);
118  linear() = copy.linear(); //ref.m_f.block(0,idx,3,len) = copy.ref.m_f.block(0,copy.idx,3,copy.len);
119  angular() = copy.angular(); //ref.m_n.block(0,idx,3,len) = copy.ref.m_n.block(0,copy.idx,3,copy.len);
120  return *this;
121  }
122 
123  template <typename D>
124  Block& operator= (const Eigen::MatrixBase<D> & m)
125  {
126  eigen_assert(D::RowsAtCompileTime == 6);
127  assert(m.cols() == len);
128  linear() = m.template topRows<3>();
129  angular() = m.template bottomRows<3>();
130  return *this;
131  }
132 
134  ForceSetTpl se3Action(const SE3 & m) const
135  {
136  // const Eigen::Block<const Matrix3x> linear = ref.linear().block(0,idx,3,len);
137  // const Eigen::Block<const Matrix3x> angular = ref.angular().block(0,idx,3,len);
138  Matrix3x Rf ((m.rotation()*linear()));
139  return ForceSetTpl(Rf,skew(m.translation())*Rf+m.rotation()*angular());
140  // TODO check if nothing better than explicitely calling skew
141  }
143  ForceSetTpl se3ActionInverse(const SE3 & m) const
144  {
145  // const Eigen::Block<const Matrix3x> linear = ref.linear().block(0,idx,3,len);
146  // const Eigen::Block<const Matrix3x> angular = ref.angular().block(0,idx,3,len);
147  return ForceSetTpl(m.rotation().transpose()*linear(),
148  m.rotation().transpose()*(angular() - skew(m.translation())*linear()) );
149  // TODO check if nothing better than explicitely calling skew
150  }
151 
152  };
153 
154  Block block(const int & idx, const int & len) { return Block(*this,idx,len); }
155 
156  /* CRBA joint operators
157  * - ForceSet::Block = ForceSet
158  * - ForceSet operator* (Inertia Y,Constraint S)
159  * - MatrixBase operator* (Constraint::Transpose S, ForceSet::Block)
160  * - SE3::act(ForceSet::Block)
161  */
162 
163 
164  public: //
165  private:
166  int size;
167  Matrix3x m_f,m_n;
168  };
169 
171 
172  namespace internal
173  {
174  template<>
175  struct SE3GroupAction<ForceSet::Block> { typedef ForceSet ReturnType; };
176  }
177 
178 
179 } // namespace se3
180 
181 #endif // ifndef __se3_force_set_hpp__
182 
ForceSetTpl se3ActionInverse(const SE3 &m) const
bf = aXb.actInv(af)
Definition: force-set.hpp:143
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
ForceSetTpl se3ActionInverse(const SE3 &m) const
bf = aXb.actInv(af)
Definition: force-set.hpp:71
ForceSetTpl se3Action(const SE3 &m) const
af = aXb.act(bf)
Definition: force-set.hpp:134
ForceSetTpl se3Action(const SE3 &m) const
af = aXb.act(bf)
Definition: force-set.hpp:64
void copy(const Model &model, const Data &origin, Data &dest)
Copy part of the data from <orig> to <dest>. Template parameter can be used to select at which differ...
Definition: copy.hpp:50