From 686dc2452fd4f798c967115586cf0edff920f010 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Mon, 9 Dec 2024 14:08:20 -0800 Subject: [PATCH] Add tests for auto-inertial with explicit mass (#1514) * link_dom test: Fix typo Signed-off-by: Steve Peters * Test case for auto-inertials with explicit mass Signed-off-by: Steve Peters --------- Signed-off-by: Steve Peters --- src/gz_TEST.cc | 13 +++ test/integration/link_dom.cc | 38 ++++++- test/sdf/inertial_stats_auto_mass.sdf | 140 ++++++++++++++++++++++++++ 3 files changed, 189 insertions(+), 2 deletions(-) create mode 100644 test/sdf/inertial_stats_auto_mass.sdf diff --git a/src/gz_TEST.cc b/src/gz_TEST.cc index dc54a45d2..864de685e 100644 --- a/src/gz_TEST.cc +++ b/src/gz_TEST.cc @@ -2021,6 +2021,19 @@ TEST(inertial_stats, SDF) EXPECT_EQ(expectedOutput, output); } + // Check a good SDF file with auto-inertials and explicit mass + // from the same folder by passing a relative path + { + std::string path = "inertial_stats_auto_mass.sdf"; + const auto pathBase = sdf::testing::TestFile("sdf"); + + std::string output = + custom_exec_str("cd " + pathBase + " && " + + GzCommand() + " sdf --inertial-stats " + + path + SdfVersion()); + EXPECT_EQ(expectedOutput, output); + } + expectedOutput = "Error Code " + std::to_string(static_cast( diff --git a/test/integration/link_dom.cc b/test/integration/link_dom.cc index 6d875b223..0a3b2add7 100644 --- a/test/integration/link_dom.cc +++ b/test/integration/link_dom.cc @@ -948,7 +948,7 @@ TEST(DOMLink, InertialAuto) const sdf::Link *link = model->LinkByName("link_1"); ASSERT_NE(link, nullptr); - // Verify inertial values for link_1 match thos in inertial_stats.sdf + // Verify inertial values for link_1 match those in inertial_stats.sdf gz::math::Inertiald inertial = link->Inertial(); gz::math::MassMatrix3d massMatrix = inertial.MassMatrix(); EXPECT_EQ(gz::math::Pose3d::Zero, inertial.Pose()); @@ -969,6 +969,40 @@ TEST(DOMLink, InertialAuto) EXPECT_FALSE(inertialElem->HasElement("pose")); } +///////////////////////////////////////////////// +TEST(DOMLink, InertialAutoExplicitMass) +{ + const std::string testFile = sdf::testing::TestFile("sdf", + "inertial_stats_auto_mass.sdf"); + + // Load the SDF file + sdf::Root root; + auto errors = root.Load(testFile); + EXPECT_TRUE(errors.empty()) << errors; + + const sdf::Model *model = root.Model(); + ASSERT_NE(model, nullptr); + + std::vector linkNames{"link_1", "link_2", "link_3", "link_4"}; + for (const std::string &linkName : linkNames) + { + const sdf::Link *link = model->LinkByName(linkName); + ASSERT_NE(link, nullptr); + + // Verify inertial values for link_i match those in inertial_stats.sdf + gz::math::Inertiald inertial = link->Inertial(); + gz::math::MassMatrix3d massMatrix = inertial.MassMatrix(); + EXPECT_EQ(gz::math::Pose3d::Zero, inertial.Pose()); + EXPECT_DOUBLE_EQ(6.0, massMatrix.Mass()); + EXPECT_DOUBLE_EQ(1.0, massMatrix.Ixx()); + EXPECT_DOUBLE_EQ(1.0, massMatrix.Iyy()); + EXPECT_DOUBLE_EQ(1.0, massMatrix.Izz()); + EXPECT_DOUBLE_EQ(0.0, massMatrix.Ixy()); + EXPECT_DOUBLE_EQ(0.0, massMatrix.Ixz()); + EXPECT_DOUBLE_EQ(0.0, massMatrix.Iyz()); + } +} + ///////////////////////////////////////////////// TEST(DOMLink, InertialAutoSaveInElement) { @@ -990,7 +1024,7 @@ TEST(DOMLink, InertialAutoSaveInElement) const sdf::Link *link = model->LinkByName("link_1"); ASSERT_NE(link, nullptr); - // Verify inertial values for link_1 match thos in inertial_stats.sdf + // Verify inertial values for link_1 match those in inertial_stats.sdf gz::math::Inertiald inertial = link->Inertial(); gz::math::MassMatrix3d massMatrix = inertial.MassMatrix(); EXPECT_EQ(gz::math::Pose3d::Zero, inertial.Pose()); diff --git a/test/sdf/inertial_stats_auto_mass.sdf b/test/sdf/inertial_stats_auto_mass.sdf new file mode 100644 index 000000000..b2b2c0381 --- /dev/null +++ b/test/sdf/inertial_stats_auto_mass.sdf @@ -0,0 +1,140 @@ + + + + + + 0 0 0 0 0 0 + + + + 5 0 0 0 0 0 + + 6 + + + + + 1 1 1 + + + + + + + 1 1 1 + + + + + + + + -5 0 0 0 0 0 + + 6 + + + 1000 + + + 1 1 1 + + + + + + + 1 1 1 + + + + + + + + + 0 5 0 0 0 0 + + 6 + + + 0 0 0.25 0 0 0 + 1000 + + + 1 1 0.5 + + + + + 0 0 -0.25 0 0 0 + 1000 + + + 1 1 0.5 + + + + + + + 1 1 1 + + + + + + + + + 0 -5 0 0 0 0 + + 6 + + + 0 0 0.25 0 0 0 + 123.456 + + + 1 1 0.5 + + + + + 0 0 -0.25 0 0 0 + 123.456 + + + 1 1 0.5 + + + + + + + 1 1 1 + + + + + + +