Skip to content

Commit

Permalink
Add test showing failure for deeply nested welds in model directives (#…
Browse files Browse the repository at this point in the history
…19090)

Change one usage of `DRAKE_DEMAND` to `DRAKE_THROW_UNLESS`
  • Loading branch information
Marco A. Gutierrez authored May 12, 2023
1 parent f8709f7 commit 0078915
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion multibody/parsing/detail_dmd_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void AddWeld(
info.child_frame_name = child_frame.name();
}
}
DRAKE_DEMAND(found);
DRAKE_THROW_UNLESS(found);
}
}

Expand Down
27 changes: 27 additions & 0 deletions multibody/parsing/test/process_model_directives_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,33 @@ GTEST_TEST(ProcessModelDirectivesTest, ErrorMessages) {
}
}

// Test model directives failure to load welds with a deep nested child.
GTEST_TEST(ProcessModelDirectivesTest, DeepNestedChildWelds) {
ModelDirectives directives = LoadModelDirectives(
FindResourceOrThrow(std::string(kTestDir) +
"/deep_child_weld.dmd.yaml"));
MultibodyPlant<double> plant(0.0);

DRAKE_EXPECT_THROWS_MESSAGE(
ProcessModelDirectives(directives, &plant, nullptr,
make_parser(&plant).get()),
R"(.*Failure at .* in AddWeld\(\): condition 'found' failed.*)");
}

// Test model directives failure to load welds with a child to a
// deep nested frame.
GTEST_TEST(ProcessModelDirectivesTest, DeepNestedChildFrameWelds) {
ModelDirectives directives = LoadModelDirectives(
FindResourceOrThrow(std::string(kTestDir) +
"/deep_child_frame_weld.dmd.yaml"));
MultibodyPlant<double> plant(0.0);

DRAKE_EXPECT_THROWS_MESSAGE(
ProcessModelDirectives(directives, &plant, nullptr,
make_parser(&plant).get()),
R"(.*Failure at .* in AddWeld\(\): condition 'found' failed.*)");
}

} // namespace
} // namespace parsing
} // namespace multibody
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
directives:

- add_model:
name: top_level_model
file: package://process_model_directives_test/model_with_directly_nested_models.sdf

- add_model:
name: simple_model
file: package://process_model_directives_test/simple_model.sdf

- add_frame:
name: top_injected_frame
X_PF:
base_frame: top_level_model::robot1::robot_base
translation: [1, 2, 3]

- add_weld:
parent: simple_model::base
child: top_injected_frame
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
directives:

- add_model:
name: top_level_model
file: package://process_model_directives_test/model_with_directly_nested_models.sdf

- add_model:
name: simple_model
file: package://process_model_directives_test/simple_model.sdf

- add_weld:
parent: simple_model::base
child: top_level_model::robot1::robot_base
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<sdf xmlns:drake="http://drake.mit.edu" version="1.7">
<model name="scoped_model">
<link name="base"/>
<model name="robot1">
<link name="robot_base"/>
<frame name="tool_frame">
<pose relative_to="robot_base">1 2 3 0 0 0</pose>
</frame>
</model>
<frame name="frame">
<pose relative_to="base">1 2 3 0 0 0</pose>
</frame>
</model>
</sdf>

0 comments on commit 0078915

Please sign in to comment.