pinocchio  UNKNOWN
kinematics.hxx
1 //
2 // Copyright (c) 2016-2017 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_kinematics_hxx__
19 #define __se3_kinematics_hxx__
20 
21 #include "pinocchio/multibody/visitor.hpp"
22 #include "pinocchio/algorithm/check.hpp"
23 
24 namespace se3
25 {
26 
27  struct emptyForwardStep : public fusion::JointVisitor<emptyForwardStep>
28  {
29  typedef boost::fusion::vector<const se3::Model &,
30  se3::Data &
31  > ArgsType;
32 
33  JOINT_VISITOR_INIT (emptyForwardStep);
34 
35  template<typename JointModel>
36  static void algo(const se3::JointModelBase<JointModel> &,
38  const se3::Model &,
39  se3::Data &)
40  { // do nothing
41  }
42 
43  };
44 
45  inline void emptyForwardPass(const Model & model,
46  Data & data)
47  {
48  assert(model.check(data) && "data is not consistent with model.");
49 
50  for (Model::JointIndex i=1; i < (Model::JointIndex) model.njoints; ++i)
51  {
52  emptyForwardStep::run(model.joints[i],
53  data.joints[i],
54  emptyForwardStep::ArgsType (model,data)
55  );
56  }
57  }
58 
59  inline void updateGlobalPlacements(const Model & model, Data & data)
60  {
61  assert(model.check(data) && "data is not consistent with model.");
62 
63  for (Model::JointIndex i=1; i < (Model::JointIndex) model.njoints; ++i)
64  {
65  const Model::JointIndex & parent = model.parents[i];
66 
67  if (parent>0)
68  data.oMi[i] = data.oMi[parent] * data.liMi[i];
69  else
70  data.oMi[i] = data.liMi[i];
71  }
72  }
73 
74  struct ForwardKinematicZeroStep : public fusion::JointVisitor<ForwardKinematicZeroStep>
75  {
76  typedef boost::fusion::vector<const se3::Model &,
77  se3::Data &,
78  const Eigen::VectorXd &
79  > ArgsType;
80 
81  JOINT_VISITOR_INIT (ForwardKinematicZeroStep);
82 
83  template<typename JointModel>
84  static void algo(const se3::JointModelBase<JointModel> & jmodel,
86  const se3::Model & model,
87  se3::Data & data,
88  const Eigen::VectorXd & q)
89  {
90  const Model::JointIndex & i = jmodel.id();
91  const Model::JointIndex & parent = model.parents[i];
92 
93  jmodel.calc (jdata.derived (), q);
94 
95  data.liMi[i] = model.jointPlacements[i] * jdata.M ();
96 
97  if (parent>0)
98  data.oMi[i] = data.oMi[parent] * data.liMi[i];
99  else
100  data.oMi[i] = data.liMi[i];
101  }
102 
103  };
104 
105  inline void
106  forwardKinematics(const Model & model,
107  Data & data,
108  const Eigen::VectorXd & q)
109  {
110  assert(q.size() == model.nq && "The configuration vector is not of right size");
111  assert(model.check(data) && "data is not consistent with model.");
112 
113  for (Model::JointIndex i=1; i < (Model::JointIndex) model.njoints; ++i)
114  {
115  ForwardKinematicZeroStep::run(model.joints[i], data.joints[i],
116  ForwardKinematicZeroStep::ArgsType (model,data,q)
117  );
118  }
119  }
120 
121  struct ForwardKinematicFirstStep : public fusion::JointVisitor<ForwardKinematicFirstStep>
122  {
123  typedef boost::fusion::vector<const se3::Model &,
124  se3::Data &,
125  const Eigen::VectorXd &,
126  const Eigen::VectorXd &
127  > ArgsType;
128 
129  JOINT_VISITOR_INIT(ForwardKinematicFirstStep);
130 
131  template<typename JointModel>
132  static void algo(const se3::JointModelBase<JointModel> & jmodel,
134  const se3::Model & model,
135  se3::Data & data,
136  const Eigen::VectorXd & q,
137  const Eigen::VectorXd & v)
138  {
139  const Model::JointIndex & i = jmodel.id();
140  const Model::JointIndex & parent = model.parents[i];
141 
142  jmodel.calc(jdata.derived(),q,v);
143 
144  data.v[i] = jdata.v();
145  data.liMi[i] = model.jointPlacements[i]*jdata.M();
146 
147  if(parent>0)
148  {
149  data.oMi[i] = data.oMi[parent]*data.liMi[i];
150  data.v[i] += data.liMi[i].actInv(data.v[parent]);
151  }
152  else
153  data.oMi[i] = data.liMi[i];
154  }
155 
156  };
157 
158  inline void
159  forwardKinematics(const Model & model, Data & data,
160  const Eigen::VectorXd & q,
161  const Eigen::VectorXd & v)
162  {
163  assert(q.size() == model.nq && "The configuration vector is not of right size");
164  assert(v.size() == model.nv && "The velocity vector is not of right size");
165  assert(model.check(data) && "data is not consistent with model.");
166 
167  data.v[0].setZero();
168 
169  for( Model::JointIndex i=1; i<(Model::JointIndex) model.njoints; ++i )
170  {
171  ForwardKinematicFirstStep::run(model.joints[i],data.joints[i],
172  ForwardKinematicFirstStep::ArgsType(model,data,q,v));
173  }
174  }
175 
176  struct ForwardKinematicSecondStep : public fusion::JointVisitor<ForwardKinematicSecondStep>
177  {
178  typedef boost::fusion::vector<const se3::Model &,
179  se3::Data &,
180  const Eigen::VectorXd &,
181  const Eigen::VectorXd &,
182  const Eigen::VectorXd &
183  > ArgsType;
184 
185  JOINT_VISITOR_INIT(ForwardKinematicSecondStep);
186 
187  template<typename JointModel>
188  static void algo(const se3::JointModelBase<JointModel> & jmodel,
190  const se3::Model & model,
191  se3::Data & data,
192  const Eigen::VectorXd & q,
193  const Eigen::VectorXd & v,
194  const Eigen::VectorXd & a)
195  {
196  const Model::JointIndex & i = jmodel.id();
197  const Model::JointIndex & parent = model.parents[i];
198 
199  jmodel.calc(jdata.derived(),q,v);
200 
201  data.v[i] = jdata.v();
202  data.liMi[i] = model.jointPlacements[i] * jdata.M();
203 
204  if(parent>0)
205  {
206  data.oMi[i] = data.oMi[parent] * data.liMi[i];
207  data.v[i] += data.liMi[i].actInv(data.v[parent]);
208  }
209  else
210  data.oMi[i] = data.liMi[i];
211 
212  data.a[i] = jdata.S() * jmodel.jointVelocitySelector(a) + jdata.c() + (data.v[i] ^ jdata.v()) ;
213  data.a[i] += data.liMi[i].actInv(data.a[parent]);
214  }
215  };
216 
217  inline void
218  forwardKinematics(const Model & model, Data & data,
219  const Eigen::VectorXd & q,
220  const Eigen::VectorXd & v,
221  const Eigen::VectorXd & a)
222  {
223  assert(q.size() == model.nq && "The configuration vector is not of right size");
224  assert(v.size() == model.nv && "The velocity vector is not of right size");
225  assert(a.size() == model.nv && "The acceleration vector is not of right size");
226  assert(model.check(data) && "data is not consistent with model.");
227 
228  data.v[0].setZero();
229  data.a[0].setZero();
230 
231  for( Model::JointIndex i=1; i < (Model::JointIndex) model.njoints; ++i )
232  {
233  ForwardKinematicSecondStep::run(model.joints[i],data.joints[i],
234  ForwardKinematicSecondStep::ArgsType(model,data,q,v,a));
235  }
236  }
237 } // namespace se3
238 
239 #endif // ifndef __se3_kinematics_hxx__
container::aligned_vector< Motion > a
Vector of joint accelerations expressed at the centers of the joints.
Definition: data.hpp:58
int nq
Dimension of the configuration vector representation.
Definition: model.hpp:49
int nv
Dimension of the velocity vector space.
Definition: model.hpp:52
container::aligned_vector< SE3 > jointPlacements
Placement (SE3) of the input of joint i regarding to the parent joint output li.
Definition: model.hpp:67
JointModelVector joints
Model of joint i, encapsulated in a JointModelAccessor.
Definition: model.hpp:70
std::vector< JointIndex > parents
Joint parent of joint i, denoted li (li==parents[i]).
Definition: model.hpp:73
JointDataVector joints
Vector of se3::JointData associated to the se3::JointModel stored in model, encapsulated in JointData...
Definition: data.hpp:55
void forwardKinematics(const Model &model, Data &data, const Eigen::VectorXd &q)
Update the joint placements according to the current joint configuration.
Definition: kinematics.hxx:106
container::aligned_vector< SE3 > liMi
Vector of relative joint placements (wrt the body parent).
Definition: data.hpp:90
container::aligned_vector< SE3 > oMi
Vector of absolute joint placements (wrt the world).
Definition: data.hpp:87
bool check(const AlgorithmCheckerBase< D > &checker=AlgorithmCheckerBase< D >()) const
Definition: model.hpp:331
void updateGlobalPlacements(const Model &model, Data &data)
Update the global placement of the joints oMi according to the relative placements of the joints...
Definition: kinematics.hxx:59
void emptyForwardPass(const Model &model, Data &data)
Browse through the kinematic structure with a void step.
Definition: kinematics.hxx:45
container::aligned_vector< Motion > v
Vector of joint velocities expressed at the centers of the joints.
Definition: data.hpp:67
int njoints
Number of joints.
Definition: model.hpp:55