Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate poses of nested models inside other nested models (sdf6) #596

Merged
merged 4 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ void addNestedModel(ElementPtr _sdf, ElementPtr _includeSDF)
replace[elemName] = newName;
}

if (elem->GetName() == "link")
if ((elem->GetName() == "link") || (elem->GetName() == "model"))
{
if (elem->HasElementDescription("pose"))
{
Expand Down
60 changes: 60 additions & 0 deletions test/integration/frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1255,3 +1255,63 @@ TEST(Frame, IncludeFrame)
EXPECT_EQ(modelPoseElem->Get<ignition::math::Pose3d>(),
ignition::math::Pose3d(5, -2, 1, 0, 0, 0));
}

////////////////////////////////////////
// Test parsing a include element that has a pose element and includes a
// submodel
TEST(Frame, IncludeFrameWithSubmodel)
{
const std::string MODEL_PATH =
sdf::filesystem::append(PROJECT_SOURCE_PATH, "test", "integration",
"model", "box_with_submodel");

std::ostringstream stream;
std::string version = SDF_VERSION;
stream
<< "<sdf version='" << version << "'>"
<< "<world name='default'>"
<< "<model name='top_level_model'>"
<< " <include>"
<< " <static>false</static>"
<< " <pose>5 5 0 0 0 0</pose>"
<< " <uri>" + MODEL_PATH +"</uri>"
<< " </include>"
<< "</model>"
<< "</world>"
<< "</sdf>";

sdf::SDFPtr sdfParsed(new sdf::SDF());
sdf::init(sdfParsed);
ASSERT_TRUE(sdf::readString(stream.str(), sdfParsed));
sdf::ElementPtr worldElem = sdfParsed->Root()->GetElement("world");

/* top level model: using include will merge top_level_model and box_with_submodel into:
* <model name='top_level_model'>
* <link name='box_with_submodel::link'>
* <pose frame=''>5 5 0 0 -0 0</pose> <<-- pose has been translated
* </link>
* <model name='box_with_submodel::submodel_box_with_submodel'>
* ...
* </model>
* </model>
*/
sdf::ElementPtr modelElem = worldElem->GetElement("model");
EXPECT_EQ(modelElem->Get<std::string>("name"), "top_level_model");
sdf::ElementPtr modelPoseElem = modelElem->GetElement("link")->GetElement("pose");
EXPECT_EQ(modelPoseElem->Get<ignition::math::Pose3d>(),
ignition::math::Pose3d(5, 5, 0, 0, 0, 0));
/* submodel: pose from parent is translated to model. links are the same
* ...
* <model name='box_with_submodel::submodel_box_with_submodel'>
* <link name='submodel_link'>
* <pose frame=''>0 0 0 0 -0 0</pose>
* </link>
* <pose frame=''>5 5 0 0 -0 0</pose>
* </model>
*/
sdf::ElementPtr subModelElem = modelElem->GetElement("model");
EXPECT_EQ(subModelElem->Get<std::string>("name"), "box_with_submodel::submodel_of_box_with_submodel");
sdf::ElementPtr subModelPoseElem = subModelElem->GetElement("pose");
EXPECT_EQ(subModelPoseElem->Get<ignition::math::Pose3d>(),
ignition::math::Pose3d(5, 5, 0, 0, 0, 0));
}
15 changes: 15 additions & 0 deletions test/integration/model/box_with_submodel/model.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<model>
<name>BoxWithSubmodel</name>
<version>1.0</version>
<sdf version="1.6">model.sdf</sdf>

<author>
<name>Jose Luis Rivero</name>
<email>[email protected]</email>
</author>

<description>
A box with a nested model
</description>
</model>
13 changes: 13 additions & 0 deletions test/integration/model/box_with_submodel/model.sdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" ?>
<sdf version="1.6">
<model name="box_with_submodel">
<link name="link">
<pose>0 0 0 0 0 0</pose>
</link>
<model name="submodel_of_box_with_submodel">
<link name="submodel_link">
<pose>0 0 0 0 0 0</pose>
</link>
</model>
</model>
</sdf>