unittest/srdf.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2016-2021 CNRS INRIA
3 //
4 
5 #include <iostream>
6 
7 #include "pinocchio/multibody/model.hpp"
8 #include "pinocchio/parsers/urdf.hpp"
9 #include "pinocchio/parsers/srdf.hpp"
10 
11 #include <boost/test/unit_test.hpp>
12 
13 using namespace pinocchio;
14 using namespace std;
15 
16 BOOST_AUTO_TEST_SUITE ( BOOST_TEST_MODULE )
17 
18 BOOST_AUTO_TEST_CASE(test_removeCollisionPairs)
19 {
20  using namespace pinocchio::urdf;
21  using namespace pinocchio::srdf;
22  const string model_filename = PINOCCHIO_MODEL_DIR + std::string("/example-robot-data/robots/romeo_description/urdf/romeo_small.urdf");
23  const string model_dir = PINOCCHIO_MODEL_DIR;
24  const string srdf_filename = PINOCCHIO_MODEL_DIR + std::string("/example-robot-data/robots/romeo_description/srdf/romeo.srdf");
25 
26  Model model;
27  buildModel(model_filename, model);
28 
30  vector<string> paths; paths.push_back(model_dir);
31  buildGeom(model,model_filename,COLLISION,geom_model,paths);
32 
33  geom_model.addAllCollisionPairs();
34 
35  const size_t num_init_col_pairs = geom_model.collisionPairs.size();
36 
37  removeCollisionPairs(model,geom_model,srdf_filename,false);
38  const size_t num_col_pairs = geom_model.collisionPairs.size();
39 
40  BOOST_CHECK(num_init_col_pairs > num_col_pairs);
41 }
42 
43 BOOST_AUTO_TEST_CASE(readReferenceConfig)
44 {
45  using namespace pinocchio::urdf;
46  using namespace pinocchio::srdf;
47  const string model_filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid.urdf");
48  const string srdf_filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid.srdf");
49 
50  Model model;
51  buildModel(model_filename, model);
52 
53  loadReferenceConfigurations(model,srdf_filename,false);
54  Eigen::VectorXd q = model.referenceConfigurations["half_sitting"];
55  Eigen::VectorXd q2 = model.referenceConfigurations["half_sitting2"];
56  BOOST_CHECK(q.size() == model.nq);
57  BOOST_CHECK(!q.isZero());
58 
59  BOOST_CHECK(q2.size() == model.nq);
60  BOOST_CHECK(!q2.isZero());
61 
62 
63 }
64 
65 BOOST_AUTO_TEST_CASE(readReferenceConfig_stream)
66 {
67  const string urdf =
68  "<robot name='test'>"
69  "<link name='base_link'/>"
70  "<link name='child_link'/>"
71  "<joint type='revolute' name='joint'>"
72  " <parent link='base_link'/>"
73  " <child link='child_link'/>"
74  " <limit effort='30' velocity='1.0' />"
75  "</joint>"
76  "</robot>";
77  const string srdf =
78  "<robot name='test'>"
79  "<group_state name='reference' group='all'>"
80  " <joint name='joint' value='0.0' />"
81  "</group_state>"
82  "</robot>";
83 
84  Model model;
86 
87  std::istringstream iss (srdf);
89 
90  Eigen::VectorXd q = model.referenceConfigurations["reference"];
91  Eigen::VectorXd qexpected(1); qexpected << 0;
92  BOOST_CHECK(q.size() == model.nq);
93  BOOST_CHECK(q.isApprox(qexpected));
94 }
95 
96 BOOST_AUTO_TEST_CASE(test_continuous_joint)
97 {
98  const string urdf =
99  "<robot name='test'>"
100  "<link name='base_link'/>"
101  "<link name='child_link'/>"
102  "<joint type='continuous' name='joint'>"
103  " <parent link='base_link'/>"
104  " <child link='child_link'/>"
105  " <limit effort='30' velocity='1.0' />"
106  "</joint>"
107  "</robot>";
108  const string srdf =
109  "<robot name='test'>"
110  "<group_state name='reference' group='all'>"
111  " <joint name='joint' value='0.0' />"
112  "</group_state>"
113  "</robot>";
114 
115  Model model;
117 
118  std::istringstream iss (srdf);
120 
121  Eigen::VectorXd q = model.referenceConfigurations["reference"];
122  Eigen::VectorXd qexpected(2); qexpected << 1,0;
123  BOOST_CHECK(q.size() == model.nq);
124  BOOST_CHECK(q.isApprox(qexpected));
125 }
126 
127 BOOST_AUTO_TEST_CASE(readRotorParams)
128 {
129  using namespace pinocchio::urdf;
130  using namespace pinocchio::srdf;
131  const string model_filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid.urdf");
132  const string srdf_filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid.srdf");
133 
134  Model model;
135  buildModel(model_filename, model);
136 
137  loadRotorParameters(model,srdf_filename,false);
138 
139  BOOST_CHECK(model.rotorInertia(model.joints[model.getJointId("WAIST_P")].idx_v())==1.0);
140  BOOST_CHECK(model.rotorGearRatio(model.joints[model.getJointId("WAIST_R")].idx_v())==1.0);
141 }
142 
143 BOOST_AUTO_TEST_SUITE_END()
void loadReferenceConfigurations(ModelTpl< Scalar, Options, JointCollectionTpl > &model, const std::string &filename, const bool verbose=false)
Get the reference configurations of a given model associated to a SRDF file. It throws if the SRDF fi...
JointModelVector joints
Model of joint i, encapsulated in a JointModelAccessor.
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...
CollisionPairVector collisionPairs
Vector of collision pairs.
TangentVectorType rotorInertia
Vector of rotor inertia parameters.
#define PINOCCHIO_MODEL_DIR
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > & q
ConfigVectorMap referenceConfigurations
Map of reference configurations, indexed by user given names.
TangentVectorType rotorGearRatio
Vector of rotor gear ratio parameters.
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 ...
bool loadRotorParameters(ModelTpl< Scalar, Options, JointCollectionTpl > &model, const std::string &filename, const bool verbose=false)
Load the rotor params of a given model associated to a SRDF file. It throws if the SRDF file is incor...
Definition: types.hpp:29
void loadReferenceConfigurationsFromXML(ModelTpl< Scalar, Options, JointCollectionTpl > &model, std::istream &xmlStream, const bool verbose=false)
Get the reference configurations of a given model associated to a SRDF file. It throws if the SRDF fi...
void addAllCollisionPairs()
Add all possible collision pairs.
string srdf_filename
Definition: collisions.py:25
SRDF parsing.
Model buildModel(const std::string &filename, const std::string &model_name)
Load a model from a Python script.
Main pinocchio namespace.
Definition: timings.cpp:28
q2
URDF parsing.
JointIndex getJointId(const std::string &name) const
Return the index of a joint given by its name.
ModelTpl< Scalar, Options, JointCollectionTpl > & buildModelFromXML(const std::string &xml_stream, const typename ModelTpl< Scalar, Options, JointCollectionTpl >::JointModel &rootJoint, ModelTpl< Scalar, Options, JointCollectionTpl > &model, const bool verbose=false)
Build the model from an XML stream with a particular joint as root of the model tree inside the model...
BOOST_AUTO_TEST_CASE(test_removeCollisionPairs)
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > VectorXd
Definition: conversions.cpp:14
JointCollectionTpl & model
int nq
Dimension of the configuration vector representation.


pinocchio
Author(s):
autogenerated on Fri Jun 23 2023 02:38:32