File size: 2,146 Bytes
8ca7ba0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from __future__ import annotations

import json
import subprocess
from pathlib import Path

from packages.adapters.arena import require_arena
from packages.robots.profiles import get_robot_profile
from packages.schemas.models import RobotCapabilityProfile


class RP13EmbodimentProvider:
    """RP1.3 provider boundary for the Isaac worker.

    USD conversion and articulation validation execute only inside the Arena worker. The
    core environment can still inspect the capability contract without importing Isaac.
    """

    def __init__(
        self,
        converter_command: list[str] | None = None,
        validator_command: list[str] | None = None,
    ) -> None:
        self.converter_command = converter_command
        self.validator_command = validator_command

    def profile(self) -> RobotCapabilityProfile:
        return get_robot_profile("rp1_3")

    def compose_robot_layer(self, output_dir: Path) -> Path:
        require_arena()
        if not self.converter_command:
            raise RuntimeError("RP1.3 converter command is not configured")
        output_dir.mkdir(parents=True, exist_ok=True)
        target = output_dir / "robot.usda"
        result = subprocess.run(
            [*self.converter_command, "--robot", "rp1_3", "--output", str(target)],
            check=False,
            capture_output=True,
            text=True,
        )
        if result.returncode or not target.exists():
            raise RuntimeError(f"RP1.3 conversion failed: {result.stderr[-2000:]}")
        return target

    def validate(self, root_usd: Path) -> dict[str, object]:
        require_arena()
        if not self.validator_command:
            raise RuntimeError("RP1.3 validator command is not configured")
        result = subprocess.run(
            [*self.validator_command, "--robot", "rp1_3", "--scene", str(root_usd)],
            check=False,
            capture_output=True,
            text=True,
        )
        if result.returncode:
            raise RuntimeError(f"RP1.3 validation failed: {result.stderr[-2000:]}")
        report: dict[str, object] = json.loads(result.stdout)
        return report