google-deepmind / mujoco

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

MJX collision between Sphere-Ellipsoid #2126

Open kinalmehta opened 8 hours ago

kinalmehta commented 8 hours 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 5 hours 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