gazebosim / gz-physics

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

bullet-featherstone: Improve mesh collision stability #600

Closed iche033 closed 4 months ago

iche033 commented 4 months ago

🦟 Bug fix

Summary

Mesh collisions are quite unstable in our bullet-featherstone implementation. Sometimes they explode and fly away on contact. The bullet-featherstone's multibody constraint solve applies a large impulse (uncapped) when penetration occurs. To reduce this effect, we tune 2 parameters:

Here's original behavior: erp = 0.2, margin = 0.001 Box meshes explode on contact

bullet-1mm

Here's testing with just increasing the margin and leaving the erp untouched: erp = 0.2, margin = 0.01 Stability improved but there are still small bounces due to penetration

bullet-1cm

Here's the new behavior with improved stability even when the top box is dropped from higher z: erp = 0.002, margin = 0.01

bullet-002erp-1cm

The downside of having a larger margin is that the mesh collision has a small gap when resting on top of one another.

bullet-1cm_margin

This will need to be addressed

To test

To reproduce the tests above, first you'll need these 2 PRs that allow bullet-featherstone in gz-phsyics to load meshes from relative paths:

You can download the world and model files for testing:

mkdir -p box_mesh_test/box
wget https://gist.githubusercontent.com/iche033/9943a9bcf6ed9eede40ee3e9dbb4f8ad/raw/2f837c5221c3d56ee13f6191de4c0a449c36b0db/box_mesh_test.sdf
wget https://gist.githubusercontent.com/iche033/d13a8d8e0c05308f98ce1e5e105500ce/raw/681a2be4a2d53d36c9f0e415640258674ef977e5/model.sdf -O box_mesh_test/box/model.sdf
wget https://gist.githubusercontent.com/iche033/8c57b8882085dbce615419d5d472530c/raw/754f620ab034d218c0cda02453c4664968fe5935/box.obj -O box_mesh_test/box/box.obj
wget https://gist.githubusercontent.com/iche033/e59504e1b67f37f2ad30588d16fadb1b/raw/9a4dd30007345f017ca44f7da671eca6cddb9843/model.config -O box_mesh_test/box/model.config

Run gz-sim with bullet-featherstone plugin:

gz sim -v 4 box_mesh_test.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.

iche033 commented 4 months ago

It seems like a small erp2 value causes objects to be slight more unstable when two objects are attached by a joint. The new erp2 value caused a few vel checks in joint_features to fail and I had to increase tolerance for the tests to pass. bae4277. Let me know if that shouldn't be done.

codecov[bot] commented 4 months ago

Codecov Report

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

Project coverage is 79.07%. Comparing base (18e0dad) to head (801dbdd).

Files Patch % Lines
bullet-featherstone/src/SDFFeatures.cc 0.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## gz-physics6 #600 +/- ## ============================================ Coverage 79.06% 79.07% ============================================ Files 140 140 Lines 7950 7951 +1 ============================================ + Hits 6286 6287 +1 Misses 1664 1664 ```

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