From c072a17855667b2296ad099b9876e9c7a6f1a3f6 Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Thu, 12 Dec 2024 06:24:36 +0800 Subject: [PATCH] add one more test with multiple collisions Signed-off-by: Ian Chen --- src/Link_TEST.cc | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/Link_TEST.cc b/src/Link_TEST.cc index cb6b0a9e2..b335863c8 100644 --- a/src/Link_TEST.cc +++ b/src/Link_TEST.cc @@ -821,7 +821,64 @@ TEST(DOMLink, ResolveAutoInertialsWithMass) link->Inertial().MassMatrix().DiagonalMoments()); } +///////////////////////////////////////////////// +TEST(DOMLink, ResolveAutoInertialsWithMassAndMultipleCollisions) +{ + // A model with link inertial auto set to true. + // The inertia matrix is specified but should be ignored. + // is speicifed - the auto computed inertial values should + // be scaled based on the desired mass. + std::string sdf = "" + "" + " " + " " + " " + " 4.0" + " 1 1 1 2 2 2" + " " + " 1" + " 1" + " 1" + " " + " " + " " + " 0.0 0.0 0.5 0 0 0" + " 2.0" + " " + " " + " 1 1 1" + " " + " " + " " + " " + " 0.0 0.0 -0.5 0 0 0" + " 4.0" + " " + " " + " 1 1 1" + " " + " " + " " + " " + " " + ""; + + sdf::Root root; + const sdf::ParserConfig sdfParserConfig; + sdf::Errors errors = root.LoadSdfString(sdf, sdfParserConfig); + EXPECT_TRUE(errors.empty()); + EXPECT_NE(nullptr, root.Element()); + const sdf::Model *model = root.Model(); + const sdf::Link *link = model->LinkByIndex(0); + root.ResolveAutoInertials(errors, sdfParserConfig); + EXPECT_TRUE(errors.empty()); + + EXPECT_DOUBLE_EQ(4.0, link->Inertial().MassMatrix().Mass()); + EXPECT_EQ(gz::math::Pose3d(0 0 -0.166667 0 0 0), link->Inertial().Pose()); + EXPECT_EQ(gz::math::Vector3d(1.55556 1.55556 0.666667), + link->Inertial().MassMatrix().DiagonalMoments()); +} ///////////////////////////////////////////////// TEST(DOMLink, ResolveAutoInertialsCalledWithAutoFalse)