google-deepmind / mujoco_menagerie

A collection of high-quality models for the MuJoCo physics engine, curated by Google DeepMind.
Other
1.25k stars 172 forks source link

General question about creating an MJCF file #66

Closed emrecemal closed 3 weeks ago

emrecemal commented 2 months ago

I want to create an MJCF file for my bipedal robot that I designed in Onshape. I used the onshape-to-robot tool to obtain the URDF file for the robot. From what I understand, I need to manually create the MJCF file based on the URDF. However, I find the process quite complex as the XML Reference is very detailed, and I'm hesitant to delve deeper into it. Can you provide me with some guidelines or suggestions on how to convert my robot more conveniently?

yuvaltassa commented 2 months ago

Did you see this section?

emrecemal commented 2 months ago

I saw the section and tried that part. I added the following line to the URDF file:

<mujoco>
    <compiler meshdir="./meshes/" discardvisual="false"/>
</mujoco>

Then, I dragged the URDF file into the Mujoco App and saw my robot there. However, when I save the MJCF file and open it, I can't see the inertia values. Do I need to modify it manually?

yuvaltassa commented 2 months ago

That is surprising. URDFs always have explicit inertial clauses, so they should always get saved...

Would you mind making a minimal URDF (no meshes or other external assets) that shows this issue?

emrecemal commented 2 months ago

Of course,

Here is a simple block's URDF with the mujoco's compiler line at the end:

<?xml version="1.0"?>
<robot name="block_2">
  <link name="block_2_base_link">
    <contact>
      <lateral_friction value="1.0"/>
      <spinning_friction value=".001"/>
    </contact>
    <inertial>
      <origin rpy="0 0 0" xyz="0 0 0"/>
      <mass value="0.02"/>
      <inertia ixx="1" ixy="0" ixz="0" iyy="1" iyz="0" izz="1"/>
    </inertial>
    <visual>
      <origin rpy="0 0 0" xyz="0.0 0.0 0.0"/>
      <geometry>
        <box size="0.10 0.018 0.018"/>
      </geometry>
      <material name="blockmat">
        <color rgba="0.1 0.7 0.1 1"/>
      </material>
    </visual>
    <collision>
      <origin rpy="0 0 0" xyz="0.0 0.0 0.0"/>
      <geometry>
        <box size="0.10 0.018 0.018"/>
      </geometry>
    </collision>
  </link>
  <mujoco>
    <compiler discardvisual="false"/>
  </mujoco>
</robot>

After I uploaded on Mujoco, and saved it, the MJCF file looks like:

<mujoco model="block_2">
  <compiler angle="radian"/>
  <worldbody>
    <geom size="0.05 0.009 0.009" type="box" contype="0" conaffinity="0" group="1" density="0" rgba="0.1 0.7 0.1 1"/>
    <geom size="0.05 0.009 0.009" type="box" rgba="0.1 0.7 0.1 1"/>
  </worldbody>
</mujoco>
yuvaltassa commented 2 months ago

Hold on, can you set fusestatic to false? It is on by default for URDF, so these bodies get fused with the world body, which has no inertia...

emrecemal commented 2 months ago

I have achieved the desired result! Thank you very much for your assistance. Regarding the model transfer, here are the following steps:

  1. I obtained the scene.xml file from one of the models in the repository and made the necessary import for my robot. However, I noticed that the model has collisions with the ground despite the absence of collision geometry definitions in the new XML file. Is this the expected behavior? Do I need to define the collision geometries?
  2. I inserted the <freejoint/> line just below my robot's trunk to ensure proper floating base dynamics.
  3. I added lighting to track my robot.
  4. I manually defined the sensors and actuators.

Do I need extra steps to get a complete model?

kevinzakka commented 3 weeks ago

@emrecemal Looks reasonable to me.