Skip to content

Commit b2d35b6

Browse files
claudeMiaoDX
authored andcommitted
feat: add MuJoCo grasp end-to-end example (closes #2)
- Add examples/mujoco_grasp.py with inline MJCF model (table + cube + 2-finger gripper), scripted grasp sequence, multi-view checkpoint captures, and optional HTML report generation - Extend MuJoCoMeshcatBackend to accept xml_string parameter for loading models without external files - Add CI job (mujoco-example) that runs the example headlessly with OSMesa, uploads visual artifacts, and posts checkpoint images to the GitHub Actions step summary - Update README Quick Start with MuJoCo example instructions https://claude.ai/code/session_01T5U94fGksPxpXo1pvedUME
1 parent e8a5d75 commit b2d35b6

4 files changed

Lines changed: 417 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,57 @@ jobs:
3333
run: pip install -e ".[dev]"
3434
- name: Run tests
3535
run: pytest
36+
37+
mujoco-example:
38+
runs-on: ubuntu-latest
39+
steps:
40+
- uses: actions/checkout@v4
41+
- uses: actions/setup-python@v5
42+
with:
43+
python-version: "3.12"
44+
45+
- name: Install system dependencies (OSMesa for headless rendering)
46+
run: sudo apt-get update && sudo apt-get install -y libosmesa6-dev
47+
48+
- name: Install package with MuJoCo backend
49+
run: pip install -e ".[mujoco]" Pillow
50+
51+
- name: Run MuJoCo grasp example
52+
env:
53+
MUJOCO_GL: osmesa
54+
run: python examples/mujoco_grasp.py --report --output-dir ./harness_output
55+
56+
- name: Upload visual artifacts
57+
uses: actions/upload-artifact@v4
58+
with:
59+
name: mujoco-grasp-output
60+
path: |
61+
harness_output/report.html
62+
harness_output/mujoco_grasp/trial_001/**/*_rgb.png
63+
harness_output/mujoco_grasp/trial_001/**/metadata.json
64+
retention-days: 30
65+
66+
- name: Post summary with checkpoint images
67+
run: |
68+
echo "## MuJoCo Grasp Example Results" >> $GITHUB_STEP_SUMMARY
69+
echo "" >> $GITHUB_STEP_SUMMARY
70+
echo "Checkpoint captures from the scripted grasp sequence:" >> $GITHUB_STEP_SUMMARY
71+
echo "" >> $GITHUB_STEP_SUMMARY
72+
for cp in harness_output/mujoco_grasp/trial_001/*/; do
73+
name=$(basename "$cp")
74+
echo "### ${name}" >> $GITHUB_STEP_SUMMARY
75+
echo "" >> $GITHUB_STEP_SUMMARY
76+
# Embed front view as base64 in summary
77+
if [ -f "${cp}front_rgb.png" ]; then
78+
echo "![${name} front view](data:image/png;base64,$(base64 -w0 "${cp}front_rgb.png"))" >> $GITHUB_STEP_SUMMARY
79+
fi
80+
if [ -f "${cp}metadata.json" ]; then
81+
step=$(python3 -c "import json; print(json.load(open('${cp}metadata.json'))['step'])")
82+
sim_time=$(python3 -c "import json; print(f\"{json.load(open('${cp}metadata.json'))['sim_time']:.3f}\")")
83+
echo "" >> $GITHUB_STEP_SUMMARY
84+
echo "Step: ${step} | Sim time: ${sim_time}s" >> $GITHUB_STEP_SUMMARY
85+
fi
86+
echo "" >> $GITHUB_STEP_SUMMARY
87+
done
88+
echo "---" >> $GITHUB_STEP_SUMMARY
89+
echo "Download the full artifact (including HTML report) from the Actions tab." >> $GITHUB_STEP_SUMMARY

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ pip install robot-harness[dev]
5454

5555
## Quick Start
5656

57+
### MuJoCo Grasp Example (End-to-End)
58+
59+
Run a complete grasp simulation with zero external dependencies:
60+
61+
```bash
62+
pip install robot-harness[mujoco] Pillow
63+
python examples/mujoco_grasp.py --report
64+
```
65+
66+
This runs a scripted grasp sequence (hover → lower → grip → lift), captures multi-view screenshots at each checkpoint, and generates an HTML report. See [`examples/mujoco_grasp.py`](examples/mujoco_grasp.py) for the full source.
67+
5768
### Option 1: Gymnasium Wrapper (Zero-Change Integration)
5869

5970
Wrap any Gymnasium-compatible environment with one line:

0 commit comments

Comments
 (0)