-
Notifications
You must be signed in to change notification settings - Fork 733
Description
Description:
Attaching one PyMJCF model (the "source") to another (the "destination") adds the content of the source's worldbody into a newly generated body element in the destination worldbody. So if we want to add a robot whose model name is "robot1" to some scene, then all the contents of its worldbody will be inside a body named "robot1/" and all its children's names will be "robot1/{original_name}". The issue is that if "robot1" has a freejoint in its root body (the one direct child of worldbody), the resulting merged model cannot be loaded with MuJoCo because the freejoint element is now inside the base element which is inside the newly generated body "robot1/".
Error Message:
Error: free joint can only be used on top level
Reproduce:
A simple example to recreate the error message using the MuJoCo menagerie. This works with any free-moving robot (has a freejoint in the base). In the "scene.xml" file, we comment the <include/> line to avoid loading the robot this way, and only attach it with MJCF
from dm_control import mjcf
scene_model = mjcf.from_path('mujoco_menagerie/robotis_op3/scene.xml') # <include/> tag is commented
robot_model = mjcf.from_path('mujoco_menagerie/robotis_op3/op3.xml')
scene_model.attach(robot_model)
physics = mjcf.Physics.from_mjcf_model(scene_model)Suggested Solution:
My preferred solution would be to add an argument in the attach method that will exclude the outer "wrapper" body. We can still avoid name ambiguity by renaming the source model's components as before ("robot1/base", "robot1/wrist", etc).