Skip to content

Fix kinematics for mocap bodies with child bodies#858

Merged
adenzler-nvidia merged 14 commits into
google-deepmind:mainfrom
adenzler-nvidia:dev/adenzler/fix-mocap
Nov 21, 2025
Merged

Fix kinematics for mocap bodies with child bodies#858
adenzler-nvidia merged 14 commits into
google-deepmind:mainfrom
adenzler-nvidia:dev/adenzler/fix-mocap

Conversation

@adenzler-nvidia

Copy link
Copy Markdown
Collaborator

The sequence of kinematics -> mocap was wrong because if a mocap body had descendant bodies, the kinematics for these bodies were calculated based on the body_pos/quat values instead of mocap_pos/mocap_quat.

I took the liberty of just fusing in the mocap update into the kinematics kernel because it made sense to me, and it looks like there is a slight edge to this performance-wise. It will definitely help for scenes with a lot of mocap bodies.

Signed-off-by: Alain Denzler <adenzler@nvidia.com>
Signed-off-by: Alain Denzler <adenzler@nvidia.com>
Signed-off-by: Alain Denzler <adenzler@nvidia.com>
Signed-off-by: Alain Denzler <adenzler@nvidia.com>
Signed-off-by: Alain Denzler <adenzler@nvidia.com>
Signed-off-by: Alain Denzler <adenzler@nvidia.com>
Signed-off-by: Alain Denzler <adenzler@nvidia.com>
@adenzler-nvidia adenzler-nvidia changed the title Fix for mocap bodies with child bodies Fix kinematics for mocap bodies with child bodies Nov 20, 2025
Signed-off-by: Alain Denzler <adenzler@nvidia.com>
Signed-off-by: Alain Denzler <adenzler@nvidia.com>
Signed-off-by: Alain Denzler <adenzler@nvidia.com>
Signed-off-by: Alain Denzler <adenzler@nvidia.com>
Signed-off-by: Alain Denzler <adenzler@nvidia.com>
@thowell

thowell commented Nov 20, 2025

Copy link
Copy Markdown
Collaborator

confirmed that this is a bug with the MJX implementation, thanks for reporting and fixing this bug with MJWarp @adenzler-nvidia!

Comment thread mujoco_warp/_src/smooth_test.py Outdated
xml = """
<mujoco>
<worldbody>
<body name="mocap_parent" mocap="true" pos="0 0 0">

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to specify pos="0 0 0" since this is the default

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed, thanks for the pointer.

Comment thread mujoco_warp/_src/smooth_test.py Outdated
_assert_eq(d.xpos.numpy()[0], mjd.xpos, "initial xpos")

# Expected: child should be at mocap_pos + (1, 0, 0) relative offset
np.testing.assert_allclose(initial_child_xpos, [1.0, 0.0, 0.0], atol=1e-5)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use _assert_eq here and below?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thanks,

Signed-off-by: Alain Denzler <adenzler@nvidia.com>
@adenzler-nvidia adenzler-nvidia merged commit 5715386 into google-deepmind:main Nov 21, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants