Skip to content

Commit

Permalink
Add expectations about auto-inertial warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Peters <scpeters@openrobotics.org>
  • Loading branch information
scpeters committed Dec 20, 2024
1 parent b1b22f7 commit 3b6d8e0
Showing 1 changed file with 46 additions and 9 deletions.
55 changes: 46 additions & 9 deletions src/Link_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,24 @@ TEST(DOMLink, ResolveAutoInertialsWithDifferentDensity)
</model>
</sdf>)";

// Parse first with enforcement policy set to ERR to detect warnings.
{
sdf::Root root;
sdf::ParserConfig sdfParserConfig;
// Set enforcement policy to ERR so we can detect warnings in sdf::Errors.
sdfParserConfig.SetWarningsPolicy(sdf::EnforcementPolicy::ERR);
sdf::Errors errors = root.LoadSdfString(sdfString, sdfParserConfig);
// Expect 1 warning due to an unset collision density.
EXPECT_EQ(1u, errors.size()) << errors;
EXPECT_EQ(sdf::ErrorCode::ELEMENT_MISSING, errors[0].Code()) << errors;
EXPECT_NE(std::string::npos,
errors[0].Message().find(
"Collision is missing a <density> child element. Using a "
"default density value of")) << errors;
EXPECT_NE(nullptr, root.Element());
}

// Parse again with default enforcement policy and expect no warnings.
sdf::Root root;
const sdf::ParserConfig sdfParserConfig;
sdf::Errors errors = root.LoadSdfString(sdfString, sdfParserConfig);
Expand Down Expand Up @@ -755,6 +773,27 @@ TEST(DOMLink, InertialValuesGivenWithAutoSetToTrue)
" </model>"
" </sdf>";

// Parse first with enforcement policy set to ERR to detect warnings.
{
sdf::Root root;
sdf::ParserConfig sdfParserConfig;
// Set enforcement policy to ERR so we can detect warnings in sdf::Errors.
sdfParserConfig.SetWarningsPolicy(sdf::EnforcementPolicy::ERR);
sdf::Errors errors = root.LoadSdfString(sdf, sdfParserConfig);
// Expect 1 warning due to user-specified inertial values when using
// inertial auto=true.
EXPECT_EQ(1u, errors.size()) << errors;
EXPECT_EQ(sdf::ErrorCode::WARNING, errors[0].Code()) << errors;
EXPECT_NE(std::string::npos,
errors[0].Message().find(
"Inertial was used with auto=true for the link named "
"compound_link, but user-defined inertial values were "
"found, which will be overwritten by the computed inertial "
"values")) << errors;
EXPECT_NE(nullptr, root.Element());
}

// Parse again with default enforcement policy and expect no warnings.
sdf::Root root;
const sdf::ParserConfig sdfParserConfig;
sdf::Errors errors = root.LoadSdfString(sdf, sdfParserConfig);
Expand Down Expand Up @@ -933,24 +972,18 @@ TEST(DOMLink, ResolveAutoInertialsWithMassAndMultipleCollisions)
TEST(DOMLink, ResolveAutoInertialsWithMassAndDefaultDensity)
{
// A model with link inertial auto set to true.
// The inertia matrix is specified but should be ignored.
// <mass> is specified - the auto computed inertial values should
// be scaled based on the desired mass.
// The model contains two collisions with different sizes. Density
// is specified for the top collision but not the bottom collision.
// There should be no parser warnings.
// The model should have a lumped center of mass at the link origin.
std::string sdf = "<?xml version=\"1.0\"?>"
"<sdf version=\"1.11\">"
" <model name='compound_model'>"
" <link name='compound_link'>"
" <inertial auto='true'>"
" <mass>12000.0</mass>"
" <pose>1 1 1 2 2 2</pose>"
" <inertia>"
" <ixx>1</ixx>"
" <iyy>1</iyy>"
" <izz>1</izz>"
" </inertia>"
" </inertial>"
" <collision name='cube_collision'>"
" <pose>0.0 0.0 0.5 0 0 0</pose>"
Expand All @@ -974,9 +1007,13 @@ TEST(DOMLink, ResolveAutoInertialsWithMassAndDefaultDensity)
"</sdf>";

sdf::Root root;
const sdf::ParserConfig sdfParserConfig;
sdf::ParserConfig sdfParserConfig;
// Set enforcement policy to ERR so we can detect warnings in sdf::Errors.
sdfParserConfig.SetWarningsPolicy(sdf::EnforcementPolicy::ERR);
sdf::Errors errors = root.LoadSdfString(sdf, sdfParserConfig);
EXPECT_TRUE(errors.empty());
// Expect no warnings due to user-specified inertial values when using
// inertial auto=true.
EXPECT_TRUE(errors.empty()) << errors;
EXPECT_NE(nullptr, root.Element());

const sdf::Model *model = root.Model();
Expand Down

0 comments on commit 3b6d8e0

Please sign in to comment.