Skip to content

Commit

Permalink
ParserConfig: default to SAVE auto inertias
Browse files Browse the repository at this point in the history
Change default value of ConfigureResolveAutoInertials
to SAVE_CALCULATION to match previous API behavior.

Signed-off-by: Steve Peters <[email protected]>
  • Loading branch information
scpeters committed Sep 23, 2023
1 parent ab438f3 commit 4b1112e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
9 changes: 5 additions & 4 deletions src/Link.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ Errors Link::Load(ElementPtr _sdf, const ParserConfig &_config)
{
Error err(
ErrorCode::WARNING,
"Inertial was used with auto=true for link, " +
this->dataPtr->name + " but user defined inertial values "
"were found. They would be overwritten by computed ones."
"Inertial was used with auto=true for the link named " +
this->dataPtr->name + ", but user-defined inertial values were "
"found, which will be overwritten by the computed inertial values."
);
enforceConfigurablePolicyCondition(
_config.WarningsPolicy(), err, errors);
Expand Down Expand Up @@ -610,7 +610,8 @@ void Link::ResolveAutoInertials(sdf::Errors &_errors,
{
_errors.push_back({ErrorCode::ELEMENT_MISSING,
"Inertial is set to auto but there are no "
"<collision> elements for the link."});
"<collision> elements for the link named " +
this->Name() + "."});
return;
}

Expand Down
17 changes: 6 additions & 11 deletions src/Link_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -293,18 +293,13 @@ TEST(DOMLink, ResolveAutoInertialsWithNoCollisionsInLink)
sdf::Root root;
const sdf::ParserConfig sdfParserConfig;
sdf::Errors errors = root.LoadSdfString(sdf, sdfParserConfig);
EXPECT_TRUE(errors.empty());
ASSERT_EQ(1u, errors.size()) << errors;
EXPECT_EQ(sdf::ErrorCode::ELEMENT_MISSING, errors[0].Code());
EXPECT_NE(std::string::npos,
errors[0].Message().find(
"Inertial is set to auto but there are no <collision> elements "
"for the link named link."));
EXPECT_NE(nullptr, root.Element());

const sdf::Model *model = root.Model();
const sdf::Link *link = model->LinkByIndex(0);
root.ResolveAutoInertials(errors, sdfParserConfig);
ASSERT_FALSE(errors.empty());

// Default Inertial values set during load
EXPECT_EQ(1.0, link->Inertial().MassMatrix().Mass());
EXPECT_EQ(gz::math::Vector3d::One,
link->Inertial().MassMatrix().DiagonalMoments());
}

/////////////////////////////////////////////////
Expand Down
6 changes: 3 additions & 3 deletions src/ParserConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ class sdf::ParserConfig::Implementation
public: std::optional<EnforcementPolicy> deprecatedElementsPolicy;

/// \brief Configuration that is set for the CalculateInertial() function
/// By default it is set to SKIP_CALCULATION_IN_LOAD which would cause
/// Root::Load() to not call CalculateInertial()
/// By default it is set to SAVE_CALCULATION to preserve the behavior of
/// Root::Load() generating complete inertial information.
public: ConfigureResolveAutoInertials resolveAutoInertialsConfig =
ConfigureResolveAutoInertials::SKIP_CALCULATION_IN_LOAD;
ConfigureResolveAutoInertials::SAVE_CALCULATION;

/// \brief Collection of custom model parsers.
public: std::vector<CustomModelParser> customParsers;
Expand Down
6 changes: 3 additions & 3 deletions src/ParserConfig_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ TEST(ParserConfig, Construction)
EXPECT_EQ(sdf::EnforcementPolicy::WARN, config.UnrecognizedElementsPolicy());
EXPECT_EQ(sdf::EnforcementPolicy::WARN, config.DeprecatedElementsPolicy());

EXPECT_EQ(sdf::ConfigureResolveAutoInertials::SKIP_CALCULATION_IN_LOAD,
EXPECT_EQ(sdf::ConfigureResolveAutoInertials::SAVE_CALCULATION,
config.CalculateInertialConfiguration());
config.SetCalculateInertialConfiguration(
sdf::ConfigureResolveAutoInertials::SAVE_CALCULATION);
EXPECT_EQ(sdf::ConfigureResolveAutoInertials::SAVE_CALCULATION,
sdf::ConfigureResolveAutoInertials::SKIP_CALCULATION_IN_LOAD);
EXPECT_EQ(sdf::ConfigureResolveAutoInertials::SKIP_CALCULATION_IN_LOAD,
config.CalculateInertialConfiguration());
EXPECT_FALSE(config.URDFPreserveFixedJoint());
EXPECT_FALSE(config.StoreResolvedURIs());
Expand Down

0 comments on commit 4b1112e

Please sign in to comment.