Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix initialization of world components when enabling velocity checks #2777

Open
wants to merge 2 commits into
base: gz-sim9
Choose a base branch
from

Conversation

gabrielfpacheco
Copy link

@gabrielfpacheco gabrielfpacheco commented Feb 14, 2025

🦟 Bug fix

Fixes #2774

Summary

When using the link API to enable velocity checks for a link that does not yet have the world ECM components (WorldPose, WorldLinearVelocity, WorldAngularVelocity), typically before the physics system plugin does its first update loop, such components will be initialized with their default constructor, zeroing values that might not be zero. One more evident example is the link world pose that could have already been initialized.

  1. Add the same unit test added by this MR to gz-sim/src/Link_TEST.cc
  2. Build the package: colcon build --packages-select gz-sim9
  3. Execute the test from your build folder: ./bin/UNIT_Link_TEST --gtest-filter=*EnableVelocityChecks*
  4. You should verify the tests will fail because all world components are zero

Checklist

  • Signed all commits for DCO
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

@github-actions github-actions bot added the 🏛️ ionic Gazebo Ionic label Feb 14, 2025
@gabrielfpacheco gabrielfpacheco force-pushed the gp-world_components_fix branch 5 times, most recently from 369ac76 to f7e26fb Compare February 18, 2025 18:42
@gabrielfpacheco
Copy link
Author

Friendly ping :)

@mjcarroll, @scpeters, @azeey. Could any of you guys take a quick look at this PR to see if I'm in the right track?

Gabriel Pacheco and others added 2 commits February 26, 2025 16:15
* Not all models of test/worlds/mesh_inertia_calculation.sdf are
initialized with zero pose
* Bug gazebosim#2774 was forcing all `link.WorldPose` to be zero after calling
`link.EnableVelocityChecks`

Signed-off-by: Gabriel Pacheco <[email protected]>

# Conflicts:
#	test/integration/mesh_inertia_calculation.cc
Copy link

codecov bot commented Feb 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.94%. Comparing base (036515f) to head (b928b4a).
Report is 5 commits behind head on gz-sim9.

Additional details and impacted files
@@             Coverage Diff             @@
##           gz-sim9    #2777      +/-   ##
===========================================
+ Coverage    68.93%   68.94%   +0.01%     
===========================================
  Files          345      345              
  Lines        33296    33319      +23     
===========================================
+ Hits         22952    22972      +20     
- Misses       10344    10347       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@scpeters scpeters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes sense to me; thanks for the contribution!

I just have a few small comments on some test expectations that I think can be removed

EXPECT_EQ(link.WorldInertialPose(*ecm).value(), gz::math::Pose3d::Zero);
// Check the Inertial Pose and Link Pose. Their world poses should be the
// same since the inertial pose relative to the link is zero.
EXPECT_EQ(link.WorldPose(*ecm).value(), worldPose(linkEntity, *ecm));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
EXPECT_EQ(link.WorldPose(*ecm).value(), worldPose(linkEntity, *ecm));

this expectation seems unnecessary based on the comments; I would remove it

@@ -219,13 +222,12 @@ void cylinderColladaMeshWithNonCenterOriginInertiaCalculation(
link.WorldInertiaMatrix(*ecm).value().Equal(inertiaMatrix, 0.005));

// Check the Inertial Pose and Link Pose
EXPECT_EQ(link.WorldPose(*ecm).value(), gz::math::Pose3d::Zero);
EXPECT_EQ(link.WorldPose(*ecm).value(), worldPose(linkEntity, *ecm));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
EXPECT_EQ(link.WorldPose(*ecm).value(), worldPose(linkEntity, *ecm));

this expectation seems unnecessary based on the comments; I would remove it

@@ -318,7 +320,7 @@ TEST(MeshInertiaCalculationTest, CylinderColladaOptimizedMeshInertiaCalculation)
EXPECT_TRUE(actualIxyxzyz.Equal(
meshInertial.MassMatrix().OffDiagonalMoments(), 3.5));
// Check the Inertial Pose and Link Pose
EXPECT_EQ(link.WorldPose(*ecm).value(), gz::math::Pose3d::Zero);
EXPECT_EQ(link.WorldPose(*ecm).value(), worldPose(linkEntity, *ecm));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
EXPECT_EQ(link.WorldPose(*ecm).value(), worldPose(linkEntity, *ecm));

this expectation seems unnecessary based on the comments; I would remove it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏛️ ionic Gazebo Ionic
Projects
Status: Inbox
Development

Successfully merging this pull request may close these issues.

Enable velocity checks create wrong world components for link entity in which they don't yet exist
2 participants