Reproducing MuJoCo Menagerie hand-to-arm attachment example with the new model editing API #2063
-
IntroHi! I am a MuJoCo user working on manipulation. My setupMuJoCo: $ python -c "import mujoco; print(mujoco.__version__)"
3.2.3 API: OS: python -c "import platform; print('OS:', platform.system(), platform.release(), platform.machine())"
OS: Darwin 23.3.0 arm64 My questionI've been previously using the I'd like to programmatically attach a gripper to my arm model, similarly as done in the MuJoCo Menagerie example. I've added a couple of my test attempts below. The body/attach documentation mentions explicitly that "the world body cannot be attached", which is why the I wonder what the recommended way of achieving such model attachment is? It would be great to see a couple of examples on how to do this. Minimal model and/or code that explain my questionHere's my attempt following the Menagerie example:
$ python mj_spec_attach_hand_to_arm.py
Traceback (most recent call last):
File "$HOME/tmp/scripts/mj_spec_attach_hand_to_arm.py", line 104, in <module>
app.run(main)
File "$HOME/conda/envs/mujoco/lib/python3.11/site-packages/absl/app.py", line 308, in run
_run_main(main, args)
File "$HOME/conda/envs/mujoco/lib/python3.11/site-packages/absl/app.py", line 254, in _run_main
sys.exit(main(argv))
^^^^^^^^^^
File "$HOME/tmp/scripts/mj_spec_attach_hand_to_arm.py", line 97, in main
attach_hand_to_arm(arm_spec, hand_spec)
File "$HOME/tmp/scripts/mj_spec_attach_hand_to_arm.py", line 88, in attach_hand_to_arm
v0(arm_spec, hand_spec)
File "$HOME/tmp/scripts/mj_spec_attach_hand_to_arm.py", line 43, in v0
attachment_site.attach(hand_spec)
^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'mujoco._specs.MjsSite' object has no attribute 'attach'
Confirmations
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
I think there might be a bug report and two feature requests here?
Is that right? |
Beta Was this translation helpful? Give feedback.
-
Yeah, assuming that there's no other intended method of achieving this, I think that's right. I can split this into issues for better testability and easier tracking. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
By the way, the keyframe resizing should be done automatically for you (if you don't have nested attachments), see https://github.com/google-deepmind/mujoco/blob/main/test/user/user_api_test.cc#L643 |
Beta Was this translation helpful? Give feedback.
-
Just wanted to report back here that this is working as expected from ebe60b9 (not from import mujoco
import numpy as np
from robot_descriptions import fr3_mj_description
from robot_descriptions import shadow_dexee_mj_description
def main():
hand_spec = mujoco.MjSpec.from_file(shadow_dexee_mj_description.MJCF_PATH)
arm_spec = mujoco.MjSpec.from_file(fr3_mj_description.MJCF_PATH)
attachment_site = next(s for s in arm_spec.sites if s.name == "attachment_site")
attachment_site.attach(hand_spec.worldbody, "hand_base", "")
mj_model = arm_spec.compile()
mujoco.mj_saveModel(mj_model, "/tmp/franka-with-dexee.mjb")
print(arm_spec.to_xml())
if __name__ == "__main__":
main() And here's what the resulting model looks like: Thanks guys! |
Beta Was this translation helpful? Give feedback.
Just wanted to report back here that this is working as expected from ebe60b9 (not from
3.2.4
that's on PyPI though). Here's a snippet if anyone else is trying to do something similar: