timings-geometry.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2015-2019 CNRS INRIA
3 //
4 
5 #include "pinocchio/algorithm/joint-configuration.hpp"
6 #include "pinocchio/algorithm/kinematics.hpp"
7 #include "pinocchio/algorithm/geometry.hpp"
8 #include "pinocchio/parsers/urdf.hpp"
9 #include "pinocchio/parsers/sample-models.hpp"
10 #include "pinocchio/multibody/geometry.hpp"
11 #include "pinocchio/utils/timer.hpp"
12 
13 #include <iostream>
14 #include <Eigen/StdVector>
15 
16 EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(Eigen::VectorXd)
17 
18 int main()
19 {
20  using namespace Eigen;
21  using namespace pinocchio;
22 
24  #ifdef NDEBUG
25  const unsigned int NBT = 1000*100;
26  const unsigned int NBD = 1000; // for heavy tests, like computeDistances()
27  #else
28  const unsigned int NBT = 1;
29  const unsigned int NBD = 1;
30  std::cout << "(the time score in debug mode is not relevant) " << std::endl;
31  #endif
32 
33  std::string romeo_filename = PINOCCHIO_MODEL_DIR + std::string("/others/robots/romeo_description/urdf/romeo_small.urdf");
34  std::vector < std::string > package_dirs;
35  std::string romeo_meshDir = PINOCCHIO_MODEL_DIR + std::string("/others/robots");
36  package_dirs.push_back(romeo_meshDir);
37 
40  pinocchio::GeometryModel geom_model; pinocchio::urdf::buildGeom(model, romeo_filename, COLLISION, geom_model, package_dirs);
41 #ifdef PINOCCHIO_WITH_HPP_FCL
42  geom_model.addAllCollisionPairs();
43 #endif // PINOCCHIO_WITH_HPP_FCL
44 
45  Data data(model);
46  GeometryData geom_data(geom_model);
47  VectorXd qmax = Eigen::VectorXd::Ones(model.nq);
48 
49 
50  std::vector<VectorXd> qs_romeo (NBT);
51  std::vector<VectorXd> qdots_romeo (NBT);
52  std::vector<VectorXd> qddots_romeo (NBT);
53  for(size_t i=0;i<NBT;++i)
54  {
55  qs_romeo[i] = randomConfiguration(model,-qmax,qmax);
56  qdots_romeo[i] = Eigen::VectorXd::Random(model.nv);
57  qddots_romeo[i] = Eigen::VectorXd::Random(model.nv);
58  }
59 
60  timer.tic();
61  SMOOTH(NBT)
62  {
63  forwardKinematics(model,data,qs_romeo[_smooth]);
64  }
65  double geom_time = timer.toc(PinocchioTicToc::US)/NBT;
66 
67  timer.tic();
68  SMOOTH(NBT)
69  {
70  updateGeometryPlacements(model,data,geom_model,geom_data,qs_romeo[_smooth]);
71  }
72  double update_col_time = timer.toc(PinocchioTicToc::US)/NBT - geom_time;
73  std::cout << "Update Collision Geometry < false > = \t" << update_col_time << " " << PinocchioTicToc::unitName(PinocchioTicToc::US) << std::endl;
74 
75 #ifdef PINOCCHIO_WITH_HPP_FCL
76  timer.tic();
77  SMOOTH(NBT)
78  {
79  updateGeometryPlacements(model,data,geom_model,geom_data,qs_romeo[_smooth]);
80  for (std::vector<pinocchio::CollisionPair>::iterator it = geom_model.collisionPairs.begin(); it != geom_model.collisionPairs.end(); ++it)
81  {
82  computeCollision(geom_model,geom_data,std::size_t(it-geom_model.collisionPairs.begin()));
83  }
84  }
85  double collideTime = timer.toc(PinocchioTicToc::US)/NBT - (update_col_time + geom_time);
86  std::cout << "Collision test between two geometry objects (mean time) = \t" << collideTime / double(geom_model.collisionPairs.size())
88 
89 
90  timer.tic();
91  SMOOTH(NBT)
92  {
93  computeCollisions(geom_model,geom_data, true);
94  }
95  double is_colliding_time = timer.toc(PinocchioTicToc::US)/NBT - (update_col_time + geom_time);
96  std::cout << "Collision Test : robot in collision? = \t" << is_colliding_time
98 
99 
100  timer.tic();
101  SMOOTH(NBD)
102  {
103  computeDistances(model,data,geom_model,geom_data,qs_romeo[_smooth]);
104  }
105  double computeDistancesTime = timer.toc(PinocchioTicToc::US)/NBD - (update_col_time + geom_time);
106  std::cout << "Compute distance between two geometry objects (mean time) = \t" << computeDistancesTime / double(geom_model.collisionPairs.size())
107  << " " << PinocchioTicToc::unitName(PinocchioTicToc::US) << " " << geom_model.collisionPairs.size() << " col pairs" << std::endl;
108 
109 #endif // PINOCCHIO_WITH_HPP_FCL
110 
111  return 0;
112 }
double toc()
Definition: timer.hpp:68
static std::string unitName(Unit u)
Definition: timer.hpp:52
CollisionPairVector collisionPairs
Vector of collision pairs.
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.
data
#define PINOCCHIO_MODEL_DIR
void tic()
Definition: timer.hpp:63
bool computeCollisions(const int num_threads, const GeometryModel &geom_model, GeometryData &geom_data, const bool stopAtFirstCollision=false)
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.
#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...
GeometryModel & buildGeom(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const std::string &filename, const GeometryType type, GeometryModel &geom_model, const std::vector< std::string > &package_paths=std::vector< std::string >(),::hpp::fcl::MeshLoaderPtr mesh_loader=::hpp::fcl::MeshLoaderPtr())
Build The GeometryModel from a URDF file. Search for meshes in the directories specified by the user ...
int main()
void addAllCollisionPairs()
Add all possible collision pairs.
Main pinocchio namespace.
Definition: timings.cpp:30
int nv
Dimension of the velocity vector space.
void updateGeometryPlacements(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const GeometryModel &geom_model, GeometryData &geom_data, const Eigen::MatrixBase< ConfigVectorType > &q)
Apply a forward kinematics and update the placement of the geometry objects.
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > VectorXd
Definition: conversions.cpp:14
int nq
Dimension of the configuration vector representation.


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