5 #include "pinocchio/algorithm/parallel/rnea.hpp" 6 #include "pinocchio/algorithm/parallel/aba.hpp" 7 #include "pinocchio/algorithm/joint-configuration.hpp" 8 #include "pinocchio/parsers/sample-models.hpp" 10 #ifdef PINOCCHIO_WITH_HPP_FCL 11 #include "pinocchio/algorithm/parallel/geometry.hpp" 14 #include "pinocchio/parsers/urdf.hpp" 15 #include "pinocchio/parsers/srdf.hpp" 16 #include "pinocchio/parsers/sample-models.hpp" 20 #include "pinocchio/utils/timer.hpp" 22 #include <Eigen/StdVector> 25 int
main(
int , const
char ** )
27 using namespace Eigen;
30 typedef Eigen::Matrix<bool,Eigen::Dynamic,1>
VectorXb;
39 std::cout <<
"(the time score in debug mode is not relevant) " << std::endl;
43 const int NUM_THREADS = omp_get_max_threads();
45 const std::string filename =
PINOCCHIO_MODEL_DIR + std::string(
"/example-robot-data/robots/talos_data/robots/talos_reduced.urdf");
50 std::cout <<
"nq = " << model.
nq << std::endl;
51 std::cout <<
"nv = " << model.
nv << std::endl;
52 std::cout <<
"name = " << model.
name << std::endl;
54 #ifdef PINOCCHIO_WITH_HPP_FCL 56 hpp::fcl::MeshLoaderPtr mesh_loader = boost::make_shared<hpp::fcl::CachedMeshLoader>();
58 std::vector<std::string> package_paths(1,package_path);
67 int num_active_collision_pairs = 0;
71 num_active_collision_pairs++;
73 std::cout <<
"active collision pairs = " << num_active_collision_pairs << std::endl;
77 std::cout <<
"--" << std::endl;
78 std::cout <<
"NUM_THREADS: " << NUM_THREADS << std::endl;
79 std::cout <<
"BATCH_SIZE: " << BATCH_SIZE << std::endl;
80 std::cout <<
"--" << std::endl;
83 const VectorXd qmax = Eigen::VectorXd::Ones(model.
nq);
85 MatrixXd qs(model.
nq,BATCH_SIZE);
86 MatrixXd vs(model.
nv,BATCH_SIZE);
87 MatrixXd as(model.
nv,BATCH_SIZE);
88 MatrixXd taus(model.
nv,BATCH_SIZE);
89 MatrixXd
res(model.
nv,BATCH_SIZE);
94 for(
size_t i=0;
i < NBT; ++
i)
102 vs.col(
i) = Eigen::VectorXd::Random(model.
nv);
103 as.col(
i) = Eigen::VectorXd::Random(model.
nv);
104 taus.col(
i) = Eigen::VectorXd::Random(model.
nv);
113 res.col(
i) =
rnea(model,data,qs.col(
i),vs.col(
i),as.col(
i));
115 std::cout <<
"mean RNEA = \t\t\t\t"; timer.
toc(std::cout,NBT*BATCH_SIZE);
125 std::stringstream ss;
126 ss <<
"mean RNEA pool (";
128 ss <<
" threads) = \t\t";
129 ss << elapsed <<
" us" << std::endl;
130 std::cout << ss.str();
133 std::cout <<
"--" << std::endl;
139 res.col(
i) =
aba(model,data,qs.col(
i),vs.col(
i),taus.col(
i));
141 std::cout <<
"mean ABA = \t\t\t\t"; timer.
toc(std::cout,NBT*BATCH_SIZE);
151 std::stringstream ss;
152 ss <<
"mean ABA pool (";
154 ss <<
" threads) = \t\t";
155 ss << elapsed <<
" us" << std::endl;
156 std::cout << ss.str();
159 #ifdef PINOCCHIO_WITH_HPP_FCL 160 std::cout <<
"--" << std::endl;
161 const int NBT_COLLISION =
math::max(NBT,1);
163 SMOOTH((
size_t)NBT_COLLISION)
167 std::cout <<
"non parallel collision = \t\t\t"; timer.
toc(std::cout,NBT_COLLISION);
172 SMOOTH((
size_t)NBT_COLLISION)
176 double elapsed = timer.
toc()/(NBT_COLLISION);
177 std::stringstream ss;
178 ss <<
"parallel collision (";
180 ss <<
" threads) = \t\t";
181 ss << elapsed <<
" us" << std::endl;
182 std::cout << ss.str();
185 std::cout <<
"--" << std::endl;
186 GeometryPool geometry_pool(model,geometry_model,NUM_THREADS);
187 VectorXb collision_res(BATCH_SIZE);
188 collision_res.fill(
false);
191 SMOOTH((
size_t)(NBT_COLLISION/BATCH_SIZE))
196 std::cout <<
"non parallel collision = \t\t\t"; timer.
toc(std::cout,NBT_COLLISION);
201 SMOOTH((
size_t)(NBT_COLLISION/BATCH_SIZE))
205 double elapsed = timer.
toc()/(NBT_COLLISION);
206 std::stringstream ss;
207 ss <<
"pool parallel collision (";
209 ss <<
" threads) = \t\t";
210 ss << elapsed <<
" us" << std::endl;
211 std::cout << ss.str();
215 std::cout <<
"--" << std::endl;
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)
The Articulated-Body algorithm. It computes the forward dynamics, aka the joint accelerations given t...
int main(int, const char **)
void removeCollisionPairs(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, GeometryModel &geom_model, const std::string &filename, const bool verbose=false)
Deactive all possible collision pairs mentioned in the SRDF file. It throws if the SRDF file is incor...
void rnea(const int num_threads, ModelPoolTpl< Scalar, Options, JointCollectionTpl > &pool, const Eigen::MatrixBase< ConfigVectorPool > &q, const Eigen::MatrixBase< TangentVectorPool1 > &v, const Eigen::MatrixBase< TangentVectorPool2 > &a, const Eigen::MatrixBase< TangentVectorPool3 > &tau)
The Recursive Newton-Euler algorithm. It computes the inverse dynamics, aka the joint torques accordi...
AD< Scalar > max(const AD< Scalar > &x, const AD< Scalar > &y)
std::vector< bool > activeCollisionPairs
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.
#define PINOCCHIO_MODEL_DIR
bool computeCollisions(const int num_threads, const GeometryModel &geom_model, GeometryData &geom_data, const bool stopAtFirstCollision=false)
std::string name
Model name;.
Eigen::Matrix< bool, Eigen::Dynamic, 1 > VectorXb
#define PINOCCHIO_ALIGNED_STD_VECTOR(Type)
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 ...
void addAllCollisionPairs()
Add all possible collision pairs.
Main pinocchio namespace.
int nv
Dimension of the velocity vector space.
JointModelFreeFlyerTpl< double > JointModelFreeFlyer
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > VectorXd
int nq
Dimension of the configuration vector representation.