mujoco icon indicating copy to clipboard operation
mujoco copied to clipboard

Unable to Build an XML file that reads in a binary MSH file?

Open kurtenkera opened this issue 11 months ago • 8 comments

Hi,

I'm a student and I'm trying to use MuJoCo for simulating robots. As I'm new to MuJoCo, I'm just attempting to create an XML file from a basic binary MSH file of a hollow cylinder with the available Python bindings. However, I cannot achieve even this simple task and I'm unsure why?

Here is the code that I'm currently trying to run in a Jupyter Notebook cell:

import mujoco
import mediapy 

xml = r"""
<mujoco>
  <asset>
    <mesh file="hollow_cylinder_binary.msh"/>
  </asset>
  <worldbody>
    <body>
      <geom type="mesh" name="hollow_cylinder_binary" mesh="hollow_cylinder_binary"/>
    </body>
  </worldbody>
</mujoco>
"""

# Make model and data
model = mujoco.MjModel.from_xml_string(xml)
data = mujoco.MjData(model)

# Make renderer, render and show the pixels
renderer = mujoco.Renderer(model)
mujoco.mj_forward(model, data)
renderer.update_scene(data)

mediapy.show_image(renderer.render())

This is the error message I get when I run it:

ValueError: Error: invalid sizes in MSH file 'hollow_cylinder_binary.msh'
Object name = hollow_cylinder_binary, id = 0, line = 4

It seems like the error is related to my .msh file. I've attached an image of the `hollow_cylinder_binary.msh' file when visualized in Gmsh below (it is the shape that I want so I'm unsure why MuJoCo cannot read in this file?):

image

Thanks in advance for any help or feedback!

kurtenkera avatar Mar 09 '24 08:03 kurtenkera

Hi, Could you please send us the hollow_cylinder_binary.msh so we can replicate the issue?

mohammad200h avatar Mar 11 '24 09:03 mohammad200h

I have included the hollow_cylinder_binary.msh file in the attached .zip file. Please let me know if you reproduce the same error as me!

hollow_cylinder.zip

kurtenkera avatar Mar 11 '24 10:03 kurtenkera

I was able to replicate the issue. Can I ask what you are trying to do with this model? are you trying to simulate a softbody?

mohammad200h avatar Mar 11 '24 15:03 mohammad200h

Hi,

I'm a student and I'm trying to use MuJoCo for simulating robots. As I'm new to MuJoCo, I'm just attempting to create an XML file from a basic binary MSH file of a hollow cylinder with the available Python bindings. However, I cannot achieve even this simple task and I'm unsure why?

Here is the code that I'm currently trying to run in a Jupyter Notebook cell:

import mujoco
import mediapy 

xml = r"""
<mujoco>
  <asset>
    <mesh file="hollow_cylinder_binary.msh"/>
  </asset>
  <worldbody>
    <body>
      <geom type="mesh" name="hollow_cylinder_binary" mesh="hollow_cylinder_binary"/>
    </body>
  </worldbody>
</mujoco>
"""

# Make model and data
model = mujoco.MjModel.from_xml_string(xml)
data = mujoco.MjData(model)

# Make renderer, render and show the pixels
renderer = mujoco.Renderer(model)
mujoco.mj_forward(model, data)
renderer.update_scene(data)

mediapy.show_image(renderer.render())

This is the error message I get when I run it:

ValueError: Error: invalid sizes in MSH file 'hollow_cylinder_binary.msh'
Object name = hollow_cylinder_binary, id = 0, line = 4

It seems like the error is related to my .msh file. I've attached an image of the `hollow_cylinder_binary.msh' file when visualized in Gmsh below (it is the shape that I want so I'm unsure why MuJoCo cannot read in this file?):

image

Thanks in advance for any help or feedback!

Same problem here!

TAFFI98 avatar Mar 15 '24 15:03 TAFFI98

@TAFFI98 Could you please provide description of what you are trying to do?

gmsh format is used for flexcomp in Mujoco: https://mujoco.readthedocs.io/en/latest/XMLreference.html#body-flexcomp Your file need to have a single entity and the xml should look something like this:

<mujoco model="shark">
  <option timestep="0.01" integrator="implicitfast" solver="CG"/>

  <worldbody>
    <flexcomp name="shark" type="gmsh" dim="3" rgba=".8 .2 .2 1" radius="0.001" pos="0 0 .3" mass="10" scale="1 1 1" file="shark.msh">
    <edge equality="true"/>
    </flexcomp>
  </worldbody>
</mujoco>

mohammad200h avatar Mar 19 '24 13:03 mohammad200h

closing the issue due to inactivity. Feel free to open it :)

mohammad200h avatar Mar 22 '24 13:03 mohammad200h

Hi @mohammad200h, I tried following your advice above. Below is the code cell block that I tried running in a Jupyter notebook environment:

import mujoco
import mediapy as media
import matplotlib.pyplot as plt

import time
import itertools
import numpy as np

xml = r"""
<mujoco model="hollow_cylinder_binary">
  <worldbody>
    <flexcomp name="hollow_cylinder_binary" type="gmsh" dim="3" file="mesh_files/hollow_cylinder_binary.msh">
    <edge equality="true"/>
    </flexcomp>
  </worldbody>
</mujoco>
"""

# Make model and data
model = mujoco.MjModel.from_xml_string(xml)
data = mujoco.MjData(model)

# Make renderer, render and show the pixels
renderer = mujoco.Renderer(model)
mujoco.mj_forward(model, data)
renderer.update_scene(data)

media.show_image(renderer.render())

As you can see above, I modified the XML file following your advice, however, I got the following error message when I ran the code above:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[6], [line 20](vscode-notebook-cell:?execution_count=6&line=20)
      [9](vscode-notebook-cell:?execution_count=6&line=9) xml = r"""
     [10](vscode-notebook-cell:?execution_count=6&line=10) <mujoco model="hollow_cylinder_binary">
     [11](vscode-notebook-cell:?execution_count=6&line=11)   <worldbody>
   (...)
     [16](vscode-notebook-cell:?execution_count=6&line=16) </mujoco>
     [17](vscode-notebook-cell:?execution_count=6&line=17) """
     [19](vscode-notebook-cell:?execution_count=6&line=19) # Make model and data
---> [20](vscode-notebook-cell:?execution_count=6&line=20) model = mujoco.MjModel.from_xml_string(xml)
     [21](vscode-notebook-cell:?execution_count=6&line=21) data = mujoco.MjData(model)
     [23](vscode-notebook-cell:?execution_count=6&line=23) # Make renderer, render and show the pixels

ValueError: XML Error: Error: All nodes must be in single block
Element 'flexcomp', line 4

Here is the .msh file that I'm trying to use: hollow_cylinder_binary.zip

I desperately need to import this binary .msh file into MuJoCo for this project I'm doing. I've been able to import a binary STL file, however, the binary msh file approach is not working!

Thanks in advance!

kurtenkera avatar Mar 24 '24 22:03 kurtenkera

Hi, Mujoco supports a single entity. Your model has 18 points 24 curves 10 surfaces and 1 volume. In order for Mujoco to be able to read the file you need to remove points, curves and surface. Only leaving the volume. You can see these information by:

  1. loading your model in GMSH app
  2. Click on Tools -> Statistics
  3. In the Statistics window click on Geometry.

mohammad200h avatar Mar 25 '24 13:03 mohammad200h