unittest/srdf.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2016-2018 CNRS
3 //
4 
5 #include <iostream>
6 
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 =
24  + std::string("/example-robot-data/robots/romeo_description/urdf/romeo_small.urdf");
25  const string model_dir = PINOCCHIO_MODEL_DIR;
26  const string srdf_filename =
28  + std::string("/example-robot-data/robots/romeo_description/srdf/romeo.srdf");
29 
30  Model model;
31  buildModel(model_filename, model);
32 
34  vector<string> paths;
35  paths.push_back(model_dir);
36  buildGeom(model, model_filename, COLLISION, geom_model, paths);
37 
38  geom_model.addAllCollisionPairs();
39 
40  const size_t num_init_col_pairs = geom_model.collisionPairs.size();
41 
43  const size_t num_col_pairs = geom_model.collisionPairs.size();
44 
45  BOOST_CHECK(num_init_col_pairs > num_col_pairs);
46 }
47 
48 BOOST_AUTO_TEST_CASE(readReferenceConfig)
49 {
50  using namespace pinocchio::urdf;
51  using namespace pinocchio::srdf;
52  const string model_filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid.urdf");
53  const string srdf_filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid.srdf");
54 
55  Model model;
56  buildModel(model_filename, model);
57 
59  Eigen::VectorXd q = model.referenceConfigurations["half_sitting"];
60  Eigen::VectorXd q2 = model.referenceConfigurations["half_sitting2"];
61  BOOST_CHECK(q.size() == model.nq);
62  BOOST_CHECK(!q.isZero());
63 
64  BOOST_CHECK(q2.size() == model.nq);
65  BOOST_CHECK(!q2.isZero());
66 }
67 
68 BOOST_AUTO_TEST_CASE(readReferenceConfig_stream)
69 {
70  const string urdf = "<robot name='test'>"
71  "<link name='base_link'/>"
72  "<link name='child_link'/>"
73  "<joint type='revolute' name='joint'>"
74  " <parent link='base_link'/>"
75  " <child link='child_link'/>"
76  " <limit effort='30' velocity='1.0' />"
77  "</joint>"
78  "</robot>";
79  const string srdf = "<robot name='test'>"
80  "<group_state name='reference' group='all'>"
81  " <joint name='joint' value='0.0' />"
82  "</group_state>"
83  "</robot>";
84 
85  Model model;
87 
88  std::istringstream iss(srdf);
90 
91  Eigen::VectorXd q = model.referenceConfigurations["reference"];
92  Eigen::VectorXd qexpected(1);
93  qexpected << 0;
94  BOOST_CHECK(q.size() == model.nq);
95  BOOST_CHECK(q.isApprox(qexpected));
96 }
97 
98 BOOST_AUTO_TEST_CASE(test_continuous_joint)
99 {
100  const string urdf = "<robot name='test'>"
101  "<link name='base_link'/>"
102  "<link name='child_link'/>"
103  "<joint type='continuous' name='joint'>"
104  " <parent link='base_link'/>"
105  " <child link='child_link'/>"
106  " <limit effort='30' velocity='1.0' />"
107  "</joint>"
108  "</robot>";
109  const string srdf = "<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);
123  qexpected << 1, 0;
124  BOOST_CHECK(q.size() == model.nq);
125  BOOST_CHECK(q.isApprox(qexpected));
126 }
127 
128 BOOST_AUTO_TEST_CASE(readRotorParams)
129 {
130  using namespace pinocchio::urdf;
131  using namespace pinocchio::srdf;
132  const string model_filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid.urdf");
133  const string srdf_filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid.srdf");
134 
135  Model model;
136  buildModel(model_filename, model);
137 
139 
140  BOOST_CHECK(model.rotorInertia(model.joints[model.getJointId("WAIST_P")].idx_v()) == 1.0);
141  BOOST_CHECK(model.rotorGearRatio(model.joints[model.getJointId("WAIST_R")].idx_v()) == 1.0);
142 }
143 
144 BOOST_AUTO_TEST_SUITE_END()
pinocchio::python::loadReferenceConfigurations
void loadReferenceConfigurations(Model &model, const bp::object &filename, const bool verbose=false)
Definition: bindings/python/parsers/srdf.cpp:27
model.hpp
q2
q2
pinocchio::urdf::buildModelFromXML
ModelTpl< Scalar, Options, JointCollectionTpl > & buildModelFromXML(const std::string &xml_stream, 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 an XML stream with a particular joint as root of the model tree inside the model...
pinocchio::python::loadRotorParameters
bool loadRotorParameters(Model &model, const bp::object &filename, const bool verbose=false)
Definition: bindings/python/parsers/srdf.cpp:40
urdf.hpp
srdf.hpp
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(test_removeCollisionPairs)
Definition: unittest/srdf.cpp:18
collisions.srdf_filename
string srdf_filename
Definition: collisions.py:25
pinocchio::mjcf::buildGeom
GeometryModel & buildGeom(ModelTpl< Scalar, Options, JointCollectionTpl > &model, const std::string &filename, const GeometryType type, GeometryModel &geom_model, ::hpp::fcl::MeshLoaderPtr mesh_loader=::hpp::fcl::MeshLoaderPtr())
Build The GeometryModel from a Mjcf file.
append-urdf-model-with-another-model.geom_model
geom_model
Definition: append-urdf-model-with-another-model.py:26
pinocchio::q
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > & q
Definition: joint-configuration.hpp:1083
pinocchio::urdf
URDF parsing.
pinocchio::mjcf::buildModel
ModelTpl< Scalar, Options, JointCollectionTpl > & buildModel(const std::string &filename, ModelTpl< Scalar, Options, JointCollectionTpl > &model, const bool verbose=false)
Build the model from a MJCF file with a fixed joint as root of the model tree.
urdf
Definition: types.hpp:29
pinocchio::srdf
SRDF parsing.
std
Definition: autodiff/casadi/utils/static-if.hpp:64
pinocchio::srdf::loadReferenceConfigurationsFromXML
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...
pinocchio::GeometryModel
Definition: multibody/geometry.hpp:50
pinocchio::COLLISION
@ COLLISION
Definition: multibody/geometry-object.hpp:27
pinocchio::python::removeCollisionPairs
void removeCollisionPairs(const Model &model, GeometryModel &geom_model, const bp::object &filename, const bool verbose=false)
Definition: bindings/python/parsers/srdf.cpp:18
pinocchio::ModelTpl
Definition: context/generic.hpp:20
pinocchio::model
JointCollectionTpl & model
Definition: joint-configuration.hpp:1082
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27
PINOCCHIO_MODEL_DIR
#define PINOCCHIO_MODEL_DIR
Definition: build-reduced-model.cpp:11


pinocchio
Author(s):
autogenerated on Sun Dec 22 2024 03:41:12