timings-jacobian.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2015-2018 CNRS
3 //
4 
5 #include "pinocchio/multibody/model.hpp"
6 #include "pinocchio/multibody/data.hpp"
7 #include "pinocchio/algorithm/joint-configuration.hpp"
8 #include "pinocchio/algorithm/kinematics.hpp"
9 #include "pinocchio/algorithm/jacobian.hpp"
10 #include "pinocchio/parsers/urdf.hpp"
11 #include "pinocchio/parsers/sample-models.hpp"
12 
13 #include <iostream>
14 
15 #include "pinocchio/utils/timer.hpp"
16 
17 #include <Eigen/StdVector>
18 EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(Eigen::VectorXd)
19 
20 int main(int argc, const char ** argv)
21 {
22  using namespace Eigen;
23  using namespace pinocchio;
24 
26  #ifdef NDEBUG
27  const int NBT = 1000*100;
28  #else
29  const int NBT = 1;
30  std::cout << "(the time score in debug mode is not relevant) " << std::endl;
31  #endif
32 
34 
35  std::string filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid.urdf");
36  if(argc>1) filename = argv[1];
37 
38  bool with_ff = true;
39  if(argc>2)
40  {
41  const std::string ff_option = argv[2];
42  if(ff_option == "-no-ff")
43  with_ff = false;
44  }
45 
46  if( filename == "HS")
48  else
49  if(with_ff)
51  else
52  pinocchio::urdf::buildModel(filename,model);
53  std::cout << "nq = " << model.nq << std::endl;
54 
55  pinocchio::Data data(model);
56  VectorXd qmax = Eigen::VectorXd::Ones(model.nq);
57  //VectorXd q = randomConfiguration(model);
58 
60  J.setZero();
62 
63  std::vector<VectorXd> qs(NBT);
64  for(size_t i=0;i<NBT;++i)
65  {
66  qs[i] = randomConfiguration(model,-qmax,qmax);
67  }
68 
69  timer.tic();
70  SMOOTH(NBT)
71  {
72  forwardKinematics(model,data,qs[_smooth]);
73  }
74  std::cout << "Zero Order Kinematics = \t"; timer.toc(std::cout,NBT);
75 
76  timer.tic();
77  SMOOTH(NBT)
78  {
79  computeJointJacobian(model,data,qs[_smooth],JOINT_ID,J);
80  }
81  std::cout << "computeJointJacobian = \t\t"; timer.toc(std::cout,NBT);
82 
83  timer.tic();
84  SMOOTH(NBT)
85  {
86  computeJointJacobians(model,data,qs[_smooth]);
87  }
88  std::cout << "computeJointJacobians(q) = \t"; timer.toc(std::cout,NBT);
89 
90  timer.tic();
91  SMOOTH(NBT)
92  {
93  computeJointJacobians(model,data);
94  }
95  std::cout << "computeJointJacobians() = \t"; timer.toc(std::cout,NBT);
96 
97  timer.tic();
98  SMOOTH(NBT)
99  {
100  getJointJacobian(model,data,JOINT_ID,LOCAL,J);
101  }
102  std::cout << "getJointJacobian(LOCAL) = \t"; timer.toc(std::cout,NBT);
103 
104  timer.tic();
105  SMOOTH(NBT)
106  {
107  getJointJacobian(model,data,JOINT_ID,WORLD,J);
108  }
109  std::cout << "getJointJacobian(WORLD) = \t"; timer.toc(std::cout,NBT);
110 
111  std::cout << "--" << std::endl;
112  return 0;
113 }
The WORLD frame convention corresponds to the frame concident with the Universe/Inertial frame but mo...
double toc()
Definition: timer.hpp:68
int njoints
Number of joints.
void randomConfiguration(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorIn1 > &lowerLimits, const Eigen::MatrixBase< ConfigVectorIn2 > &upperLimits, const Eigen::MatrixBase< ReturnType > &qout)
Generate a configuration vector uniformly sampled among provided limits.
void getJointJacobian(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const typename ModelTpl< Scalar, Options, JointCollectionTpl >::JointIndex jointId, const ReferenceFrame rf, const Eigen::MatrixBase< Matrix6Like > &J)
Computes the Jacobian of a specific joint frame expressed either in the world (rf = WORLD) frame or i...
data
#define PINOCCHIO_MODEL_DIR
void tic()
Definition: timer.hpp:63
int main(int argc, const char **argv)
void forwardKinematics(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q)
Update the joint placements according to the current joint configuration.
The LOCAL frame convention corresponds to the frame directly attached to the moving part (Joint...
pinocchio::JointIndex JointIndex
#define SMOOTH(s)
Definition: timer.hpp:38
ModelTpl< Scalar, Options, JointCollectionTpl > & buildModel(const std::string &filename, const typename ModelTpl< Scalar, Options, JointCollectionTpl >::JointModel &rootJoint, ModelTpl< Scalar, Options, JointCollectionTpl > &model, const bool verbose=false)
Build the model from a URDF file with a particular joint as root of the model tree inside the model g...
Main pinocchio namespace.
Definition: timings.cpp:30
const DataTpl< Scalar, Options, JointCollectionTpl >::Matrix6x & computeJointJacobians(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q)
Computes the full model Jacobian, i.e. the stack of all motion subspace expressed in the world frame...
int nv
Dimension of the velocity vector space.
JointModelFreeFlyerTpl< double > JointModelFreeFlyer
void computeJointJacobian(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const JointIndex jointId, const Eigen::MatrixBase< Matrix6Like > &J)
Computes the Jacobian of a specific joint frame expressed in the local frame of the joint and store t...
void humanoidRandom(ModelTpl< Scalar, Options, JointCollectionTpl > &model, bool usingFF=true)
Create a humanoid kinematic tree with 6-DOF limbs and random joint placements.
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > VectorXd
Definition: conversions.cpp:14
Eigen::Matrix< Scalar, 6, Eigen::Dynamic, Options > Matrix6x
The 6d jacobian type (temporary)
int nq
Dimension of the configuration vector representation.


pinocchio
Author(s):
autogenerated on Tue Jun 1 2021 02:45:04