Skip to content

Commit

Permalink
Fix bug where included URDFs are not parsed when there are no custom …
Browse files Browse the repository at this point in the history
…parsers (gazebosim#562)

gazebosim#475 introduced a regression where included URDFs were being silently ignored when there are no custom parsers available. This returns the behavior back to URDFs being parsed natively by SDFormat if there are no custom parsers.

Signed-off-by: Addisu Z. Taddese <[email protected]>
  • Loading branch information
azeey authored May 5, 2021
1 parent bed1589 commit e5ca000
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ bool readXml(tinyxml2::XMLElement *_xml, ElementPtr _sdf,
// If the file is not an SDFormat file, it is assumed that it will
// handled by a custom parser, so fall through and add the include
// element into _sdf.
if (sdf::isSdfFile(filename))
if (sdf::isSdfFile(filename) || _config.CustomModelParsers().empty())
{
// NOTE: sdf::init is an expensive call. For performance reason,
// a new sdf pointer is created here by cloning a fresh sdf template
Expand Down
27 changes: 27 additions & 0 deletions test/integration/includes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,30 @@ TEST(IncludesTest, IncludeModelMissingConfig)

EXPECT_EQ(nullptr, root.Model());
}

//////////////////////////////////////////////////
/// Check that sdformat natively parses URDF files when there are no custom
/// parsers
TEST(IncludesTest, IncludeUrdf)
{
sdf::setFindCallback(findFileCb);

std::ostringstream stream;
stream
<< "<sdf version='" << SDF_VERSION << "'>"
<< "<include>"
<< " <uri>test_include_urdf</uri>"
<< "</include>"
<< "</sdf>";

sdf::Root root;
sdf::Errors errors = root.LoadSdfString(stream.str());
ASSERT_TRUE(errors.empty()) << errors;

auto model = root.Model();
ASSERT_NE(nullptr, model);
EXPECT_EQ("test_include_urdf", model->Name());
EXPECT_EQ(2u, model->LinkCount());
EXPECT_EQ(1u, model->JointCount());
}

6 changes: 6 additions & 0 deletions test/integration/model/test_include_urdf/model.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>

<model>
<name>test_include_urdf</name>
<sdf version="1.6">model.urdf</sdf>
</model>
27 changes: 27 additions & 0 deletions test/integration/model/test_include_urdf/model.urdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" ?>
<robot name="test_include_urdf">

<link name="base_link">
<inertial>
<mass value="1"/>
<inertia ixx="1" ixy="0" ixz="0" iyy="1" iyz="0" izz="1"/>
</inertial>
</link>

<joint name="joint_1" type="revolute">
<parent link="base_link"/>
<child link="link_1"/>
<axis xyz="0 0 1"/>
<limit effort="1" lower="-1" upper="1" velocity="1"/>
</joint>

<link name="link_1">
<inertial>
<mass value="1"/>
<inertia ixx="1" ixy="0" ixz="0" iyy="1" iyz="0" izz="1"/>
</inertial>
</link>

</robot>


0 comments on commit e5ca000

Please sign in to comment.