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

bullet-featherstone: Improve mesh collision stability #600

Merged
merged 4 commits into from
Mar 7, 2024

Conversation

iche033
Copy link
Contributor

@iche033 iche033 commented Feb 23, 2024

🦟 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:

  • collision margin - increased from 0.001 to 0.01
    • 0.01 is actually the default margin for GImpact meshes. The new value is also consistent with gazebo-classic which does not have margin set for GImpact meshes (so uses default value of 0.01)
  • erp2 (contact constraint error reduction param) - Reduces from default value of 0.2 to 0.02. This affects the contact penetration impulse applied.

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

  • 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.

Signed-off-by: Ian Chen <ichen@openrobotics.org>
@github-actions github-actions bot added the 🎵 harmonic Gazebo Harmonic label Feb 23, 2024
Signed-off-by: Ian Chen <ichen@openrobotics.org>
@iche033 iche033 changed the base branch from gz-physics7 to gz-physics6 February 24, 2024 02:45
@iche033 iche033 added 🌱 garden Ignition Garden and removed 🎵 harmonic Gazebo Harmonic labels Feb 24, 2024
@iche033
Copy link
Contributor Author

iche033 commented Feb 24, 2024

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.

Copy link

codecov bot commented Feb 24, 2024

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 ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           gz-physics6     #600   +/-   ##
============================================
  Coverage        79.06%   79.07%           
============================================
  Files              140      140           
  Lines             7950     7951    +1     
============================================
+ Hits              6286     6287    +1     
  Misses            1664     1664           

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

@@ -1266,9 +1266,9 @@ TYPED_TEST(JointFeaturesAttachDetachTest, JointAttachMultiple)
gz::math::eigen3::convert(frameDataModel2Body.linearVelocity);
gz::math::Vector3d body3LinearVelocity =
gz::math::eigen3::convert(frameDataModel3Body.linearVelocity);
EXPECT_NEAR(0.0, body1LinearVelocity.Z(), 1e-3);
EXPECT_NEAR(0.0, body1LinearVelocity.Z(), 3e-3);
Copy link
Contributor

@shameekganguly shameekganguly Feb 29, 2024

Choose a reason for hiding this comment

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

nit: I'm slightly surprised that we need to increase the LinearVelocity.Z() thresholds for both body1 and body3 but not body2 with this change. I guess this is due to the weld joint constraint being imperfect in bullet? You could consider using a position and velocity based threshold here as well as I mentioned in my previous comment to make the check robust to future changes.

Copy link
Contributor Author

@iche033 iche033 Mar 2, 2024

Choose a reason for hiding this comment

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

yeah I'm not sure why the constraints are more unstable. I tried using the while loop approach with position and vel thresholds but the checks are always satisfied (and loop exists) on the 1st iteration right after the joints are created since this is when the objects are most stable - if that makes sense. Given that the idea is to check that the objects are still at rest and stable after a few iterations, I reverted and kept the test the same as before. I just added position checks to make sure the boxes didn't move.

Signed-off-by: Ian Chen <ichen@openrobotics.org>
@iche033 iche033 merged commit e42cf34 into gz-physics6 Mar 7, 2024
8 of 11 checks passed
@iche033 iche033 deleted the bullet_mesh_stability branch March 7, 2024 01:59
@iche033 iche033 added the Bullet Bullet engine label Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bullet Bullet engine 🌱 garden Ignition Garden
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants