timings-impulse-dynamics-derivatives.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 LAAS-CNRS, INRIA
3 //
4 
11 
12 #include <iostream>
13 
15 
16 int main(int argc, const char ** argv)
17 {
18  using namespace Eigen;
19  using namespace pinocchio;
20 
22 #ifdef NDEBUG
23  const int NBT = 1000 * 100;
24 #else
25  const int NBT = 1;
26  std::cout << "(the time score in debug mode is not relevant) " << std::endl;
27 #endif
28 
29  // Build model
30  Model model;
31 
32  std::string filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid.urdf");
33  if (argc > 1)
34  filename = argv[1];
35  bool with_ff = true;
36 
37  if (argc > 2)
38  {
39  const std::string ff_option = argv[2];
40  if (ff_option == "-no-ff")
41  with_ff = false;
42  }
43 
44  if (filename == "HS")
46  else if (with_ff)
48  // pinocchio::urdf::buildModel(filename,JointModelRX(),model);
49  else
51 
52  const std::string RA = "RARM_LINK6";
53  const std::string LA = "LARM_LINK6";
54  const std::string RF = "RLEG_LINK6";
55  const std::string LF = "LLEG_LINK6";
56 
57  RigidConstraintModel ci_RF_6D(CONTACT_6D, model.getFrameId(RF), LOCAL);
58  RigidConstraintData cd_RF_6D(ci_RF_6D);
59 
60  RigidConstraintModel ci_LF_6D(CONTACT_6D, model.getFrameId(LF), LOCAL);
61  RigidConstraintData cd_LF_6D(ci_LF_6D);
62 
63  // Define contact infos structure
66 
67  cholesky::ContactCholeskyDecomposition contact_chol_empty(model, contact_infos_empty);
68 
71  contact_infos_6D.push_back(ci_RF_6D);
72  contact_datas_6D.push_back(cd_RF_6D);
73 
74  cholesky::ContactCholeskyDecomposition contact_chol_6D(model, contact_infos_6D);
75 
78  contact_infos_6D6D.push_back(ci_RF_6D);
79  contact_datas_6D6D.push_back(cd_RF_6D);
80  contact_infos_6D6D.push_back(ci_LF_6D);
81  contact_datas_6D6D.push_back(cd_LF_6D);
82 
83  cholesky::ContactCholeskyDecomposition contact_chol_6D6D(model, contact_infos_6D6D);
84 
85  std::cout << "nq = " << model.nq << std::endl;
86  std::cout << "nv = " << model.nv << std::endl;
87  std::cout << "--" << std::endl;
88 
89  Data data(model);
90  VectorXd qmax = Eigen::VectorXd::Ones(model.nq);
91 
93  PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR(VectorXd) qdots(NBT);
94  PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR(VectorXd) qddots(NBT);
96 
97  for (size_t i = 0; i < NBT; ++i)
98  {
99  qs[i] = randomConfiguration(model, -qmax, qmax);
100  qdots[i] = Eigen::VectorXd::Random(model.nv);
101  qddots[i] = Eigen::VectorXd::Random(model.nv);
102  taus[i] = Eigen::VectorXd::Random(model.nv);
103  }
104 
105  double total_time = 0;
106  initConstraintDynamics(model, data, contact_infos_empty);
107  SMOOTH(NBT)
108  {
110  model, data, qs[_smooth], qdots[_smooth], contact_infos_empty, contact_datas_empty);
111  timer.tic();
112  computeImpulseDynamicsDerivatives(model, data, contact_infos_empty, contact_datas_empty);
113  total_time += timer.toc(timer.DEFAULT_UNIT);
114  }
115  std::cout << "impulseDynamicsDerivs {} = \t\t" << (total_time / NBT) << std::endl;
116 
117  total_time = 0;
118  initConstraintDynamics(model, data, contact_infos_6D);
119  SMOOTH(NBT)
120  {
121  impulseDynamics(model, data, qs[_smooth], qdots[_smooth], contact_infos_6D, contact_datas_6D);
122  timer.tic();
123  computeImpulseDynamicsDerivatives(model, data, contact_infos_6D, contact_datas_6D);
124  total_time += timer.toc(timer.DEFAULT_UNIT);
125  }
126  std::cout << "impulseDynamicsDerivs {6D} = \t\t" << (total_time / NBT) << std::endl;
127 
128  total_time = 0;
129  initConstraintDynamics(model, data, contact_infos_6D6D);
130  SMOOTH(NBT)
131  {
133  model, data, qs[_smooth], qdots[_smooth], contact_infos_6D6D, contact_datas_6D6D);
134  timer.tic();
135  computeImpulseDynamicsDerivatives(model, data, contact_infos_6D6D, contact_datas_6D6D);
136  total_time += timer.toc(timer.DEFAULT_UNIT);
137  }
138  std::cout << "impulseDynamicsDerivs {6D,6D} = \t" << (total_time / NBT) << std::endl;
139  return 0;
140 }
PinocchioTicToc::toc
double toc()
Definition: timer.hpp:88
Eigen
pinocchio::python::ContactCholeskyDecomposition
ContactCholeskyDecompositionTpl< context::Scalar, context::Options > ContactCholeskyDecomposition
Definition: admm-solver.cpp:33
pinocchio::DataTpl
Definition: context/generic.hpp:25
inverse-kinematics.i
int i
Definition: inverse-kinematics.py:17
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
PinocchioTicToc::DEFAULT_UNIT
Unit DEFAULT_UNIT
Definition: timer.hpp:56
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
impulse-dynamics-derivatives.hpp
pinocchio::CONTACT_6D
@ CONTACT_6D
Point contact model.
Definition: algorithm/contact-info.hpp:22
timer.hpp
anymal-simulation.model
model
Definition: anymal-simulation.py:8
SMOOTH
#define SMOOTH(s)
Definition: timer.hpp:38
joint-configuration.hpp
pinocchio::RigidConstraintModelTpl
Definition: algorithm/constraints/fwd.hpp:14
main
int main(int argc, const char **argv)
Definition: timings-impulse-dynamics-derivatives.cpp:16
filename
filename
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::computeImpulseDynamicsDerivatives
void computeImpulseDynamicsDerivatives(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 Scalar r_coeff, const ProximalSettingsTpl< Scalar > &settings, const Eigen::MatrixBase< MatrixType1 > &dvimpulse_partial_dq, const Eigen::MatrixBase< MatrixType2 > &dvimpulse_partial_dv, const Eigen::MatrixBase< MatrixType3 > &impulse_partial_dq, const Eigen::MatrixBase< MatrixType4 > &impulse_partial_dv)
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_STD_VECTOR_WITH_EIGEN_ALLOCATOR
#define PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR(T)
Definition: container/aligned-vector.hpp:13
PinocchioTicToc::US
@ US
Definition: timer.hpp:53
cholesky.hpp
impulse-dynamics.hpp
pinocchio::impulseDynamics
const PINOCCHIO_DEPRECATED DataTpl< Scalar, Options, JointCollectionTpl >::TangentVectorType & impulseDynamics(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType > &v_before, const Eigen::MatrixBase< ConstraintMatrixType > &J, const Scalar r_coeff=0., const Scalar inv_damping=0.)
Compute the impulse dynamics with contact constraints. Internally, pinocchio::crba is called.
sample-models.hpp
pinocchio::ModelTpl
Definition: context/generic.hpp:20
PinocchioTicToc
Definition: timer.hpp:47
meshcat-viewer.qs
qs
Definition: meshcat-viewer.py:128
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27
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 Sun Dec 22 2024 03:41:12