nimblephysics icon indicating copy to clipboard operation
nimblephysics copied to clipboard

Mesh - Sphere Collision

Open gonultasbu opened this issue 3 years ago • 7 comments

Hello, thank you for your awesome work and this repository. I am currently having issues with Mesh - Sphere collisions. When I initialize and drop a sphere initialized by a URDF file, it does not collide with a URDF terrain and passes through.

I don't think this was the intended behavior because a quick search through the source code has revealed mesh-sphere collisions. Is this an implemented feature?

I am attaching a .gif below.

sphere-pierce-terrain ?

gonultasbu avatar Nov 23 '21 19:11 gonultasbu

That ball shouldn't be falling through the ground, and we probably don't have enough unit tests for mesh-sphere collisions. I'll go take a look at this after I get back from Thanksgiving break.

A few notes:

  • We support mesh colliders, but the meshes are assumed to be convex. Your ground mesh appears to have hills and valleys. Those valleys won't behave the way you expect, even if we fix the other issues with your example. You can compose multiple convex mesh colliders to make a single non-convex collider, if you like, but we don't (yet) automatically split non-convex meshes for you.
  • Are you sure that the shapes attached to your objects are collision shapes, as well as visual shapes?

keenon avatar Nov 23 '21 19:11 keenon

Thanks for the quick answer Keenon.

I am fairly sure that I have the collision models because swapping the "sphere" variable with "box" and corresponding dimensions seems to work as intended. I will take a look at this again with the convex partition.

If you want to take a look at the source code or test it yourself; I have pushed the test to my fork here: https://github.com/gonultasbu/nimblephysics/tree/355acdcb47bd84ed599e26037790b6bbfd49224b

in the python examples terrain.py.

Wish you a wonderful Thanksgiving break.

EDIT: It also looks like URDF capsules may not be rendered at all. I am also going to analyze this further.

gonultasbu avatar Nov 23 '21 19:11 gonultasbu

I finally got to investigate this behavior further with Kinova Gen3 URDF model, where every link is an STL mesh. It looks like mesh-sphere collisions work fine but the issue is with the convex parts (which is not expected to work anyway)? Adding gifs for your discretion. I'll close the issue after your confirmation.

bad_mesh_collision

good_mesh_sphere_collision

gonultasbu avatar Jan 12 '22 17:01 gonultasbu

I have done the convex decomposition of the mesh and imported the collision model through URDF. It does not look like the Shape-Mesh collisions work as intended. I have tested it with Mesh-Sphere and Mesh-Box collisions and primitives occasionally (but not always) fail to collide with the convex mesh parts, I will keep this thread updated. Posting a sample Box-Mesh collision below. The mesh is convex decomposed through trimesh.exchange.urdf function which uses V-HACD backend.

boxmesh

A more interesting example:

boxmesh (1)

gonultasbu avatar Feb 27 '22 16:02 gonultasbu

What I have noticed from further analysis is that objects can penetrate convex hulls and the amound of penetration depends on the velocity of the object. I have launched the red box to the unit_plane.obj convex hull with different velocities. The higher velocity penetrates the convex mesh further.

lowgrav

higrav

EDIT: I think I have understood the problem. Since the contacts are not exactly computed but only approximated, if the object is fast enough to penetrate the mesh (or primitive like a thin box), it will go right through that object. Therefore, this behavior is not only limited to meshes but is also observable with primitives

gonultasbu avatar Feb 27 '22 21:02 gonultasbu

I think it is because the penetration correction is disabled in nimble. See nimblephysics/dart/constraint/ConstraintSolver.cpp Line 69-71. A smaller timestep can fix this.

mPenetrationCorrectionEnabled(
        false), // Default to no penetration correction, because it breaks our
                // gradients

Also, sometimes, when penetration happens and one object goes right through the other, setting a larger mContactClippingDepth will prevent this. See nimblephysics/dart/constraint/ConstraintSolver.cpp Line 72-73.

mContactClippingDepth(
        0.03) // Default to clipping only after fairly deep penetration

LyuJ1998 avatar Apr 14 '22 06:04 LyuJ1998

Thanks for the advice. I have tried enabling the penetration correction but have not tried reducing the timestep. That could indeed be a neat workaround.

I have also noticed the contact clipping parameter but have not been successful with adjusting that, I will try again and report back.

gonultasbu avatar Apr 14 '22 13:04 gonultasbu