timings-cg.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2018 CNRS
3 // Copyright (c) 2020-2024 INRIA
4 //
5 
7 
24 
26 
27 #include <iostream>
28 
30 
31 int main(int argc, const char ** argv)
32 {
33  using namespace Eigen;
34  using namespace pinocchio;
35 
37 #ifdef NDEBUG
38  const int NBT = 1000 * 100;
39 #else
40  const int NBT = 1;
41  std::cout << "(the time score in debug mode is not relevant) " << std::endl;
42 #endif
43 
45  std::string filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid.urdf");
46  if (argc > 1)
47  filename = argv[1];
48 
49  bool with_ff = true;
50  if (argc > 2)
51  {
52  const std::string ff_option = argv[2];
53  if (ff_option == "-no-ff")
54  with_ff = false;
55  }
56 
57  if (filename == "H")
59  else if (with_ff)
61  else
63 
64  std::cout << "nq = " << model.nq << std::endl;
65  std::cout << "nv = " << model.nv << std::endl;
66  std::cout << "--" << std::endl;
67 
69 
70  const std::string RF = "RLEG_ANKLE_R";
71  const std::string LF = "LLEG_ANKLE_R";
73 
74  RigidConstraintModel ci_RF(CONTACT_6D, model, model.getFrameId(RF), LOCAL);
75  RigidConstraintModel ci_LF(CONTACT_6D, model, model.getFrameId(LF), LOCAL);
76  contact_models_6D6D.push_back(ci_RF);
77  contact_models_6D6D.push_back(ci_LF);
78 
80 
81  RigidConstraintData cd_RF(ci_RF);
82  contact_datas_6D6D.push_back(cd_RF);
83  RigidConstraintData cd_LF(ci_LF);
84  contact_datas_6D6D.push_back(cd_LF);
85 
86  VectorXd qmax = Eigen::VectorXd::Ones(model.nq);
87 
88  CodeGenRNEA<double> rnea_code_gen(model);
89  rnea_code_gen.initLib();
90  rnea_code_gen.loadLib();
91 
92  CodeGenABA<double> aba_code_gen(model);
93  aba_code_gen.initLib();
94  aba_code_gen.loadLib();
95 
96  CodeGenCRBA<double> crba_code_gen(model);
97  crba_code_gen.initLib();
98  crba_code_gen.loadLib();
99 
100  CodeGenMinv<double> minv_code_gen(model);
101  minv_code_gen.initLib();
102  minv_code_gen.loadLib();
103 
104  CodeGenRNEADerivatives<double> rnea_derivatives_code_gen(model);
105  rnea_derivatives_code_gen.initLib();
106  rnea_derivatives_code_gen.loadLib();
107 
108  CodeGenABADerivatives<double> aba_derivatives_code_gen(model);
109  aba_derivatives_code_gen.initLib();
110  aba_derivatives_code_gen.loadLib();
111 
112  CodeGenConstraintDynamicsDerivatives<double> constraint_dynamics_derivatives_code_gen(
113  model, contact_models_6D6D);
114  constraint_dynamics_derivatives_code_gen.initLib();
115  constraint_dynamics_derivatives_code_gen.loadLib();
116 
121 
122  for (size_t i = 0; i < NBT; ++i)
123  {
124  qs[i] = randomConfiguration(model, -qmax, qmax);
125  qdots[i] = Eigen::VectorXd::Random(model.nv);
126  qddots[i] = Eigen::VectorXd::Random(model.nv);
127  taus[i] = Eigen::VectorXd::Random(model.nv);
128  }
129 
130  timer.tic();
131  SMOOTH(NBT)
132  {
133  rnea(model, data, qs[_smooth], qdots[_smooth], qddots[_smooth]);
134  }
135  std::cout << "RNEA = \t\t";
136  timer.toc(std::cout, NBT);
137 
138  timer.tic();
139  SMOOTH(NBT)
140  {
141  rnea_code_gen.evalFunction(qs[_smooth], qdots[_smooth], qddots[_smooth]);
142  }
143  std::cout << "RNEA generated = \t\t";
144  timer.toc(std::cout, NBT);
145 
146  timer.tic();
147  SMOOTH(NBT)
148  {
149  rnea_code_gen.evalJacobian(qs[_smooth], qdots[_smooth], qddots[_smooth]);
150  }
151  std::cout << "RNEA partial derivatives auto diff + code gen = \t\t";
152  timer.toc(std::cout, NBT);
153 
154  timer.tic();
155  SMOOTH(NBT)
156  {
157  rnea_derivatives_code_gen.evalFunction(qs[_smooth], qdots[_smooth], qddots[_smooth]);
158  }
159  std::cout << "RNEA partial derivatives code gen = \t\t";
160  timer.toc(std::cout, NBT);
161 
162  timer.tic();
163  SMOOTH(NBT)
164  {
165  aba(model, data, qs[_smooth], qdots[_smooth], taus[_smooth], Convention::WORLD);
166  }
167  timer.toc();
168 
169  timer.tic();
170  SMOOTH(NBT)
171  {
172  crba(model, data, qs[_smooth], Convention::WORLD);
173  }
174  std::cout << "CRBA = \t\t";
175  timer.toc(std::cout, NBT);
176 
177  timer.tic();
178  SMOOTH(NBT)
179  {
180  crba_code_gen.evalFunction(qs[_smooth]);
181  }
182  std::cout << "CRBA generated = \t\t";
183  timer.toc(std::cout, NBT);
184 
185  timer.tic();
186  SMOOTH(NBT)
187  {
188  computeMinverse(model, data, qs[_smooth]);
189  }
190  std::cout << "Minv = \t\t";
191  timer.toc(std::cout, NBT);
192 
193  timer.tic();
194  SMOOTH(NBT)
195  {
196  minv_code_gen.evalFunction(qs[_smooth]);
197  }
198  std::cout << "Minv generated = \t\t";
199  timer.toc(std::cout, NBT);
200 
201  timer.tic();
202  SMOOTH(NBT)
203  {
204  aba(model, data, qs[_smooth], qdots[_smooth], taus[_smooth], Convention::WORLD);
205  }
206  std::cout << "ABA = \t\t";
207  timer.toc(std::cout, NBT);
208 
209  timer.tic();
210  SMOOTH(NBT)
211  {
212  aba_code_gen.evalFunction(qs[_smooth], qdots[_smooth], taus[_smooth]);
213  }
214  std::cout << "ABA generated = \t\t";
215  timer.toc(std::cout, NBT);
216 
217  timer.tic();
218  SMOOTH(NBT)
219  {
220  aba_code_gen.evalJacobian(qs[_smooth], qdots[_smooth], taus[_smooth]);
221  }
222  std::cout << "ABA partial derivatives auto diff + code gen = \t\t";
223  timer.toc(std::cout, NBT);
224 
225  timer.tic();
226  SMOOTH(NBT)
227  {
228  aba_derivatives_code_gen.evalFunction(qs[_smooth], qdots[_smooth], qddots[_smooth]);
229  }
230  std::cout << "ABA partial derivatives code gen = \t\t";
231  timer.toc(std::cout, NBT);
232 
233  pinocchio::initConstraintDynamics(model, data, contact_models_6D6D);
234  timer.tic();
235  SMOOTH(NBT)
236  {
238  model, data, qs[_smooth], qdots[_smooth], qddots[_smooth], contact_models_6D6D,
239  contact_datas_6D6D);
241  model, data, contact_models_6D6D, contact_datas_6D6D);
242  }
243  std::cout << "contact dynamics derivatives 6D,6D = \t\t";
244  timer.toc(std::cout, NBT);
245 
246  timer.tic();
247  SMOOTH(NBT)
248  {
249  constraint_dynamics_derivatives_code_gen.evalFunction(
250  qs[_smooth], qdots[_smooth], qddots[_smooth]);
251  }
252  std::cout << "contact dynamics derivatives 6D,6D code gen = \t\t";
253  timer.toc(std::cout, NBT);
254 
255  return 0;
256 }
pinocchio::WORLD
@ WORLD
Definition: multibody/fwd.hpp:48
PinocchioTicToc::toc
double toc()
Definition: timer.hpp:88
pinocchio::CodeGenBase::initLib
void initLib()
Definition: code-generator-base.hpp:78
pinocchio::CodeGenABA::evalFunction
void evalFunction(const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVector1 > &v, const Eigen::MatrixBase< TangentVector2 > &tau)
Definition: code-generator-algo.hpp:198
Eigen
pinocchio::CodeGenMinv
Definition: code-generator-algo.hpp:358
pinocchio::DataTpl
Definition: context/generic.hpp:25
cppadcg.hpp
compute-all-terms.hpp
pinocchio::computeConstraintDynamicsDerivatives
void computeConstraintDynamicsDerivatives(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const std::vector< RigidConstraintModelTpl< Scalar, Options >, ConstraintModelAllocator > &contact_models, std::vector< RigidConstraintDataTpl< Scalar, Options >, ConstraintDataAllocator > &contact_data, const ProximalSettingsTpl< Scalar > &settings, const Eigen::MatrixBase< MatrixType1 > &ddq_partial_dq, const Eigen::MatrixBase< MatrixType2 > &ddq_partial_dv, const Eigen::MatrixBase< MatrixType3 > &ddq_partial_dtau, const Eigen::MatrixBase< MatrixType4 > &lambda_partial_dq, const Eigen::MatrixBase< MatrixType5 > &lambda_partial_dv, const Eigen::MatrixBase< MatrixType6 > &lambda_partial_dtau)
aligned-vector.hpp
pinocchio::CodeGenRNEADerivatives::evalFunction
void evalFunction(const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVector1 > &v, const Eigen::MatrixBase< TangentVector2 > &a)
Definition: code-generator-algo.hpp:527
pinocchio::CodeGenRNEA::evalFunction
void evalFunction(const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVector1 > &v, const Eigen::MatrixBase< TangentVector2 > &a)
Definition: code-generator-algo.hpp:79
inverse-kinematics.i
int i
Definition: inverse-kinematics.py:17
code-generator-algo.hpp
kinematics.hpp
setup.data
data
Definition: cmake/cython/setup.in.py:48
pinocchio::buildModels::humanoidRandom
void humanoidRandom(ModelTpl< Scalar, Options, JointCollectionTpl > &model, bool usingFF=true)
Create a humanoid kinematic tree with 6-DOF limbs and random joint placements.
pinocchio::python::context::JointModelFreeFlyer
JointModelFreeFlyerTpl< Scalar > JointModelFreeFlyer
Definition: bindings/python/context/generic.hpp:126
pinocchio::crba
const DataTpl< Scalar, Options, JointCollectionTpl >::MatrixXs & crba(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const Convention convention=Convention::LOCAL)
Computes the upper triangular part of the joint space inertia matrix M by using the Composite Rigid B...
pinocchio::aba
const DataTpl< Scalar, Options, JointCollectionTpl >::TangentVectorType & aba(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType1 > &v, const Eigen::MatrixBase< TangentVectorType2 > &tau, const Convention convention=Convention::LOCAL)
The Articulated-Body algorithm. It computes the forward dynamics, aka the joint accelerations given t...
main
int main(int argc, const char **argv)
Definition: timings-cg.cpp:31
constrained-dynamics-derivatives.hpp
pinocchio::randomConfiguration
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.
Definition: joint-configuration.hpp:315
pinocchio::CONTACT_6D
@ CONTACT_6D
Point contact model.
Definition: algorithm/contact-info.hpp:22
rnea.hpp
timer.hpp
pinocchio::computeMinverse
const DataTpl< Scalar, Options, JointCollectionTpl >::RowMatrixXs & computeMinverse(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q)
Computes the inverse of the joint space inertia matrix using Articulated Body formulation.
pinocchio::CodeGenMinv::evalFunction
void evalFunction(const Eigen::MatrixBase< ConfigVectorType > &q)
Definition: code-generator-algo.hpp:414
aba.hpp
anymal-simulation.model
model
Definition: anymal-simulation.py:8
center-of-mass.hpp
SMOOTH
#define SMOOTH(s)
Definition: timer.hpp:38
joint-configuration.hpp
pinocchio::CodeGenBase::loadLib
void loadLib(const bool generate_if_not_exist=true, const std::string &gcc_path="/usr/bin/gcc", const std::string &compile_options="-Ofast")
Definition: code-generator-base.hpp:123
pinocchio::RigidConstraintModelTpl
Definition: algorithm/constraints/fwd.hpp:14
filename
filename
pinocchio::CodeGenABADerivatives
Definition: code-generator-algo.hpp:570
urdf.hpp
pinocchio::RigidConstraintDataTpl
Definition: algorithm/constraints/fwd.hpp:16
pinocchio::initConstraintDynamics
void initConstraintDynamics(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const std::vector< RigidConstraintModelTpl< Scalar, Options >, Allocator > &contact_models)
Init the forward dynamics data according to the contact information contained in contact_models.
pinocchio::CodeGenABA
Definition: code-generator-algo.hpp:142
pinocchio::urdf::buildModel
ModelTpl< Scalar, Options, JointCollectionTpl > & buildModel(const std::string &filename, const typename ModelTpl< Scalar, Options, JointCollectionTpl >::JointModel &rootJoint, const std::string &rootJointName, 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...
pinocchio::CodeGenABADerivatives::evalFunction
void evalFunction(const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVector1 > &v, const Eigen::MatrixBase< TangentVector2 > &tau)
Definition: code-generator-algo.hpp:646
pinocchio::CodeGenCRBA
Definition: code-generator-algo.hpp:262
PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR
#define PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR(T)
Definition: container/aligned-vector.hpp:13
pinocchio::CodeGenABA::evalJacobian
void evalJacobian(const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVector1 > &v, const Eigen::MatrixBase< TangentVector2 > &tau)
Definition: code-generator-algo.hpp:218
PinocchioTicToc::US
@ US
Definition: timer.hpp:53
cholesky.hpp
pinocchio::container::aligned_vector
std::vector< T, Eigen::aligned_allocator< T > > aligned_vector
Definition: container/aligned-vector.hpp:21
pinocchio::CodeGenRNEA::evalJacobian
void evalJacobian(const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVector1 > &v, const Eigen::MatrixBase< TangentVector2 > &a)
Definition: code-generator-algo.hpp:99
centroidal.hpp
pinocchio::rnea
const DataTpl< Scalar, Options, JointCollectionTpl >::TangentVectorType & rnea(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType1 > &v, const Eigen::MatrixBase< TangentVectorType2 > &a)
The Recursive Newton-Euler algorithm. It computes the inverse dynamics, aka the joint torques accordi...
contact-info.hpp
pinocchio::CodeGenCRBA::evalFunction
void evalFunction(const Eigen::MatrixBase< ConfigVectorType > &q)
Definition: code-generator-algo.hpp:319
sample-models.hpp
pinocchio::CodeGenConstraintDynamicsDerivatives::evalFunction
void evalFunction(const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVector1 > &v, const Eigen::MatrixBase< TangentVector2 > &tau)
Definition: code-generator-algo.hpp:820
jacobian.hpp
pinocchio::ModelTpl
Definition: context/generic.hpp:20
constrained-dynamics.hpp
crba.hpp
pinocchio::CodeGenRNEADerivatives
Definition: code-generator-algo.hpp:451
PinocchioTicToc
Definition: timer.hpp:47
meshcat-viewer.qs
qs
Definition: meshcat-viewer.py:128
pinocchio::constraintDynamics
const DataTpl< Scalar, Options, JointCollectionTpl >::TangentVectorType & constraintDynamics(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType1 > &v, const Eigen::MatrixBase< TangentVectorType2 > &tau, const std::vector< RigidConstraintModelTpl< Scalar, Options >, ConstraintModelAllocator > &contact_models, std::vector< RigidConstraintDataTpl< Scalar, Options >, ConstraintDataAllocator > &contact_datas, ProximalSettingsTpl< Scalar > &settings)
Computes the forward dynamics with contact constraints according to a given list of contact informati...
pinocchio::CodeGenRNEA
Definition: code-generator-algo.hpp:22
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27
pinocchio::CodeGenConstraintDynamicsDerivatives
Definition: code-generator-algo.hpp:689
PINOCCHIO_MODEL_DIR
#define PINOCCHIO_MODEL_DIR
Definition: build-reduced-model.cpp:11
PinocchioTicToc::tic
void tic()
Definition: timer.hpp:82
pinocchio::LOCAL
@ LOCAL
Definition: multibody/fwd.hpp:50


pinocchio
Author(s):
autogenerated on Thu Dec 19 2024 03:41:33