Skip to content

[MJX] accelerometer, framelinacc and frameangacc report -gravity on static and mocap bodies #3716

Open

Description

@dundysm

mj_objectAcceleration in mujoco c returns zero when the object's body is welded to a dof-less body (world, static or mocap). mjx reads cacc directly, and cacc[0] is -gravity, so accelerometer, framelinacc and frameangacc report 9.81 instead of 0.

this shows up in the menagerie: google_barkour_v0 has <accelerometer site="origin"/> on a worldbody site, and mjx reports [0, 0, 9.81] where mujoco reports [0, 0, 0].

repro:

import mujoco, numpy as np, jax
from mujoco import mjx
XML = """
<mujoco>
  <worldbody>
    <site name="world_site" pos="0.1 0 0"/>
    <body name="mocap" mocap="true" pos="0 0 1"><site name="mocap_site"/></body>
    <body name="static" pos="0 1 1"><site name="static_site"/><geom size=".1"/></body>
    <body name="free" pos="1 0 1"><freejoint/><geom size=".1"/><site name="free_site"/></body>
  </worldbody>
  <sensor>
    <accelerometer site="world_site"/>
    <accelerometer site="mocap_site"/>
    <accelerometer site="static_site"/>
    <framelinacc objtype="site" objname="mocap_site"/>
    <frameangacc objtype="site" objname="static_site"/>
    <accelerometer site="free_site"/>
  </sensor>
</mujoco>
"""
m = mujoco.MjModel.from_xml_string(XML); d = mujoco.MjData(m)
mujoco.mj_forward(m, d)
mx = mjx.put_model(m); dx = mjx.put_data(m, d)
dx = jax.jit(mjx.forward)(mx, dx)
print("mujoco c:", d.sensordata.reshape(-1, 3))
print("mjx:     ", np.asarray(dx.sensordata).reshape(-1, 3))

output:

mujoco c:    [[0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]]
mjx:         [[0.   0.   9.81]
 [0.   0.   9.81]
 [0.   0.   9.81]
 [0.   0.   9.81]
 [0.   0.   0.  ]
 [0.   0.   0.  ]]

mujoco 3.16.0, mjx from main (mujoco nightly 3.16.1.dev), jax cpu.

the same bug in mujoco_warp: google-deepmind/mujoco_warp#1804, fix in google-deepmind/mujoco_warp#1805.

Activity

  1. yuvaltassa commented on Nov 7, 2026

    @yuvaltassa
    Collaborator

    I think this is no longer true at head? please check

  2. dhairyajangir commented on Nov 10, 2026

    @dhairyajangir

    I reran the six-sensor model on Linux CPU with JAX 0.12.0.1. The MuJoCo and MJX 3.17.0 wheels reproduced all four discrepancies. With both wheels at 4.0.0, all six sensors agreed within 4.2e-7.

    I got the same result with the MJX Python source at a937a4f916dc586660145973b015e56e04043377 and the 4.0.0 native wheel. The four native readings that were zero in 3.17.0 now read +9.81 and agree with MJX. I used Codex to help run and check the comparison.

    I also checked the unmodified Barkour v0 MJX scene in Menagerie at 98a70c56. On the paired 3.17.0 wheels, its world-origin accelerometer reproduced the report in both the default pose and the standing keyframe. With the current MJX source and native 4.0.0, both read [0, 0, +9.81] in both poses. I initialized the MJX sensor output to NaN before each forward pass to verify it was recomputed.

    Applying just the production hunks from #3717 at e1f96e85 to current main made MJX read zero in both poses while native MuJoCo continued to read [0, 0, +9.81]. This comparison used current main with those hunks and the same release native engine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions