timings-impulse-dynamics.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 CNRS INRIA
3 //
4 
18 
19 #include <iostream>
20 
22 
23 int main(int argc, const char ** argv)
24 {
25  using namespace Eigen;
26  using namespace pinocchio;
27 
29 #ifdef NDEBUG
30  const int NBT = 1000 * 100;
31 #else
32  const int NBT = 1;
33  std::cout << "(the time score in debug mode is not relevant) " << std::endl;
34 #endif
35 
36  // Build model
37  Model model;
38 
39  std::string filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid.urdf");
40  if (argc > 1)
41  filename = argv[1];
42  bool with_ff = true;
43 
44  if (argc > 2)
45  {
46  const std::string ff_option = argv[2];
47  if (ff_option == "-no-ff")
48  with_ff = false;
49  }
50 
51  if (filename == "HS")
53  else if (with_ff)
55  // pinocchio::urdf::buildModel(filename,JointModelRX(),model);
56  else
58 
59  const std::string RA = "RARM_LINK6";
60  const std::string LA = "LARM_LINK6";
61  const std::string RF = "RLEG_LINK6";
62  const std::string LF = "LLEG_LINK6";
63 
64  RigidConstraintModel ci_RF_6D(CONTACT_6D, model.getFrameId(RF), WORLD);
65  RigidConstraintModel ci_RF_3D(CONTACT_3D, model.getFrameId(RF), WORLD);
66 
67  RigidConstraintModel ci_LF_6D(CONTACT_6D, model.getFrameId(LF), WORLD);
68  RigidConstraintModel ci_LF_3D(CONTACT_3D, model.getFrameId(LF), WORLD);
69 
70  RigidConstraintModel ci_RA_3D(CONTACT_3D, model.getFrameId(RA), WORLD);
71  RigidConstraintModel ci_LA_3D(CONTACT_3D, model.getFrameId(LA), WORLD);
72 
73  // Define contact infos structure
74  static const PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR(RigidConstraintModel) contact_models_empty;
76  cholesky::ContactCholeskyDecomposition contact_chol_empty(model, contact_models_empty);
77 
79  contact_models_6D.push_back(ci_RF_6D);
81  contact_data_6D.push_back(RigidConstraintData(ci_RF_6D));
82  cholesky::ContactCholeskyDecomposition contact_chol_6D(model, contact_models_6D);
83 
85  contact_models_6D6D.push_back(ci_RF_6D);
86  contact_models_6D6D.push_back(ci_LF_6D);
88  contact_data_6D6D.push_back(RigidConstraintData(ci_RF_6D));
89  contact_data_6D6D.push_back(RigidConstraintData(ci_LF_6D));
90  cholesky::ContactCholeskyDecomposition contact_chol_6D6D(model, contact_models_6D6D);
91 
93  prox_settings.max_iter = 10;
94  prox_settings.mu = 1e8;
95 
96  std::cout << "nq = " << model.nq << std::endl;
97  std::cout << "nv = " << model.nv << std::endl;
98  std::cout << "--" << std::endl;
99 
100  Data data(model);
101  VectorXd qmax = Eigen::VectorXd::Ones(model.nq);
102 
104  PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR(VectorXd) qdots(NBT);
105  PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR(VectorXd) qddots(NBT);
106  PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR(VectorXd) taus(NBT);
107 
109 
110  for (size_t i = 0; i < NBT; ++i)
111  {
112  qs[i] = randomConfiguration(model, -qmax, qmax);
113  qdots[i] = Eigen::VectorXd::Random(model.nv);
114  qddots[i] = Eigen::VectorXd::Random(model.nv);
115  }
116  Eigen::ArrayXd r_coeffs = (Eigen::ArrayXd::Random(NBT) + 1.) / 2.;
117 
118  initConstraintDynamics(model, data, contact_models_empty);
119  timer.tic();
120  SMOOTH(NBT)
121  {
123  model, data, qs[_smooth], qdots[_smooth], contact_models_empty, contact_data_empty,
124  r_coeffs[(Eigen::Index)_smooth]);
125  }
126  std::cout << "impulseDynamics {} = \t\t";
127  timer.toc(std::cout, NBT);
128 
129  initConstraintDynamics(model, data, contact_models_6D);
130  timer.tic();
131  SMOOTH(NBT)
132  {
134  model, data, qs[_smooth], qdots[_smooth], contact_models_6D, contact_data_6D,
135  r_coeffs[(Eigen::Index)_smooth]);
136  }
137  std::cout << "impulseDynamics {6D} = \t\t";
138  timer.toc(std::cout, NBT);
139 
140  initConstraintDynamics(model, data, contact_models_6D6D);
141  timer.tic();
142  SMOOTH(NBT)
143  {
145  model, data, qs[_smooth], qdots[_smooth], contact_models_6D6D, contact_data_6D6D,
146  r_coeffs[(Eigen::Index)_smooth]);
147  }
148  std::cout << "impulseDynamics {6D,6D} = \t\t";
149  timer.toc(std::cout, NBT);
150 
151  Eigen::MatrixXd J(Eigen::MatrixXd::Zero(12, model.nv));
152  timer.tic();
153  SMOOTH(NBT)
154  {
155  crba(model, data, qs[_smooth], Convention::WORLD);
156  getFrameJacobian(model, data, ci_RF_6D.frame_id, ci_RF_6D.reference_frame, J.middleRows<6>(0));
157  getFrameJacobian(model, data, ci_LF_6D.frame_id, ci_LF_6D.reference_frame, J.middleRows<6>(6));
158  impulseDynamics(model, data, qdots[_smooth], J, r_coeffs[(Eigen::Index)_smooth]);
159  }
160  std::cout << "constrained impulseDynamics {6D,6D} = \t\t";
161  timer.toc(std::cout, NBT);
162 
163  std::cout << "--" << std::endl;
164 
165  return 0;
166 }
pinocchio::RigidConstraintData
RigidConstraintDataTpl< context::Scalar, context::Options > RigidConstraintData
Definition: algorithm/fwd.hpp:27
pinocchio::WORLD
@ WORLD
Definition: multibody/fwd.hpp:48
frames.hpp
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
pinocchio::getFrameJacobian
void getFrameJacobian(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const JointIndex joint_id, const SE3Tpl< Scalar, Options > &placement, const ReferenceFrame reference_frame, const Eigen::MatrixBase< Matrix6xLike > &J)
Returns the jacobian of the frame given by its relative placement w.r.t. a joint frame,...
inverse-kinematics.i
int i
Definition: inverse-kinematics.py:17
kinematics.hpp
rnea-derivatives.hpp
setup.data
data
Definition: cmake/cython/setup.in.py:48
inverse-kinematics-3d.J
J
Definition: inverse-kinematics-3d.py:28
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::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
aba-derivatives.hpp
timer.hpp
aba.hpp
pinocchio::Index
PINOCCHIO_COMPILER_DIAGNOSTIC_POP typedef std::size_t Index
Definition: multibody/fwd.hpp:22
anymal-simulation.model
model
Definition: anymal-simulation.py:8
SMOOTH
#define SMOOTH(s)
Definition: timer.hpp:38
main
int main(int argc, const char **argv)
Definition: timings-impulse-dynamics.cpp:23
joint-configuration.hpp
pinocchio::ProximalSettingsTpl
Structure containing all the settings parameters for the proximal algorithms.
Definition: algorithm/fwd.hpp:13
pinocchio::RigidConstraintModelTpl
Definition: algorithm/constraints/fwd.hpp:14
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::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
kinematics-derivatives.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.
contact-cholesky.contact_models
list contact_models
Definition: contact-cholesky.py:22
sample-models.hpp
pinocchio::ModelTpl
Definition: context/generic.hpp:20
simulation-closed-kinematic-chains.prox_settings
prox_settings
Definition: simulation-closed-kinematic-chains.py:163
crba.hpp
pinocchio::CONTACT_3D
@ CONTACT_3D
Definition: algorithm/contact-info.hpp:21
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
Author(s):
autogenerated on Thu Dec 19 2024 03:41:33