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()
model.hpp
q2
q2
cassie-simulation.model_dir
string model_dir
Definition: cassie-simulation.py:13
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:28
pinocchio::python::buildModel
Model buildModel(const std::string &filename, const std::string &model_name)
Load a model from a Python script.
Definition: bindings/python/parsers/python/model.cpp:23
pinocchio::urdf::buildModelFromXML
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...
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:1117
pinocchio::srdf::loadRotorParameters
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...
pinocchio::urdf
URDF parsing.
urdf
Definition: types.hpp:29
pinocchio::srdf
SRDF parsing.
std
Definition: autodiff/casadi/utils/static-if.hpp:64
pinocchio::srdf::loadReferenceConfigurations
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...
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::ModelTpl
Definition: context/generic.hpp:20
pinocchio::model
JointCollectionTpl & model
Definition: joint-configuration.hpp:1116
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27
BOOST_CHECK
#define BOOST_CHECK(check)
Definition: overview-urdf.cpp:34
PINOCCHIO_MODEL_DIR
#define PINOCCHIO_MODEL_DIR
Definition: build-reduced-model.cpp:11
pinocchio::srdf::removeCollisionPairs
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...


pinocchio
Author(s):
autogenerated on Sat Jun 22 2024 02:41:50