mujoco
mujoco copied to clipboard
Unable to Build an XML file that reads in a binary MSH file?
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?):
Thanks in advance for any help or feedback!
Hi, Could you please send us the hollow_cylinder_binary.msh so we can replicate the issue?
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!
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?
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?):
Thanks in advance for any help or feedback!
Same problem here!
@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>
closing the issue due to inactivity. Feel free to open it :)
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!
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:
- loading your model in GMSH app
- Click on Tools -> Statistics
- In the Statistics window click on Geometry.