Convert URDF to MuJoCo MJCF Without Installing Anything API + Python SDK
Source: Dev.to
The Problem
- MuJoCo is the fastest‑growing robotics simulator.
- Converting URDF to MJCF is painful: the
./compiletool is buggy,urdf2mjcfignores off‑diagonal inertia, and mesh paths often break. - You just want to convert and start training your RL agent.
The Solution
Curl
curl -X POST https://api.example.com/api/urdf/convert-format?target=mjcf \
-H "X-Api-Key: rk_..." \
-F "file=@robot.urdf"
Python SDK
import roboinfra
client = roboinfra.Client("rk_...")
result = client.urdf.convert_format("robot.urdf", "mjcf")
with open("robot.xml", "w") as f:
f.write(result.converted_xml)
Real Example (preview_test_arm.urdf)
- Input URDF – a robot with 6 links and 5 joints.
- Output MJCF – includes actuators, floor, and lighting.
This conversion would take 2–3 hours manually; the API completes it in ~200 ms.
Also Converts to Gazebo SDF
The same API can produce an SDF file; just change the target parameter:
curl -X POST https://api.example.com/api/urdf/convert-format?target=sdf \
-H "X-Api-Key: rk_..." \
-F "file=@robot.urdf"
The returned SDF output contains the equivalent Gazebo description.
Bonus: Validate + Convert in CI
Add a short GitHub Action to validate the URDF and convert it to MJCF on every push:
name: URDF Validation & Conversion
on: [push]
jobs:
convert:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Convert URDF to MJCF
run: |
curl -X POST https://api.example.com/api/urdf/convert-format?target=mjcf \
-H "X-Api-Key: ${{ secrets.ROBOINFRA_API_KEY }}" \
-F "file=@path/to/robot.urdf"
Free 14‑Day Pro Trial
Try the service for free—no credit card required.