Skip to content

Instantly share code, notes, and snippets.

@traversaro
Last active December 13, 2023 12:08
Show Gist options
  • Save traversaro/a07efb8c9448ade704d8aace46f17e6f to your computer and use it in GitHub Desktop.
Save traversaro/a07efb8c9448ade704d8aace46f17e6f to your computer and use it in GitHub Desktop.
Reproduce mujoco parsing problem
import mujoco
import tempfile
model_urdf_string = """
<?xml version="1.0" encoding="utf-8"?>
<!--Create with rod using build_cartpole_model.py -->
<robot name="cartpole">
<link name="cart">
<inertial>
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/>
<mass value="1.0"/>
<inertia ixx="0.0035416666666666674" ixy="0.0" ixz="0.0" iyy="0.0010416666666666669" iyz="0.0" izz="0.0041666666666666675"/>
</inertial>
</link>
<link name="pole">
<inertial>
<origin xyz="0.0 0.0 0.5" rpy="0.0 0.0 0.0"/>
<mass value="0.1"/>
<inertia ixx="0.008333958333333334" ixy="0.0" ixz="0.0" iyy="0.008333958333333334" iyz="0.0" izz="1.25e-06"/>
</inertial>
</link>
<joint name="pivot" type="revolute">
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/>
<parent link="cart"/>
<child link="pole"/>
<axis xyz="1 0 0"/>
<limit effort="500.0" velocity="10.0" lower="-3.4028234663852886e+38" upper="3.4028234663852886e+38"/>
</joint>
</robot>
"""
mj_model_raw = mujoco.MjModel.from_xml_string(model_urdf_string)
path_temp_xml = tempfile.NamedTemporaryFile(mode="w+")
mujoco.mj_saveLastXML(path_temp_xml.name, mj_model_raw)
model_mjcf_string = path_temp_xml.read()
print(model_mjcf_string)
mj_model = mujoco.MjModel.from_xml_string(model_mjcf_string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment