pinocchio  UNKNOWN
finite-differences.hxx
1 //
2 // Copyright (c) 2016 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_finite_differences_hxx__
19 #define __se3_finite_differences_hxx__
20 
21 #include "pinocchio/multibody/visitor.hpp"
22 #include <boost/foreach.hpp>
23 
25 
26 namespace se3
27 {
28  namespace details
29  {
30  struct FinitDiffEpsVisitor : public fusion::JointModelVisitor<FinitDiffEpsVisitor>
31  {
32  typedef boost::fusion::vector<
33  Eigen::VectorXd &
34  > ArgsType;
35 
36  JOINT_MODEL_VISITOR_INIT(FinitDiffEpsVisitor);
37 
38  template<typename JointModel>
39  static void algo(const se3::JointModelBase<JointModel> & jmodel,
40  Eigen::VectorXd & fd_increment)
41  {
42  jmodel.jointVelocitySelector(fd_increment).fill(jmodel.finiteDifferenceIncrement());
43  }
44 
45  }; // struct FinitDiffEpsVisitor
46 
47  } // namespace details
48 
49  inline Eigen::VectorXd finiteDifferenceIncrement(const Model & model)
50  {
51  using namespace se3::details;
52  Eigen::VectorXd fd_increment(model.nv);
53  for(std::size_t k = 1; k < model.joints.size(); ++k)
54  {
55  const JointModel & jmodel = model.joints[k];
56  FinitDiffEpsVisitor::run(jmodel,FinitDiffEpsVisitor::ArgsType(fd_increment));
57  }
58 
59  return fd_increment;
60  }
61 } // namespace se3
62 
64 
65 #endif // ifndef __se3_finite_differences_hxx__
int nv
Dimension of the velocity vector space.
Definition: model.hpp:52
JointModelVector joints
Model of joint i, encapsulated in a JointModelAccessor.
Definition: model.hpp:70
ConfigVector_t::Scalar finiteDifferenceIncrement() const
Return the resolution of the finite differerence increment according to the Scalar type...
Definition: joint-base.hpp:241
Eigen::VectorXd finiteDifferenceIncrement(const Model &model)
Computes the finite difference increments for each degree of freedom according to the current joint c...