mjcf-to-urdf
Convert a MuJoCo MJCF robot to URDF, string in and string out, with no files written. Masses and inertias come from MuJoCo's compiled model (so inertia MuJoCo infers from geoms is right), links keep the MJCF body names, and mesh files are referenced as-is (never re-exported), with MuJoCo's mesh re-centering, scale, refpos and refquat folded into each mesh's <origin>/scale.
pip install mjcf-to-urdf
from mjcf_to_urdf import mjcf_to_urdf, mjcf_file_to_urdf, mjcf_spec_to_urdf
urdf = mjcf_file_to_urdf("robot/scene.xml") # mesh paths stay relative to robot/, as in the MJCF
urdf = mjcf_to_urdf(xml_text, mesh_dir="robot/meshes") # mesh_dir replaces the MJCF's meshdir
urdf = mjcf_to_urdf(xml_text, assets={"meshes/base.stl": stl_bytes})
urdf = mjcf_spec_to_urdf(mujoco.MjSpec.from_file("robot.xml"))
What maps to what
- Bodies become links named after the body; a body's link frame is its MuJoCo frame moved to its joint's anchor (identical when the joint sits at the body origin, as in most robots).
- Joints: hinge →
revolute(continuouswhen unlimited), slide →prismatic, ball → threecontinuousjoints about x, y, z (<name>_x/_y/_z), free on the root body → dropped (the root link is the floating base), free elsewhere →floating. A body with several joints gets massless intermediate links<joint>_link; bodies with one joint keep a single link. Limits come fromrange(shifted byref), effort fromactuatorfrcrange, an actuator'sforcerange, or a motor'sctrlrange, times its gear. Velocity is never written (MuJoCo has no joint velocity limit). - Inertials: compiled mass, center of mass and principal inertia (
ipos,iquat→ origin rpy, diagonal inertia). - Geoms: box, sphere, cylinder, mesh, and capsule as a cylinder plus a sphere at each end. Colliding geoms (
contype/conaffinitynonzero) become<collision>; non-colliding geoms in a default-visible group become<visual>with the material/geomrgba. A link with no visual geoms is drawn with its visible colliding geoms. - Root: the URDF root is the single body under the worldbody; a
worldlink is added only when there are several, or the robot is attached to the world by a joint.
Not converted: planes, ellipsoids, heightfields, SDF and inline-vertex meshes (skipped with a warning), ball-joint cone limits, tendons, equality constraints, sites, cameras, sensors, textures, and non-uniform mesh scale combined with refquat. Loading the URDF back into MuJoCo needs <compiler boundmass=... boundinertia=...> when a body has several joints, since MuJoCo rejects massless moving links.
Checked against MuJoCo
Tests load every URDF back into MuJoCo and compare link poses at random joint configurations, total mass and composite inertia against the original MJCF (uv run pytest; -m "not network" skips the robots cloned from GitHub). uv run python tests/compare.py compares with mjcf-urdf-simple-converter 0.7.3:
| robot | converter | joints | max link pos err (m) | max link rot err (rad) | mass err (rel) | inertia err (rel) | links | visual+collision |
|---|---|---|---|---|---|---|---|---|
| franka_emika_panda (11 bodies, 9 joints) | mjcf-to-urdf | 9 | 1.8e-09 | 8.4e-08 | 0.0e+00 | 2.0e-10 | 11 | 81 |
| mjcf-urdf-simple-converter | 7 | 8.5e-16 | 6.3e-08 | 5.2e-04 | 3.7e-04 | 21 | 71 | |
| Deep Robotics M20 (17 bodies, 17 joints) | mjcf-to-urdf | 16 | 1.7e-16 | 4.2e-08 | 0.0e+00 | 8.2e-12 | 17 | 44 |
| mjcf-urdf-simple-converter | 16 | 0.0e+00 | 4.2e-08 | 4.9e-04 | 6.4e-04 | 35 | 17 | |
| unitree_go2 (13 bodies, 13 joints) | mjcf-to-urdf | 12 | 6.9e-17 | 4.7e-08 | 0.0e+00 | 4.5e-10 | 13 | 56 |
| mjcf-urdf-simple-converter | 12 | 0.0e+00 | 4.7e-08 | 8.5e-04 | 1.1e-03 | 27 | 33 | |
| universal_robots_ur5e (7 bodies, 6 joints) | mjcf-to-urdf | 6 | 3.0e-09 | 5.2e-08 | 0.0e+00 | 3.0e-09 | 7 | 45 |
| mjcf-urdf-simple-converter | 6 | 2.5e-16 | 5.2e-08 | 2.9e-04 | 5.8e-04 | 14 | 20 |
mjcf-urdf-simple-converter drops slide joints (the panda's fingers) and primitive geoms, adds a dummy link per joint, and writes re-exported OBJ meshes to disk. Errors near 1e-8 are the 9 significant digits written.
Metadata
Release files for mjcf-to-urdf 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mjcf_to_urdf-0.1.0.tar.gz | 91.7 kB | Without provenance | Details for mjcf_to_urdf-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mjcf_to_urdf-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for mjcf_to_urdf-0.1.0-py3-none-any.whl |
Total release size: 100.5 kB
Release files / mjcf_to_urdf-0.1.0.tar.gz
| Download URL | mjcf_to_urdf-0.1.0.tar.gz |
|---|---|
| Size | 91.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fb08e23c216f6e34ce60b0ce696a8c9cb489931b330ae70dfac06b22c0aefda5
|
|
BLAKE2b-256 checksum How to use checksums |
a9873790c9daabc63cd72b79a9a8fdb89a626d5ed8073de9cc03671f17a784e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.12
|
Release files / mjcf_to_urdf-0.1.0-py3-none-any.whl
| Download URL | mjcf_to_urdf-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fcfe95b08bbcd24576cfa6270a6a233f83e2222c4d92ea7c1307f4adf560cd21
|
|
BLAKE2b-256 checksum How to use checksums |
cb673fa83e804d68a081fbdfdceea7621efbbfa6400aee90ca9cb69268c8fddd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.12
|
Security for mjcf-to-urdf 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.