Skip to content
Closed
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
44 changes: 44 additions & 0 deletions sdf/1.12/1_11.convert
Original file line number Diff line number Diff line change
@@ -1,2 +1,46 @@
<convert name="sdf">

<convert name="world">
<!-- Rename state elements -->
<convert name="state">

<move>
<from element="light"/>
<to element="light_state"/>
</move>

<move>
<from element="model"/>
<to element="model_state"/>
</move>

<convert name="model">
<move>
<from element="link"/>
<to element="link_state"/>
</move>
<move>
<from element="model"/>
<to element="model_state"/>
</move>
<convert name="model">
<move>
<from element="link"/>
<to element="link_state"/>
</move>
<move>
<from element="model"/>
<to element="model_state"/>
</move>
<convert name="model">
<move>
<from element="link"/>
<to element="link_state"/>
</move>
</convert>
</convert>
</convert>

</convert>
</convert>
</convert> <!-- End SDF -->
2 changes: 1 addition & 1 deletion sdf/1.12/light_state.sdf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- State information for a light -->
<element name="light" required="*">
<element name="light_state" required="*">
<description>Light state</description>

<attribute name="name" type="string" default="__default__" required="1">
Expand Down
4 changes: 2 additions & 2 deletions sdf/1.12/link_state.sdf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- State information for a link -->
<element name="link" required="*">
<element name="link_state" required="*">
<description>Link state</description>

<attribute name="name" type="string" default="__default__" required="1">
Expand Down Expand Up @@ -27,7 +27,7 @@
</description>
</element>

<element name="collision" required="*">
<element name="collision_state" required="*">
<description>Collision state</description>

<attribute name="name" type="string" default="__default__" required="1">
Expand Down
6 changes: 3 additions & 3 deletions sdf/1.12/model_state.sdf
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!-- State information for a model -->
<element name="model" required="*">
<element name="model_state" required="*">
<description>Model state</description>

<attribute name="name" type="string" default="__default__" required="1">
<description>Name of the model</description>
</attribute>

<element name="joint" required="*">
<element name="joint_state" required="*">
<description>Joint angle</description>

<attribute name="name" type="string" default="__default__" required="1">
Expand All @@ -22,7 +22,7 @@
</element>
</element>

<element name="model" ref="model_state" required="*">
<element name="model_state" ref="model_state" required="*">
<description>A nested model state element</description>
<attribute name="name" type="string" default="__default__" required="1">
<description>Name of the model. </description>
Expand Down
16 changes: 8 additions & 8 deletions test/integration/frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ TEST(Frame, NoFrame)
}

////////////////////////////////////////
// Test parsing nested model states
// Test parsing states with //pose/@relative_to
TEST(Frame, StateFrame)
{
std::ostringstream sdfStr;
sdfStr << "<sdf version ='" << SDF_VERSION << "'>"
sdfStr << "<sdf version ='1.11'>"
<< "<world name='default'>"
<< "<state world_name='default'>"
<< "<model name='my_model'>"
Expand Down Expand Up @@ -239,8 +239,8 @@ TEST(Frame, StateFrame)
EXPECT_TRUE(worldElem->HasElement("state"));
sdf::ElementPtr stateElem = worldElem->GetElement("state");

EXPECT_TRUE(stateElem->HasElement("model"));
sdf::ElementPtr modelStateElem = stateElem->GetElement("model");
EXPECT_TRUE(stateElem->HasElement("model_state"));
sdf::ElementPtr modelStateElem = stateElem->GetElement("model_state");

// model
EXPECT_TRUE(modelStateElem->HasAttribute("name"));
Expand Down Expand Up @@ -271,8 +271,8 @@ TEST(Frame, StateFrame)
}

// link
EXPECT_TRUE(modelStateElem->HasElement("link"));
sdf::ElementPtr linkStateElem = modelStateElem->GetElement("link");
EXPECT_TRUE(modelStateElem->HasElement("link_state"));
sdf::ElementPtr linkStateElem = modelStateElem->GetElement("link_state");
EXPECT_TRUE(linkStateElem->HasAttribute("name"));
EXPECT_EQ(linkStateElem->Get<std::string>("name"), "my_link");

Expand All @@ -286,8 +286,8 @@ TEST(Frame, StateFrame)
gz::math::Pose3d(111, 3, 0, 0, 0, 0));
}

EXPECT_TRUE(stateElem->HasElement("light"));
sdf::ElementPtr lightStateElem = stateElem->GetElement("light");
EXPECT_TRUE(stateElem->HasElement("light_state"));
sdf::ElementPtr lightStateElem = stateElem->GetElement("light_state");

