Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use urdf files in mujoco? #1569

Closed
LIUHAITAO-CH opened this issue Apr 4, 2024 · 13 comments
Closed

How to use urdf files in mujoco? #1569

LIUHAITAO-CH opened this issue Apr 4, 2024 · 13 comments
Labels
question Request for help or information

Comments

@LIUHAITAO-CH
Copy link

macOS Sonoma 14.4.1

Mujoco 3.1.3(pip install mujoco,not C++)

How to use urdf files in mujoco? , should the urdf file be modified appropriately, or does mujoco have an API to directly process urdf files? And what is the general format of the mesh path in the urdf file?

Thanks

@LIUHAITAO-CH LIUHAITAO-CH added the question Request for help or information label Apr 4, 2024
@LIUHAITAO-CH
Copy link
Author

and i noticed that the URDF Extensions, this picture is my files
image
What is the correct way to write meshdir and mesh, and what is needed to correctly identify and compile this urdf file in mujoco?
image
thanks

@jonzamora
Copy link

@LIUHAITAO-CH I see you are using the Franka Panda arm. I'd recommend you check out the Franka Panda arm from MuJoCo Menagerie if your main goal is to have a MuJoCo environment w/ the Panda arm already setup for you.

@LIUHAITAO-CH
Copy link
Author

LIUHAITAO-CH commented May 13, 2024

@LIUHAITAO-CH I see you are using the Franka Panda arm. I'd recommend you check out the Franka Panda arm from MuJoCo Menagerie if your main goal is to have a MuJoCo environment w/ the Panda arm already setup for you.

@jonzamora thanks for your suggest, Franka is just an example of my test. What I want to realize is a mobile manipulator model, which is a 4-wheel differential base and franka as a whole.

@traversaro
Copy link
Contributor

traversaro commented May 13, 2024

How to use urdf files in mujoco? , should the urdf file be modified appropriately, or does mujoco have an API to directly process urdf files? And what is the general format of the mesh path in the urdf file?

Just in case someone finds this discussion with search engines, there have been a discussion on this in #1432 . Main points I got from the discussion (if I write anything wrong feel free to correct me):

  • MuJoCo supports loading URDF, but does not support out of the box the use of package:// URIs, that is how URDF specification prescribe mesh path should be specified. Instead, as you correctly pointed out, relative paths (not directly supported in URDF spec) should be used for meshes, and meshdir should be used to indicate the relative location of the mesh directory w.r.t. to the .urdf file directory. In How to use urdf files in mujoco? #1569 (comment) example so meshdir should also include the meshes directory, or the strippath should be set to false (it is true by default for URDF files, see https://mujoco.readthedocs.io/en/stable/XMLreference.html#compiler-strippath).
  • Beside meshes related modifications, it is common for people consuming URDF in mujoco to modify the URDF before passing to mujoco, and then eventually also modify the resulting mjcf file (see for example How to import new urdf models in mujoco? #273 (comment)), as some features are not available in the form of URDF extensions.

@yuvaltassa
Copy link
Collaborator

Thanks @traversaro !

How hard/easy would it be to add URI support? The URDF import code is in xml_urdf.cc, which I think is not very hard to read. Let us know if there are straightforward improvement that you'd like us to add. Better still, send us a PR 🙂

@traversaro
Copy link
Contributor

How hard/easy would it be to add URI support? The URDF import code is in xml_urdf.cc, which I think is not very hard to read. Let us know if there are straightforward improvement that you'd like us to add. Better still, send us a PR 🙂

I did a working prototype in #1432 (comment), however I realized that anyhow this can't be used to load out of the box URDF with package:// URIs, as you need anyhow to:

  • Modify the URDF to set strippath to false
  • Modify the C++/Python source code to register the resource provider

So we pivoted to have code to modify the URDF files on the fly, as that is necessary for other parameters that can't be added as URDF extensions. See #1432 (comment) for a more in-depth discussion.

@LIUHAITAO-CH
Copy link
Author

LIUHAITAO-CH commented May 14, 2024

thanks, @traversaro @yuvaltassa .now i have another question about mujoco visulaization.
in urdf, my code is shown below.

<?xml version="1.0" ?>

<robot name="fr3">
  
  <mujoco>
    <compiler meshdir="meshes/" balanceinertia="true" discardvisual="false"/>
  </mujoco>

  <link name="fr3_link0">
    <inertial>
      <origin xyz="-0.041018 -0.00014 0.049974" rpy="0 0 0" />
      <mass value="0.629769" />
      <inertia ixx="0.00315" ixy="8.2904E-07" ixz="0.00015" iyy="0.00388" iyz="8.2299E-06" izz="0.004285" />
    </inertial>

    <visual>
      <geometry>
        <mesh filename="link0_meshlab.stl"/>
      </geometry>
    </visual>

    <collision>
      <geometry>
        <mesh filename="link0.stl"/>
      </geometry>
    </collision>
  </link>


  <link name="fr3_link1">
    <inertial>
      <origin xyz="0.003875 0.002081 -0.04762" rpy="0 0 0" />
      <mass value="4.970684" />
      <inertia ixx="0.70337" ixy="-0.000139" ixz="0.006772" iyy="0.70661" iyz="0.019169" izz="0.009117" />
    </inertial>

    <visual>
      <geometry>
        <mesh filename="link1_meshlab.stl"/>
      </geometry>
    </visual>

    <collision>
      <geometry>
        <mesh filename="link1.stl"/>
      </geometry>
    </collision>
  </link>

......

image

I found that mujoco is not displaying a visual pattern, but a convex hull model in collision, and if the collision label is commented out, the normal visual label model will be displayed. Why is this?
image

@LIUHAITAO-CH
Copy link
Author

@yuvaltassa hello, I did read the document, i think that discardvisual is true for urdf, but the result is wrong,still a convex hull.

@yuvaltassa
Copy link
Collaborator

I think you are turning on the convex hull visualization. Try hitting the "H" key for both models, see what happens.

@LIUHAITAO-CH
Copy link
Author

LIUHAITAO-CH commented May 14, 2024

@yuvaltassa thanks for your suggestion, I don't have a comment on the collision tag for my first two links, and I've noticed that holding down the h key doesn't make a noticeable difference, it's still a convex packet type.
image
image

I feel that both visual and collision labels are displayed, but the collision label covers the content of the visual label. But I haven't found any other way not to implement the collision tag content, please help me, thank you

@yuvaltassa
Copy link
Collaborator

try pressing the 0, 1 or 2 keys, I think the visual and collision geoms are usually in different groups

@LIUHAITAO-CH
Copy link
Author

@yuvaltassa thanks,you are right,
group 0 is enabled by default, when i press the 0 key , the convex hull doesn't show up
image

when i press the 0 key again, the convex hull show up
image

Can I not set it in the mujoco tag of the urdf file so that it does not show packages? Or is it only possible to convert urdf files to mjcf files?

help me,thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Request for help or information
Projects
None yet
Development

No branches or pull requests

4 participants