Open 7oponaut opened 4 months ago
Thanks for this. We are currently in the process of significantly improving the collision functions which should hopefully solve this. We will make sure to include height fields in our tests.
I have a similar problem too, the fromto and distance sensors and the mj_geomDistance function all return wrong values for non plane geometries as can be seen visually from the following picture: The segments going from the body ovals to the flat floor are correct but the ones connecting the ovals with the box geometries are always wrong
here is a minimal example to reproduce the bug:
import mujoco.viewer
import time
m = mujoco.MjModel.from_xml_string(
"""
<mujoco>
<asset>
<texture type="skybox" builtin="gradient" rgb1="0.3 0.5 0.7" rgb2="0 0 0" width="512" height="3072"/>
<texture type="2d" name="groundplane" builtin="checker" mark="edge" rgb1="0.2 0.3 0.4" rgb2="0.1 0.2 0.3" markrgb="0.8 0.8 0.8" width="300" height="300"/>
<material name="groundplane" texture="groundplane" texuniform="true" texrepeat="5 5" reflectance="0.2"/>
</asset>
<worldbody>
<geom name="floor" group="1" size="0 0 0.05" type="plane" material="groundplane"/>
<body name="test" pos="-0.5 0 0">
<geom type='box' size='0.1 0.1 0.1' pos='0 0 0.2'/>
<joint type="free"/>
</body>
<body name="test2" pos="0.5 0 0">
<geom type='box' size='0.1 0.1 0.1' pos='0 0 0.2'/>
<joint type="free"/>
</body>
</worldbody>
<sensor>
<fromto name="test" cutoff="10" body1="test" body2="test2"/>
</sensor>
</mujoco>
"""
)
d = mujoco.MjData(m)
with mujoco.viewer.launch_passive(m, d) as viewer:
viewer.sync()
start = time.time()
while viewer.is_running():
step_start = time.time()
# Step the physics.
mujoco.mj_step(m, d)
viewer.sync()
time_until_next_step = m.opt.timestep - (time.time() - step_start)
if time_until_next_step > 0:
time.sleep(time_until_next_step)
https://github.com/user-attachments/assets/fc023362-5846-4d56-a592-59c25a9e3e1b
Hi @nikisalli,
For boxes, MuJoCo is using a bespoke box-box collider. I recommend trying meshes for boxes, so it forces the collider to use the more general MPR collider from libccd. I think that should give you better results for geom distances. In the case of contact, you might need to enable the multiccd flag to generate multiple contacts to give more stable contacts (the box-box collider by default gives multiple contacts).
thank you but libccd is too slow for my use case, I think I'll stick to multiple capsules to approximate my geometry as I see capsule-box colliders work much better than anything else
mujoco.mj_geomDistance() returns negative values for non-colliding (sphere, hfield) geom pairs.
In contrast, when testing with (sphere, plane) geom pairs, the function returns positive values as expected.
I am using the mujoco_menagerie/google_barkour_vb scenes for testing, since these include floor geoms of both the planar and hfield types.
To make the measurements, I added the attribute
name="neck_geom"
to the geom with the "neck" mesh in mujoco_menagerie/google_barkour_vb/barkour_vb_mjx.xml and then I ran the code I provided at the end of this report.I raise the height of the freejoint of the robot before simulation because it gets spawned too low into the hfield by default.
For non-colliding (sphere, plane) geom pairs, mujoco.mj_geomDistance() returns positive values as expected. Example scene: mujoco_menagerie/google_barkour_vb/scene_mjx.xml
For non-colliding (sphere, hfield) geom pairs, mujoco.mj_geomDistance() returns negative values. Example scene: mujoco_menagerie/google_barkour_vb/scene_hfield_mjx.xml
According to the code linked from the documentation, the mjc_ConvexHField() function handles these collisions.
mujoco.mj_geomDistance() produces negative falues for (sphere, hfield) geom pairs both with and without jax acceleration.
Video of the hfield scene:
https://github.com/google-deepmind/mujoco/assets/174741646/27e613a0-a72a-4712-aa40-21730fd7c70b
The code I used for generating the figures and the video:
Planar and hfield configurations respecitvely:
OS: ArchLinux 2024.07.01 MuJoCo version: 3.1.6 mujoco_menagerie commit id: 143ae53 Using mujoco python bindings