google-deepmind / mujoco

Multi-Joint dynamics with Contact. A general purpose physics simulator.
https://mujoco.org
Apache License 2.0
8.18k stars 817 forks source link

Adding multiple movable composite (deformable) bodies to a scene in XML #763

Closed rpapallas closed 1 year ago

rpapallas commented 1 year ago

Hi,

I'm trying to use MuJoCo for robotic manipulation. We have a model which comprises multiple rigid bodies and a robot manipulator, and we want to also add multiple deformable objects in there. I came across the composite macro, which looks to be exactly what we want to define such deformable objects. I can get one such deformable object in a scene with other rigid-bodies.

It seems that there is currently limited support for adding multiple composite bodies? What would be the easiest way to add numerous movable deformable objects in a MuJoCo scene currently?

Adding two composite objects give the following error: "Error: repeated name in body array, position XYZ". I don't think I can specify a name to the composite macro, which would have been great, so it can add a prefix to the bodies being generated?

I tried to export the XML model after it's being loaded to the simulate program to get the macro expanded, but copying the entire body generated by MuJoCo requires renaming hundreds of bodies, and it seems that the naming convention for these bodies is important.

We want something like this:

<mujoco>
    <worldbody>
        <body name="rigid_body_1">
            <geom type="cylinder" size="0.03 0.05" name="rb1_geom"/>
            <freejoint/>
        </body>
        <body name="rigid_body_2">
            <geom type="cylinder" size="0.03 0.05" name="rb2_geom"/>
            <freejoint/>
        </body>
        <body nane="deformable_body_1" pos="0 0 1">
            <composite type="box" count="7 7 7" spacing="0.04">
                <skin texcoord="true" material="matsponge" rgba=".7 .7 .7 1"/>
                <geom type="capsule" size=".015 0.05" rgba=".8 .2 .1 1"/>
            </composite>
            <freejoint/>
        </body>
        <body nane="deformable_body_2" pos="0 0 1">
            <composite type="box" count="7 7 7" spacing="0.04">
                <skin texcoord="true" material="matsponge" rgba=".7 .7 .7 1"/>
                <geom type="capsule" size=".015 0.05" rgba=".8 .2 .1 1"/>
            </composite>
            <freejoint/>
        </body>
    </worldbody>
</mujoco>
quagla commented 1 year ago

Hi, what you need is the prefix attribute (see https://mujoco.readthedocs.io/en/latest/XMLreference.html#body-j-composite) in the composite specification. Let me know if it doesn't solve your issue.

rpapallas commented 1 year ago

Thanks, @quagla!

Shubh0802 commented 4 months ago

Hey tried running your model But there is an eroor i cant understand with body ERROR: Load model error: Error: repeated name 'B0_0_0' in body