mjcf_urdf_simple_converter
A minimal and simple script to convert limited elements of MJCF (MuJoCo modeling format) robot model files to URDF. Developed from a need to visualize MJCF robots in ROS environments like Rviz, it only converts a limited subset of the robot model elements to URDF.
The model file is loaded in the Python mujoco package, and its model elements are parsed using the library and then output according to the URDF XML format.
I do not intend to expand this into a full-fledged transclation script from MJCF to URDF.
installation
pip install mjcf-urdf-simple-converter
usage
from mjcf_urdf_simple_converter import convert
convert("model.xml", "model.urdf")
# or, if you are using it in your ROS package and would like for the mesh directories to be resolved correctly, set meshfile_prefix, for example:
convert("model.xml", "model.urdf", asset_file_prefix="package://your_package_name/model/")
This converts the model.xml (and any associated MJCF files loaded from within model.xml) to model.urdf. Mesh geoms are exported as OBJ/MTL pairs with baked-in color information and saved under the meshes/ directory. If the same mesh is used with different colors, separate OBJ/MTL files are generated with a color code appended to the filename. The converted files can be checked in Rviz, or online tools like https://gkjohnson.github.io/urdf-loaders/javascript/example/bundle/index.html (just drag & drop the URDF file and all the mesh OBJ/MTL files into the page).
what are converted
- links
- mesh geoms
- inertial information
- joints
- joint position, axis and limits (arbitrary values are set for effort and velocity limits)
- only hinge (revolute) joints are supported
only up to one joint per link is supported-> now supports multiple joints per body!
what are NOT converted
- actuators
- sensors
- tendons
- etc.
comments
- A similar tool exists to convert from MJCF to URDF (mjcf2urdf), but the pybullet import that it uses did not work for our case so this tool was created.
- for converting from URDF to MJCF, the
./compileprogram bundled with standard MuJoCo installations can be used.
how it works
in URDF, when a joint connects a parent and child body, the child body's origin is fixed to the position of the joint (https://wiki.ros.org/urdf/XML/joint). There is always only a single joint connecting the parent and child. On the other hand, for MJCFs there can be multiple joints defined in a body, and joints are defined within the child body element. Also, the body position is defined relative to the parent frame and it does not depend on the joint positions. Thus some conversions are necessary to translate the MJCF's kinematic structure to URDF.
The approach that I took in this code is to use just add many intermediate bodies whose relative poses are defined with fixed joints, to express each transformation. The add_dummy_body() function creates a body with negligible mass and inertia at the joint position, which creates an empty body, to which joints can be attached. This way, each actual body defined in the MJCF can keep using the same coordinate system
For example, if a body in the MJCF has 2 joints:
- a
revolutejoint connectsparent_bodytojoint1_jointbody - a
revolutejoint connectsjoint1_jointbodytojoint2_jointbody - a
fixedjoint connectsjoint2_jointbodytochild_body(this "brings back" the coordinate frame back to the MJCF child body's frame)
and the process is continued onwards to the next MJCF body.
Metadata
Release files for mjcf-urdf-simple-converter 0.7.3
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 | |
|---|---|---|---|---|
| mjcf_urdf_simple_converter-0.7.3.tar.gz | 7.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mjcf_urdf_simple_converter-0.7.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.0 kB
Release files / mjcf_urdf_simple_converter-0.7.3.tar.gz
| Download URL | mjcf_urdf_simple_converter-0.7.3.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b4286186fd016427ef44ffc2e41c56588398bd7fd0b7d883d412021a1b240684
|
|
BLAKE2b-256 checksum How to use checksums |
7e63dad6b981235c214a30941319f87ba29d6fffb94581252bb509831098d463
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.8
|
Release files / mjcf_urdf_simple_converter-0.7.3-py3-none-any.whl
| Download URL | mjcf_urdf_simple_converter-0.7.3-py3-none-any.whl |
|---|---|
| Size | 8.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d5d9dcb5f483e4040e51d53fad313f2872a14e778f7343044cd35e2b3d733616
|
|
BLAKE2b-256 checksum How to use checksums |
e7a3e068e9e6a73fee9dba987cd7432c9506060a923d106291fbe65c7a894c67
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.8
|
Security for mjcf-urdf-simple-converter 0.7.3
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.