// light
EXPECT_TRUE(lightStateElem->HasAttribute("name"));
Expand Down
122 changes: 109 additions & 13 deletions test/integration/nested_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ TEST(NestedModel, NestedModel)
TEST(NestedModel, State)
{
std::ostringstream sdfStr;
sdfStr << "<sdf version ='" << SDF_VERSION << "'>"
sdfStr << "<sdf version ='1.11'>"
<< "<world name='default'>"
<< "<state world_name='default'>"
<< "<model name='model_00'>"
Expand Down Expand Up @@ -154,9 +154,9 @@ TEST(NestedModel, State)
sdf::ElementPtr worldElem = sdfParsed->Root()->GetElement("world");
EXPECT_TRUE(worldElem->HasElement("state"));
sdf::ElementPtr stateElem = worldElem->GetElement("state");
EXPECT_TRUE(stateElem->HasElement("model"));
EXPECT_TRUE(stateElem->HasElement("model_state"));

sdf::ElementPtr modelStateElem = stateElem->GetElement("model");
sdf::ElementPtr modelStateElem = stateElem->GetElement("model_state");

// model sdf
EXPECT_TRUE(modelStateElem->HasAttribute("name"));
Expand All @@ -167,8 +167,8 @@ TEST(NestedModel, State)
EXPECT_TRUE(!modelStateElem->HasElement("joint"));

// link sdf
EXPECT_TRUE(modelStateElem->HasElement("link"));
sdf::ElementPtr linkStateElem = modelStateElem->GetElement("link");
EXPECT_TRUE(modelStateElem->HasElement("link_state"));
sdf::ElementPtr linkStateElem = modelStateElem->GetElement("link_state");
EXPECT_TRUE(linkStateElem->HasAttribute("name"));
EXPECT_EQ(linkStateElem->Get<std::string>("name"), "link_00");
EXPECT_TRUE(linkStateElem->HasElement("pose"));
Expand All @@ -185,9 +185,9 @@ TEST(NestedModel, State)
gz::math::Pose3d(0, 0.006121, 0, 0, 0, 0));

// nested model sdf
EXPECT_TRUE(modelStateElem->HasElement("model"));
EXPECT_TRUE(modelStateElem->HasElement("model_state"));
sdf::ElementPtr nestedModelStateElem =
modelStateElem->GetElement("model");
modelStateElem->GetElement("model_state");
EXPECT_TRUE(nestedModelStateElem->HasAttribute("name"));
EXPECT_EQ(nestedModelStateElem->Get<std::string>("name"), "model_01");
EXPECT_TRUE(nestedModelStateElem->HasElement("pose"));
Expand All @@ -196,9 +196,9 @@ TEST(NestedModel, State)
EXPECT_TRUE(!nestedModelStateElem->HasElement("joint"));

// nested model's link sdf
EXPECT_TRUE(nestedModelStateElem->HasElement("link"));
EXPECT_TRUE(nestedModelStateElem->HasElement("link_state"));
sdf::ElementPtr nestedLinkStateElem =
nestedModelStateElem->GetElement("link");
nestedModelStateElem->GetElement("link_state");
EXPECT_TRUE(nestedLinkStateElem->HasAttribute("name"));
EXPECT_EQ(nestedLinkStateElem->Get<std::string>("name"), "link_01");
EXPECT_TRUE(nestedLinkStateElem->HasElement("pose"));
Expand All @@ -215,8 +215,8 @@ TEST(NestedModel, State)
gz::math::Pose3d(0, 0.000674, 0, 0, 0, 0));

// double nested model sdf
EXPECT_TRUE(nestedModelStateElem->HasElement("model"));
nestedModelStateElem = nestedModelStateElem->GetElement("model");
EXPECT_TRUE(nestedModelStateElem->HasElement("model_state"));
nestedModelStateElem = nestedModelStateElem->GetElement("model_state");
EXPECT_TRUE(nestedModelStateElem->HasAttribute("name"));
EXPECT_EQ(nestedModelStateElem->Get<std::string>("name"), "model_02");
EXPECT_TRUE(nestedModelStateElem->HasElement("pose"));
Expand All @@ -225,8 +225,8 @@ TEST(NestedModel, State)
EXPECT_TRUE(!nestedModelStateElem->HasElement("joint"));

// double nested model's link sdf
EXPECT_TRUE(nestedModelStateElem->HasElement("link"));
nestedLinkStateElem = nestedModelStateElem->GetElement("link");
EXPECT_TRUE(nestedModelStateElem->HasElement("link_state"));
nestedLinkStateElem = nestedModelStateElem->GetElement("link_state");
EXPECT_TRUE(nestedLinkStateElem->HasAttribute("name"));
EXPECT_EQ(nestedLinkStateElem->Get<std::string>("name"), "link_02");
EXPECT_TRUE(nestedLinkStateElem->HasElement("pose"));
Expand All @@ -243,6 +243,102 @@ TEST(NestedModel, State)
gz::math::Pose3d(0, 0, 0, 0, 0, 0));
}

