Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] Add efc_address to Contact in MJX #1561

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions mjx/mujoco/mjx/_src/collision_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from mujoco.mjx._src.collision_primitive import plane_sphere
from mujoco.mjx._src.collision_primitive import sphere_capsule
from mujoco.mjx._src.collision_primitive import sphere_sphere
from mujoco.mjx._src.constraint import count_constraints
from mujoco.mjx._src.types import Contact
from mujoco.mjx._src.types import Data
from mujoco.mjx._src.types import DisableBit
Expand Down Expand Up @@ -328,6 +329,12 @@ def _collide_geoms(
(g1.geom_id, g2.geom_id, params),
)

efc_active = (d.efc_J != 0).any(axis=1)
nefc = efc_active.sum()
_, _, _, nc = count_constraints(m, d)
nc = efc_active[-nc:].sum()
efc_start = nefc - nc

con = Contact(
dist=dist,
pos=pos,
Expand All @@ -339,6 +346,7 @@ def _collide_geoms(
solimp=params.solimp,
geom1=geom1,
geom2=geom2,
efc_address=jp.arange(fn.ncon) * 4 + efc_start,
)
return con

Expand Down
5 changes: 4 additions & 1 deletion mjx/mujoco/mjx/_src/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ class Contact(PyTreeNode):
solimp: constraint solver impedance (mjNIMP,)
geom1: id of geom 1
geom2: id of geom 2
efc_address: address in efc
"""
dist: jax.Array
pos: jax.Array
Expand All @@ -608,7 +609,8 @@ class Contact(PyTreeNode):
# unsupported: mu, H, dim
geom1: jax.Array
geom2: jax.Array
# unsupported: efc_address, exclude
efc_address: jax.Array
# unsupported: exclude

@classmethod
def zero(cls, ncon: int = 0) -> 'Contact':
Expand All @@ -624,6 +626,7 @@ def zero(cls, ncon: int = 0) -> 'Contact':
solimp=jp.zeros((ncon, mujoco.mjNIMP,)),
geom1=jp.zeros(ncon, dtype=int),
geom2=jp.zeros(ncon, dtype=int),
efc_address=jp.zeros(ncon, dtype=int),
)


Expand Down