google-deepmind / mujoco

Multi-Joint dynamics with Contact. A general purpose physics simulator.
https://mujoco.org
Apache License 2.0
8.29k stars 833 forks source link

Negative distance between non colliding geometries #1857

Open cganuza opened 4 months ago

cganuza commented 4 months ago

Hi,

I'm an engineer and I'm trying to use MuJoCo for collision detection.

At the beginning I experienced this behavior with our own geometries, but after looking more in depth I found the same output with two general MuJoCo geometries. The issue is that I found negative distances between bodies even though they are not in contact. when they are in a close distance you can see negative distance. Not only that the contact point it is not where I would expect it to be. As you can see in the screenshot bellow it seems it is facing the center of the disk instead of the surface.

I want to get the distance between the bodies. Am I missing some setting for this?

Here is a simplified model which explains my question:

I am using MuJoCo 3.2.0

XML ```XML ```

the python script (not including the xml model from above:

import mujoco
import mujoco.viewer

model = mujoco.MjModel.from_xml_string(model_xml)
data = mujoco.MjData(model)
mujoco.viewer.launch(model, data)

Here is a screenshot, illustrating my question, already with the initial conditions I have the issue: image

yuvaltassa commented 4 months ago

Yes, this is a bug we are working on fixing.

See caveat here

cganuza commented 4 months ago

Thank you for the prompt response @yuvaltassa. Do you have a time line when this will be fixed?

For mesh geometries the only option now is to create SDF files? Does this change the way of interacting with mujoco? Do you have any example? And, is it easy to change a mesh file to SDF?

Thank you so much!

rf4lc commented 4 weeks ago

Hello everyone,

I am trying to use MuJoCo to compute the minimum distance between two moving geometries, but I am facing the same issue (with MuJoCo version 3.2.4). Please is there any setup/ alternative that would improve this condition while the bug is being resolved?

Thanks in advance!

kbayes commented 4 weeks ago

Hi @rf4lc, can you try enabling nativeccd? Hopefully that works.