Meshes ignored when Converting URDF to MJCF

Discussion in 'Modeling' started by Frederik Ebert, Mar 26, 2017.

  1. Hi,

    I used the compile.cpp example to convert a URDF file into an MJCF file.
    The problem is that all the mesh tags in the URDF file are ignored, so the generated MJCF file does not have any geoms of type mesh.

    Here is a short example of how the mesh is used in my URDF:
    Code:
    <link name="head">
        <inertial>
          <origin rpy="0 0 0" xyz="0.0053207 -2.6549E-05 0.1021"/>
          <mass value="1.5795"/>
          <inertia ixx="0.011833" ixy="-4.4669E-06" ixz="4.9425E-05" iyy="0.0082709" iyz="4.2124E-07" izz="0.0049661"/>
        </inertial>
        <visual>
          <origin rpy="0 0 0" xyz="0 0 0"/>
          <geometry>
            <mesh filename="sawyer_pv/head.stl"/>
          </geometry>
          <material name="sawyer_red"/>
        </visual>
        <collision>
          <origin rpy="0 0 0" xyz="0 0 0.08"/>
          <geometry>
            <sphere radius="0.18"/>
          </geometry>
        </collision>
      </link>
    Is there a better way to get the meshes of the URDF file into the MJCF-file other than manually inserting geoms with meshes into the MJCF?

    On another note, mujoco does not understand the mesh tags in the URDF file when loading it directly. It simply ignores all meshes (without warnings).

    Thank you.
     
  2. Emo Todorov

    Emo Todorov Administrator Staff Member

    There are plenty of examples where MuJoCo loads meshes from URDF - most robot models on the Forum/Resources were converted from URDF actually. See documentation here:

    http://www.mujoco.org/book/modeling.html#CURDF

    You can insert a <mujoco> element in your URDF specifying directories and other options.
     
  3. I had inserted the <mujoco> element and given the mesh-directory as described in the documentation.
    I also set the strippath attribute to False.
    However when making Mujoco load the URDF file directly it keeps ignoring meshes (it also does not complain about not finding files).

    It seems that mujoco is entirely ignoring the mesh tags. This might also explain why the MJCF file generated from this URDF does not have any geoms with meshes.

    It would be helpful if you could provide me with a sample URDF file including meshes. (In the model files on this forum I only found MJCF)

    The first few lines of the URDF look like this:
    Code:
    <robot name="sawyer" xmlns:xacro="http://www.ros.org/wiki/xacro">
    
      <mujoco>
            <compiler meshdir="/home/frederik/Documents/RoboGym/mujoco_models/sawyer/meshes/"
                      balanceinertia="true"
                      strippath="false"/>
      </mujoco>
    
    
      <material name="black">
        <color rgba="0 0 0 1"/>
      </material>
      <material name="darkgray">
        <color rgba=".2 .2 .2 1"/>
      </material>
      <material name="darkred">
        <color rgba=".5 .1 .1 1"/>
      </material>
      <material name="sawyer_red">
        <color rgba=".5 .1 .1 1"/>
      </material>
      <material name="sawyer_gray">
        <color rgba="0.75294 0.75294 0.75294 1"/>
      </material>
      <link name="base"/>
      <link name="torso">
        <visual>
          <origin rpy="0 0 0" xyz="0 0 0"/>
          <geometry>
            <box size="0 0 0"/>
          </geometry>
          <material name="darkgray">
            <color rgba=".2 .2 .2 1"/>
          </material>
        </visual>
        <inertial>
          <origin rpy="0 0 0" xyz="0.000000 0.000000 0.000000"/>
          <mass value="0.0001"/>
          <inertia ixx="1e-08" ixy="0" ixz="0" iyy="1e-08" iyz="0" izz="1e-08"/>
        </inertial>
      </link>
      <link name="pedestal">
        <visual>
          <origin rpy="1.57079632679 0 -1.57079632679" xyz="0.26 0.345 -0.91488"/>
          <geometry>
            <mesh filename="sawyer_pv/pedestal.stl"/>
          </geometry>
          <material name="darkgray"/>
        </visual>
        <collision>
          <origin rpy="0 0 0" xyz="0 0 -0.30"/>
          <geometry>
            <cylinder length="0.62" radius="0.18"/>
          </geometry>
        </collision>
        <inertial>
          <origin rpy="0 0 0" xyz="0 0 0"/>
          <mass value="60.86397744"/>
          <inertia ixx="5.0635929" ixy="0.00103417" ixz="0.80199628" iyy="6.08689388" iyz="0.00105311" izz="4.96191932"/>
        </inertial>
      </link>
     
  4. Emo Todorov

    Emo Todorov Administrator Staff Member

    Here is a URDF file with meshes that loads happily.
     

    Attached Files:

  5. Hi,

    The darwin.urdf is working fine for me, but I'm still struggling to get the sawyer.urdf running.
    I made sure to match every detail of my sawyer.urdf with the darwin.urdf, however neither the mujoco simulator nor the conversion function recognizes the meshes in sawyer.urdf. The mesh files are at the proper location and ending with .stl.

    What other error sources could there be?
    Since you have access to the parsing code could you take a look to see what is going wrong?

    I'm attaching the full sawyer.urdf file as well as the corresponding meshes.
    Thank you very much for the help.
     

    Attached Files:

  6. Emo Todorov

    Emo Todorov Administrator Staff Member

    Darwin has collision meshes, which is why they are showing. Sawyer only has visual meshes, which are discarded automatically when discardvisual="true", which is the default when parsing URDFs. So you need to set discardvisual="false" in <compiler>. Also, you have a box with size="0 0 0" which is an error. Geom sizes must be positive. See attached model.

    Note that collision geoms are placed in geom group 0, while visual geoms are placed in geom group 1. You can toggle the rendering of each group pressing '0' and '1' respectively.
     

    Attached Files:

  7. Thank you very much! That helped a lot.
     
  8. Hi,
    I was able to load darwin model in mujoco.
    However, when I saved the model and saw the number of nu 0.

    What would I do?

    Thank you
     

    Attached Files:

  9. Yes, I have the same problem as @Junhyeok. Did anyone find the solution, or is this the expected behavior?
     
  10. I guess the behavior is just fine. nu is the "number of actuators/controls = dim(ctrl)". I do not recall the urdf import to add actuators. Just add them yourself.
     
  11. But this is for xml format, not for urdf?

    I tested adding <actuator> tag into urdf file, but it doesn't get picked up when loaded...
     
  12. I assume you want to simulate your robot using mujoco. So why don't you just compile the urdf into the corresponding mujoco xml format (mjcf). Then add the actuators manually in that file.
     
  13. Sure, that is indeed an option, but really dirty one. The group that I'm part of uses urdf/xacro for other projects, therefore for consistency, we would like to do the same. Since mujoco supports urdf, as per documentation page, we taught that it's equivalent writing either xml (mjcf) or urdf. Mixing the two is the worse option, and if there is no chance of specifying all the bits in urdf, we would probably fully switch to xml. Still, this is unfavourable solution, and if there's a way we would be glad to describe the robot with urdf.

    Having said all this, I have two questions:
    1. Are there some mujoco features/properties that can only be specified using xml, and not with urdf?
    2. What is the equivalent of xml <actuator> tag in urdf?

    Thanks!
     
  14. 1. Quote from the documentation: "This is why we have implemented support for URDF even though it can only represent a subset of the model elements available in MuJoCo" and "The above extensions make URDF more usable but still limited." (http://mujoco.org/book/modeling.html)
    Hence, I guess the answer is yes, indeed, quite a lot.
    2. You are searching for sth. that translates into an <actuator>. As far as I know there is no equivalent.
     
  15. Thanks a lot for your answers