Skip to content

mujoco: Implement AttachFixedJointFeature and DetachJointFeature#1001

Merged
azeey merged 3 commits into
gazebosim:mainfrom
azeey:mujoco_detachable_joint
Jun 11, 2026
Merged

mujoco: Implement AttachFixedJointFeature and DetachJointFeature#1001
azeey merged 3 commits into
gazebosim:mainfrom
azeey:mujoco_detachable_joint

Conversation

@azeey

@azeey azeey commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

🎉 New feature

Part of #299

Summary

  • Implemented AttachFixedJoint using MuJoCo equality weld constraints.
  • Optimized AttachFixedJoint and DetachJoint to reuse and toggle constraints (active = 0/1) to avoid expensive mjModel recompilations.
  • Implemented CastToFixedJoint to identify fixed joints.
  • Added comprehensive unit tests in detachable_joint.cc.

Test it

ctest -R detachable_joint

Screenshot

centrifuge

Orbital Centrifuge Target Game (gist detachable_joint_space.sdf)
A physics-based timing game in Gazebo Sim using the MuJoCo plugin. Players must trigger the detach command at the perfect millisecond to launch the rotating payloads through the target gate.

Note: Developing this demo exposed a reset bug where dynamic weld constraints failed to update their relative offsets after a simulation reset. The recording demonstrates that this is now resolved and working properly.

Checklist

  • Signed all commits for DCO
  • Added a screen capture or video to the PR description that demonstrates the feature
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • Updated Bazel files (if adding new files). Created an issue otherwise.
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers
  • Was GenAI used to generate this PR? If so, make sure to add "Generated-by" to your commits. (See this policy for more info.)

Generated-by: Gemini 3.1 Pro

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by and Generated-by messages.

Backports: If this is a backport, please use Rebase and Merge instead.

- Implemented `AttachFixedJoint` using MuJoCo equality weld constraints.
- Optimized `AttachFixedJoint` and `DetachJoint` to reuse and toggle constraints (`active = 0/1`) to avoid expensive `mjModel` recompilations.
- Implemented `CastToFixedJoint` to identify fixed joints.
- Added comprehensive unit tests in `detachable_joint.cc`.

Generated-by: Gemini 3.1 Pro
Signed-off-by: Addisu Z. Taddese <addisuzt@intrinsic.ai>
const char *n1 = mjs_getString(eqSpec->name1);
const char *n2 = mjs_getString(eqSpec->name2);
if (!n1 || !n2 || std::string_view(childBodyName) != n1 ||
std::string_view(parentBodyName) != n2)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do you need to check if childBodyName / parentBodyName are null?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think it's possible to have a body without a name. It's assigned immediately after creation:

https://github.com/azeey/gz-physics/blob/ccf109130c422caf9f720ceedf767cf2566cced5/mujoco/src/SDFFeatures.cc#L517

Do you think we should still add the extra check?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Mainly because I saw the use of std::string_view which does not work well with nullptr. Yeah if mjs_getString(mjs_getName(childLinkInfo->body->element)) never returns null then I think it should be fine.

Comment thread mujoco/src/JointFeatures.cc Outdated
Comment thread mujoco/src/JointFeatures.cc Outdated
Comment thread mujoco/src/JointFeatures.cc Outdated
@github-project-automation github-project-automation Bot moved this from Inbox to In review in Core development Jun 10, 2026
@azeey
azeey merged commit 8f07ca1 into gazebosim:main Jun 11, 2026
13 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in Core development Jun 11, 2026
@azeey
azeey deleted the mujoco_detachable_joint branch June 11, 2026 17:50
shameekganguly pushed a commit that referenced this pull request Jun 26, 2026
* mujoco: Implement AttachFixedJointFeature and DetachJointFeature

- Implemented `AttachFixedJoint` using MuJoCo equality weld constraints.
- Optimized `AttachFixedJoint` and `DetachJoint` to reuse and toggle constraints (`active = 0/1`) to avoid expensive `mjModel` recompilations.
- Implemented `CastToFixedJoint` to identify fixed joints.
- Added comprehensive unit tests in `detachable_joint.cc`.

Generated-by: Gemini 3.1 Pro

---------

Signed-off-by: Addisu Z. Taddese <addisuzt@intrinsic.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants