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

Support mesh optimization params in mesh inertial calculator #2770

Merged
merged 12 commits into from
Feb 21, 2025

Conversation

iche033
Copy link
Contributor

@iche033 iche033 commented Feb 12, 2025

🎉 New feature

Summary

When //inertial/@auto is set to true, gz-sim auto computes inertial values for meshes using the MeshInertialCalculator. The calculator however uses the original mesh and ignores any //mesh/@optimization properties.

This PR extends the MeshInertialCalculator to work with optimized meshes. Main changes are:

  • Switched to use the loadMesh helper function which takes care parsing the mesh SDF, loading and returning the optimized mesh.
  • Use calculator to compute inertial for each submesh (as opposed to entire mesh), then sum up to get the final inertial values.

Note that the optimized meshes are stored in the MeshManager singleton, which means later when loading the physics system (which in turn needs these optimized meshes for creating collisions), it can just get the optimized meshes directly from the MeshManager cache without having to do mesh optimization again.

Test it

Here's an example of doing mesh inertial calculation for the Cordless Drill Simplified model. The mesh in this model has convex decomposition enabled, and here are the auto computed inertial values before and after the changes in this PR:

Before:

auto_inertial_original
  mass: 1.61561
  xx yy zz: [0.0143132 0.0124479 0.00406482]
  xy xz yz: [0.000326503 0.00036718 -0.000947023]
  principal moments: [0.00394363 0.0125094 0.0143729]
  CoM: [-0.00637488 -0.00799589 0.222544 0 0 0]

After:

auto_inertial_convex
mass: 2.11133
xx yy zz: [0.0185708 0.0159216 0.0057028]
xy xz yz: [0.000455349 0.000285211 -0.00127505]
principal moments: [0.0055373 0.0160106 0.0186473]
CoM: [-0.0066768 -0.00711079 0.227182 0 0 0]

Note that the optimized mesh has larger volume due to convex decomposition which leads to larger mass.

Here are the results with a fixed mass of: 1.50252

Before (no convex decomposition):

mass: 1.50252 
xx yy zz: [0.0133113 0.0115766 0.00378028]
xy xz yz: [0.000303647 0.000341477 -0.000880731]
principal moments: [0.00366758 0.0116338 0.0133668]
CoM: [-0.00637488 -0.00799589 0.132544 0 0 0]

After:

mass: 1.50252 
xx yy zz: [0.0132101 0.0114322 0.00408824]
xy xz yz: [0.00034167 0.000419915 -0.000875292]
principal moments: [0.00396275 0.011487 0.0132808]
CoM: [-0.0069944 -0.00689877 0.131142 0 0 0]

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • 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.

@iche033 iche033 requested a review from mjcarroll as a code owner February 12, 2025 23:41
@github-actions github-actions bot added the 🏛️ ionic Gazebo Ionic label Feb 12, 2025
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
<model name="cylinder_dae_convex_decomposition">
<link name="cylinder_dae_convex_decomposition">
<pose>0 0 0 0 0 0</pose>
<inertial auto="true" />
Copy link
Member

Choose a reason for hiding this comment

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

I'd be curious to compare the change in inertial properties before and after this PR when a fixed mass is specified

Copy link
Contributor Author

@iche033 iche033 Feb 13, 2025

Choose a reason for hiding this comment

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

updated the description with inertial results from using a fixed mass. The difference is small.

Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
Copy link

codecov bot commented Feb 19, 2025

Codecov Report

Attention: Patch coverage is 72.00000% with 7 lines in your changes missing coverage. Please review.

Please upload report for BASE (gz-sim9@54830b9). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/MeshInertiaCalculator.cc 72.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             gz-sim9    #2770   +/-   ##
==========================================
  Coverage           ?   68.93%           
==========================================
  Files              ?      345           
  Lines              ?    33292           
  Branches           ?        0           
==========================================
  Hits               ?    22949           
  Misses             ?    10343           
  Partials           ?        0           

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

@iche033 iche033 merged commit 219e70b into gz-sim9 Feb 21, 2025
14 checks passed
@iche033 iche033 deleted the mesh_inertial_calc_optimization branch February 21, 2025 19:18
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.

4 participants