////////////////////////////////////////
// Test parsing nested model states
TEST(NestedModel, StateSiblingsConversion1_12)
{
const std::string testFile =
sdf::testing::TestFile("sdf", "state_nested_model_world.sdf");

// Load the SDF file
sdf::Root root;
auto errors = root.Load(testFile);
EXPECT_TRUE(errors.empty());

// load the state sdf
EXPECT_TRUE(root.Element()->HasElement("world"));
sdf::ElementPtr worldElem = root.Element()->GetElement("world");

// Confirm that regular model elements were not migrated
EXPECT_FALSE(worldElem->HasElement("model_state"));

// Confirm that model and link elements in state were converted to
// model_state and link_state
EXPECT_TRUE(worldElem->HasElement("state"));
sdf::ElementPtr stateElem = worldElem->GetElement("state");
EXPECT_TRUE(stateElem->HasElement("model_state"))
<< stateElem->ToString("");
EXPECT_FALSE(stateElem->HasElement("model"))
<< stateElem->ToString("");

// model sdf
sdf::ElementPtr modelStateElem = stateElem->GetElement("model_state");
EXPECT_TRUE(modelStateElem->HasAttribute("name"));
EXPECT_EQ(modelStateElem->Get<std::string>("name"), "top_level_model");
EXPECT_TRUE(modelStateElem->HasElement("link_state"))
<< modelStateElem->ToString("");
EXPECT_TRUE(modelStateElem->HasElement("model_state"))
<< modelStateElem->ToString("");
EXPECT_FALSE(modelStateElem->HasElement("link"))
<< modelStateElem->ToString("");
EXPECT_FALSE(modelStateElem->HasElement("model"))
<< modelStateElem->ToString("");
}

////////////////////////////////////////
// Test parsing nested model states
TEST(NestedModel, StateInsertionsConversion1_12)
{
const std::string testFile =
sdf::testing::TestFile("sdf", "state_nested_model_world_insertion.sdf");

// Load the SDF file
sdf::Root root;
auto errors = root.Load(testFile);
EXPECT_TRUE(errors.empty());

// load the state sdf
EXPECT_TRUE(root.Element()->HasElement("world"));
sdf::ElementPtr worldElem = root.Element()->GetElement("world");

// Confirm that regular model elements were not migrated
EXPECT_FALSE(worldElem->HasElement("model_state"));

// Confirm that model and link elements in state were converted to
// model_state and link_state
EXPECT_TRUE(worldElem->HasElement("state"));
sdf::ElementPtr stateElem = worldElem->GetElement("state");
EXPECT_TRUE(stateElem->HasElement("model_state"))
<< stateElem->ToString("");
EXPECT_FALSE(stateElem->HasElement("model"))
<< stateElem->ToString("");

// model sdf
sdf::ElementPtr modelStateElem = stateElem->GetElement("model_state");
EXPECT_TRUE(modelStateElem->HasAttribute("name"));
EXPECT_EQ(modelStateElem->Get<std::string>("name"), "top_level_model");
EXPECT_TRUE(modelStateElem->HasElement("link_state"))
<< modelStateElem->ToString("");
EXPECT_TRUE(modelStateElem->HasElement("model_state"))
<< modelStateElem->ToString("");
EXPECT_FALSE(modelStateElem->HasElement("link"))
<< modelStateElem->ToString("");
EXPECT_FALSE(modelStateElem->HasElement("model"))
<< modelStateElem->ToString("");

// insertions
EXPECT_TRUE(stateElem->HasElement("insertions"));
sdf::ElementPtr insertionsElem = stateElem->GetElement("insertions");
// confirm that //insertions/model and link tags were not converted
EXPECT_FALSE(insertionsElem->HasElement("model_state"));
EXPECT_TRUE(insertionsElem->HasElement("model"));
sdf::ElementPtr insertedModelElem = insertionsElem->GetElement("model");
EXPECT_TRUE(insertedModelElem->HasAttribute("name"));
EXPECT_EQ(insertedModelElem->Get<std::string>("name"), "unit_box");
EXPECT_FALSE(insertedModelElem->HasElement("link_state"));
EXPECT_TRUE(insertedModelElem->HasElement("link"));
}

////////////////////////////////////////
// Test parsing models with joints nested via <include>
// Confirm that joint axis rotation is handled differently for 1.4 and 1.5+
Expand Down
Loading