google-deepmind / mujoco

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

MJX collision between Sphere-Ellipsoid #2126

Closed kinalmehta closed 1 month ago

kinalmehta commented 1 month ago

Intro

Hi!

I am trying to use MuJoCo-MJX with CMUHumanoid from dm-control. However I'm getting the following error.

NotImplementedError: (mjtGeom.mjGEOM_SPHERE, mjtGeom.mjGEOM_ELLIPSOID) collisions not implemented.

However in the documentation it is mentioned that ELLIPSOID and CYLINDER are implemented but only collide with other primitives, note that BOX is implemented as a mesh. I assume sphere is a primitive, so this error is unexpected.

My setup

Mujoco versions

Python and OS version

Minimal model for reproduction

minimal XML link: https://github.com/google-deepmind/dm_control/blob/main/dm_control/suite/humanoid_CMU.xml

Code required for reproduction

import mujoco
from mujoco import mjx

mj_model = mujoco.MjModel.from_xml_path(xml_path)
mj_data = mujoco.MjData(mj_model)
print(mj_data.qpos, type(mj_data.qpos))

mjx_model = mjx.put_model(mj_model) # error here
mjx_data = mjx.put_data(mj_model, mj_data)

print(mjx_data.qpos, type(mjx_data.qpos), mjx_data.qpos.devices())

Confirmations

kinalmehta commented 1 month ago

I tried adding the following code in collision_sdf.py

@collider(ncon=1)
def sphere_ellipsoid(s: GeomInfo, e: GeomInfo) -> Collision:
  """"Calculates contact between a sphere and an ellipsoid."""
  x0 = 0.5 * (s.pos + e.pos)
  return _optim(_sphere, _ellipsoid, s, e, x0)

Not sure if this works, I saw that there is an implementation of _sphere and _ellipsoid and wanted some feedback on this.

Thanks Kinal

btaba commented 1 month ago

@kinalmehta let us know if the recent push fixes the issue, thanks for reporting this!

kinalmehta commented 1 month ago

Thanks for the quick fix.