Skip to content

Fix initialization of world components when enabling velocity checks #2777

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

Merged
merged 2 commits into from
Mar 4, 2025

Conversation

gabrielfpacheco
Copy link
Contributor

@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
Contributor 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 6 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

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.

thanks for the contribution! I'll address my comments in a follow-up PR

@github-project-automation github-project-automation bot moved this from Inbox to In review in Core development Mar 4, 2025
@scpeters scpeters merged commit 4ae75e5 into gazebosim:gz-sim9 Mar 4, 2025
13 checks passed
@github-project-automation github-project-automation bot moved this from In review to Done in Core development Mar 4, 2025
scpeters added a commit that referenced this pull request Mar 4, 2025
@gabrielfpacheco
Copy link
Contributor Author

@scpeters, thank you for your review. Do you think it would be possible to backport that change to Harmonic?

@gabrielfpacheco gabrielfpacheco deleted the gp-world_components_fix branch March 6, 2025 16:20
@scpeters
Copy link
Member

scpeters commented Mar 6, 2025

https://github.com/Mergifyio backport gz-sim8

Copy link
Contributor

mergify bot commented Mar 6, 2025

backport gz-sim8

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Mar 6, 2025
…2777)

Retain already initialized world component values when
enabling velocity checks and adjust expectations
accordingly in mesh_inertia_calulation integration tests.

Signed-off-by: Gabriel Pacheco <[email protected]>
Co-authored-by: Gabriel Pacheco <[email protected]>
(cherry picked from commit 4ae75e5)

# Conflicts:
#	test/integration/mesh_inertia_calculation.cc
scpeters pushed a commit that referenced this pull request Mar 7, 2025
…2777)

Retain already initialized world component values when
enabling velocity checks and adjust expectations
accordingly in mesh_inertia_calulation integration tests.

Signed-off-by: Gabriel Pacheco <[email protected]>
Co-authored-by: Gabriel Pacheco <[email protected]>
(cherry picked from commit 4ae75e5)
scpeters pushed a commit that referenced this pull request Mar 7, 2025
…2777)

Retain already initialized world component values when
enabling velocity checks and adjust expectations
accordingly in mesh_inertia_calulation integration tests.

Signed-off-by: Gabriel Pacheco <[email protected]>
Co-authored-by: Gabriel Pacheco <[email protected]>
(cherry picked from commit 4ae75e5)
scpeters added a commit that referenced this pull request Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏛️ ionic Gazebo Ionic
Projects
Status: Done
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