force-set.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2015 CNRS
3 //
4 
5 #ifndef __pinocchio_spatial_force_set_hpp__
6 #define __pinocchio_spatial_force_set_hpp__
7 
9 #include <Eigen/Geometry>
10 
11 namespace pinocchio
12 {
13  template<typename _Scalar, int _Options>
15  {
16  public:
17  typedef _Scalar Scalar;
18  enum
19  {
20  Options = _Options
21  };
22  typedef Eigen::Matrix<Scalar, 3, 1, Options> Vector3;
23  typedef Eigen::Matrix<Scalar, 3, 3, Options> Matrix3;
24  typedef Eigen::Matrix<Scalar, 6, 1, Options> Vector6;
25  typedef Eigen::Matrix<Scalar, 6, 6, Options> Matrix6;
27 
28  typedef Eigen::Matrix<Scalar, 3, Eigen::Dynamic, Options> Matrix3x;
29  typedef Eigen::Matrix<Scalar, 6, Eigen::Dynamic, Options> Matrix6x;
30 
31  public:
32  // Constructors
33  ForceSetTpl(const int & ncols)
34  : size(ncols)
35  , m_f(3, ncols)
36  , m_n(3, ncols)
37  {
38  m_f.fill(NAN);
39  m_n.fill(NAN);
40  }
42  : size((int)linear.cols())
43  , m_f(linear)
44  , m_n(angular)
45  {
46  assert(linear.cols() == angular.cols());
47  }
48 
49  Matrix6x matrix() const
50  {
51  Matrix6x F(6, size);
52  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
58  {
59  return matrix();
60  }
61 
62  // Getters
63  const Matrix3x & linear() const
64  {
65  return m_f;
66  }
67  const Matrix3x & angular() const
68  {
69  return m_n;
70  }
71 
73  ForceSetTpl se3Action(const SE3 & m) const
74  {
75  Matrix3x Rf(m.rotation() * linear());
76  return ForceSetTpl(Rf, skew(m.translation()) * Rf + m.rotation() * angular());
77  // TODO check if nothing better than explicitely calling skew
78  }
81  {
82  return ForceSetTpl(
83  m.rotation().transpose() * linear(),
84  m.rotation().transpose() * (angular() - skew(m.translation()) * linear()));
85  // TODO check if nothing better than explicitely calling skew
86  }
87 
88  friend std::ostream & operator<<(std::ostream & os, const ForceSetTpl & phi)
89  {
90  os << "F =\n" << phi.linear() << std::endl << "Tau =\n" << phi.angular() << std::endl;
91  return os;
92  }
93 
94  /* --- BLOCK ------------------------------------------------------------ */
95  struct Block
96  {
98  int idx, len;
99  Block(ForceSetTpl & ref, const int & idx, const int & len)
100  : ref(ref)
101  , idx(idx)
102  , len(len)
103  {
104  }
105 
106  Eigen::Block<ForceSetTpl::Matrix3x> linear()
107  {
108  return ref.m_f.block(0, idx, 3, len);
109  }
110  Eigen::Block<ForceSetTpl::Matrix3x> angular()
111  {
112  return ref.m_n.block(0, idx, 3, len);
113  }
114  Eigen::Block<const ForceSetTpl::Matrix3x> linear() const
115  {
116  return ((const ForceSetTpl::Matrix3x &)(ref.m_f)).block(0, idx, 3, len);
117  }
118  Eigen::Block<const ForceSetTpl::Matrix3x> angular() const
119  {
120  return ((const ForceSetTpl::Matrix3x &)(ref.m_n)).block(0, idx, 3, len);
121  }
122 
124  {
126  res << linear(), angular();
127  return res;
128  }
129 
131  {
132  assert(copy.size == len);
133  linear() = copy.linear(); // ref.m_f.block(0,idx,3,len) = copy.m_f;
134  angular() = copy.angular(); // ref.m_n.block(0,idx,3,len) = copy.m_n;
135  return *this;
136  }
137 
139  {
140  assert(copy.len == len);
141  linear() =
142  copy.linear(); // ref.m_f.block(0,idx,3,len) = copy.ref.m_f.block(0,copy.idx,3,copy.len);
143  angular() =
144  copy.angular(); // ref.m_n.block(0,idx,3,len) = copy.ref.m_n.block(0,copy.idx,3,copy.len);
145  return *this;
146  }
147 
148  template<typename D>
149  Block & operator=(const Eigen::MatrixBase<D> & m)
150  {
151  eigen_assert(D::RowsAtCompileTime == 6);
152  assert(m.cols() == len);
153  linear() = m.template topRows<3>();
154  angular() = m.template bottomRows<3>();
155  return *this;
156  }
157 
159  ForceSetTpl se3Action(const SE3 & m) const
160  {
161  // const Eigen::Block<const Matrix3x> linear = ref.linear().block(0,idx,3,len);
162  // const Eigen::Block<const Matrix3x> angular = ref.angular().block(0,idx,3,len);
163  Matrix3x Rf((m.rotation() * linear()));
164  return ForceSetTpl(Rf, skew(m.translation()) * Rf + m.rotation() * angular());
165  // TODO check if nothing better than explicitely calling skew
166  }
169  {
170  // const Eigen::Block<const Matrix3x> linear = ref.linear().block(0,idx,3,len);
171  // const Eigen::Block<const Matrix3x> angular = ref.angular().block(0,idx,3,len);
172  return ForceSetTpl(
173  m.rotation().transpose() * linear(),
174  m.rotation().transpose() * (angular() - skew(m.translation()) * linear()));
175  // TODO check if nothing better than explicitely calling skew
176  }
177  };
178 
179  Block block(const int & idx, const int & len)
180  {
181  return Block(*this, idx, len);
182  }
183 
184  /* CRBA joint operators
185  * - ForceSet::Block = ForceSet
186  * - ForceSet operator* (Inertia Y,Constraint S)
187  * - MatrixBase operator* (Constraint::Transpose S, ForceSet::Block)
188  * - SE3::act(ForceSet::Block)
189  */
190 
191  public: //
192  private:
193  int size;
195  };
196 
198 
199  template<>
200  struct SE3GroupAction<ForceSet::Block>
201  {
203  };
204 
205 } // namespace pinocchio
206 
207 #endif // ifndef __pinocchio_spatial_force_set_hpp__
pinocchio::ForceSetTpl::Vector3
Eigen::Matrix< Scalar, 3, 1, Options > Vector3
Definition: force-set.hpp:22
fwd.hpp
test-cpp2pybind11.m
m
Definition: test-cpp2pybind11.py:22
pinocchio::ForceSetTpl::matrix
Matrix6x matrix() const
Definition: force-set.hpp:49
pinocchio::ForceSetTpl::Options
@ Options
Definition: force-set.hpp:20
pinocchio::ForceSetTpl::Matrix3x
Eigen::Matrix< Scalar, 3, Eigen::Dynamic, Options > Matrix3x
Definition: force-set.hpp:28
pinocchio::ForceSetTpl::Block::operator=
Block & operator=(const ForceSetTpl::Block &copy)
Definition: force-set.hpp:138
pinocchio::ForceSetTpl::angular
const Matrix3x & angular() const
Definition: force-set.hpp:67
pinocchio::ForceSetTpl::linear
const Matrix3x & linear() const
Definition: force-set.hpp:63
pinocchio::ForceSetTpl::ForceSetTpl
ForceSetTpl(const int &ncols)
Definition: force-set.hpp:33
pinocchio::ForceSetTpl::size
int size
Definition: force-set.hpp:193
pinocchio::SE3Tpl< Scalar, Options >
pinocchio::ForceSetTpl::Block::Block
Block(ForceSetTpl &ref, const int &idx, const int &len)
Definition: force-set.hpp:99
pinocchio::ForceSetTpl::Block::se3ActionInverse
ForceSetTpl se3ActionInverse(const SE3 &m) const
bf = aXb.actInv(af)
Definition: force-set.hpp:168
pinocchio::ForceSetTpl::Block
Definition: force-set.hpp:95
pinocchio::ForceSetTpl::Block::angular
Eigen::Block< const ForceSetTpl::Matrix3x > angular() const
Definition: force-set.hpp:118
pinocchio::res
ReturnType res
Definition: spatial/classic-acceleration.hpp:57
pinocchio::ForceSetTpl::Block::se3Action
ForceSetTpl se3Action(const SE3 &m) const
af = aXb.act(bf)
Definition: force-set.hpp:159
pinocchio::SE3GroupAction
Definition: spatial/se3.hpp:39
pinocchio::ForceSetTpl::m_n
Matrix3x m_n
Definition: force-set.hpp:194
pinocchio::ForceSetTpl::Block::linear
Eigen::Block< const ForceSetTpl::Matrix3x > linear() const
Definition: force-set.hpp:114
pinocchio::ForceSetTpl::ForceSetTpl
ForceSetTpl(const Matrix3x &linear, const Matrix3x &angular)
Definition: force-set.hpp:41
pinocchio::skew
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:22
pinocchio::ForceSetTpl::m_f
Matrix3x m_f
Definition: force-set.hpp:194
pinocchio::ForceSetTpl::Block::operator=
Block & operator=(const ForceSetTpl &copy)
Definition: force-set.hpp:130
pinocchio::ForceSetTpl::Scalar
_Scalar Scalar
Definition: force-set.hpp:17
pinocchio::ForceSetTpl::Matrix6x
Eigen::Matrix< Scalar, 6, Eigen::Dynamic, Options > Matrix6x
Definition: force-set.hpp:29
pinocchio::ForceSetTpl::Block::operator=
Block & operator=(const Eigen::MatrixBase< D > &m)
Definition: force-set.hpp:149
pinocchio::ForceSetTpl::Matrix3
Eigen::Matrix< Scalar, 3, 3, Options > Matrix3
Definition: force-set.hpp:23
pinocchio::ForceSetTpl::Block::ref
ForceSetTpl & ref
Definition: force-set.hpp:97
pinocchio::ForceSetTpl::SE3
SE3Tpl< Scalar, Options > SE3
Definition: force-set.hpp:26
pinocchio::ForceSetTpl::Vector6
Eigen::Matrix< Scalar, 6, 1, Options > Vector6
Definition: force-set.hpp:24
pinocchio::ForceSetTpl::Block::linear
Eigen::Block< ForceSetTpl::Matrix3x > linear()
Definition: force-set.hpp:106
pinocchio::ForceSetTpl::Matrix6
Eigen::Matrix< Scalar, 6, 6, Options > Matrix6
Definition: force-set.hpp:25
pinocchio::ForceSetTpl::se3ActionInverse
ForceSetTpl se3ActionInverse(const SE3 &m) const
bf = aXb.actInv(af)
Definition: force-set.hpp:80
pinocchio::ForceSetTpl
Definition: force-set.hpp:14
pinocchio::ForceSetTpl::Block::len
int len
Definition: force-set.hpp:98
pinocchio::SE3GroupAction< ForceSet::Block >::ReturnType
ForceSet ReturnType
Definition: force-set.hpp:202
pinocchio::ForceSetTpl::Block::matrix
ForceSetTpl::Matrix6x matrix() const
Definition: force-set.hpp:123
pinocchio::copy
void copy(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &origin, DataTpl< Scalar, Options, JointCollectionTpl > &dest, KinematicLevel kinematic_level)
Copy part of the data from origin to dest. Template parameter can be used to select at which differen...
Definition: copy.hpp:42
pinocchio::ForceSetTpl::operator<<
friend std::ostream & operator<<(std::ostream &os, const ForceSetTpl &phi)
Definition: force-set.hpp:88
cols
int cols
pinocchio::ForceSet
ForceSetTpl< context::Scalar, context::Options > ForceSet
Definition: force-set.hpp:197
pinocchio::ForceSetTpl::Block::idx
int idx
Definition: force-set.hpp:98
pinocchio::ForceSetTpl::block
Block block(const int &idx, const int &len)
Definition: force-set.hpp:179
pinocchio::ForceSetTpl::se3Action
ForceSetTpl se3Action(const SE3 &m) const
af = aXb.act(bf)
Definition: force-set.hpp:73
pinocchio::ForceSetTpl::Block::angular
Eigen::Block< ForceSetTpl::Matrix3x > angular()
Definition: force-set.hpp:110
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27


pinocchio
Author(s):
autogenerated on Sat Jun 22 2024 02:41:46