gazebosim / gz-physics

Abstract physics interface designed to support simulation and rapid development of robot applications.
https://gazebosim.org
Apache License 2.0
65 stars 40 forks source link

bullet-featherstone: Support convex decomposition for meshes #606

Closed iche033 closed 5 months ago

iche033 commented 6 months ago

🎉 New feature

Replaces #603

Depends on

Summary

Supports convex decomposition on meshes. Bullet-featherstone implementation will parse the new mesh ~simplification~ optimization attribute introduced in https://github.com/gazebosim/sdformat/pull/1380, decompses the mesh into convex meshes, and builds btConvexHullShape collision shapes.

Compared to btGImpactMeshes (which is currently used for all meshes), the convex hulls seems to be more stable, do not have gaps between meshes (collision margins can be set to 1mm instead of 1cm), and some manual testing shows potentially faster performance (dependent on the number of submeshes generated)

Added test to verify that convex decomposition flag is parsed and valid collisions are generated.

Other changes:

To Test

Run gz sim with bullet-featherstone plugin and a world that has a model (e.g. Cordless Drill Simplified) that uses mesh decomposition:

gz sim -v 4 your_test_world.sdf --physics-engine gz-physics-bullet-featherstone-plugin

Checklist

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.

codecov[bot] commented 6 months ago

Codecov Report

Attention: Patch coverage is 98.52941% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 78.91%. Comparing base (492b124) to head (1f2aaa7). Report is 15 commits behind head on main.

:exclamation: Current head 1f2aaa7 differs from pull request most recent head fec9fad. Consider uploading reports for the commit fec9fad to get more accurate results

Files Patch % Lines
bullet-featherstone/src/SDFFeatures.cc 98.48% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #606 +/- ## ========================================== + Coverage 78.32% 78.91% +0.59% ========================================== Files 140 140 Lines 8069 8173 +104 ========================================== + Hits 6320 6450 +130 + Misses 1749 1723 -26 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

iche033 commented 6 months ago

I think convex_decomposition and convex_hull operations should apply to the fusion of all submeshes, unless only a single submesh is specified, in which case it would act only on that submesh. In the unoptimized case, we could also consider merging to a single mesh shape instead of using btCompoundShape (this can happen in separate pull requests)

hmm ok to make this happen, we'll need to:

I'll work on these changes

iche033 commented 6 months ago

hmm ok to make this happen, we'll need to:

  • update sdf description - currently it explicitly states decomposition is for each submesh
  • add a new function to merge multiple common::SubMeshes into one (before calling gz::common::ConvexDecomposition with that one combined submesh)

I'll work on these changes

https://github.com/gazebosim/sdformat/pull/1386 https://github.com/gazebosim/gz-common/pull/588

iche033 commented 5 months ago

I'm getting some unexpected penetration with convex_decomposition. I've attached the .sdf files.

I found that by setting a small m_globalCfm value, it's able to prevent this penetration, e.g.

diff --git a/bullet-featherstone/src/Base.cc b/bullet-featherstone/src/Base.cc
index ac66f574..80a04ced 100644
--- a/bullet-featherstone/src/Base.cc
+++ b/bullet-featherstone/src/Base.cc
@@ -49,6 +49,7 @@ WorldInfo::WorldInfo(std::string name_)
   // the penentration impulse depends on the erp2 parameter so set to a small
   // value (default in bullet is 0.2).
   this->world->getSolverInfo().m_erp2 = btScalar(0.02);
+  this->world->getSolverInfo().m_globalCfm = btScalar(0.001);

by default m_globalCfm is 0