physicalai-runtime-running-policy-on-robot

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Running a Policy on a Robot

在机器人上运行策略

PolicyRuntime
(
src/physicalai/runtime/runtime.py
) owns the control loop;
InferenceModel
owns policy math. Execution strategy lives under
src/physicalai/runtime/execution.py
and
src/physicalai/runtime/rtc_execution.py
. CLI:
physicalai run
in
src/physicalai/cli/run.py
instantiates from YAML via jsonargparse.
PolicyRuntime
(
src/physicalai/runtime/runtime.py
) 负责控制循环;
InferenceModel
负责策略运算。执行策略定义在
src/physicalai/runtime/execution.py
src/physicalai/runtime/rtc_execution.py
中。CLI命令:
src/physicalai/cli/run.py
中的
physicalai run
通过jsonargparse从YAML文件实例化相关组件。

Workflow

工作流程

  1. Choose API vs config: Python for notebooks/tests; YAML +
    physicalai run
    for reproducible deployment.
    • Done when: entry point matches the user's task.
  2. Python minimal loop (see
    docs/how-to/runtime/run-policy-on-robot.md
    ):
    python
    from physicalai.runtime import PolicyRuntime, SyncExecution
    from physicalai.inference import InferenceModel
    from physicalai.robot import SO101
    from physicalai.capture import UVCCamera
    
    runtime = PolicyRuntime(
        fps=30,
        robot=SO101(port="/dev/ttyACM0"),
        model=InferenceModel("./exports/act_policy"),
        cameras={"wrist": UVCCamera(device="/dev/video0", width=640, height=480)},
        execution=SyncExecution(),
    )
    with runtime:
        runtime.run(duration_s=60)
    • Done when: components connect and the loop runs in a test or dry-run with fakes.
  3. YAML config — nest
    class_path
    /
    init_args
    for robot, model, cameras, execution; run:
    bash
    physicalai run --config runtime.yaml --run.duration_s=60
  4. Execution mode — pick sync vs RTC per
    docs/how-to/runtime/use-execution-modes.md
    ; do not build ad-hoc timing around
    InferenceModel.select_action
    when
    PolicyRuntime
    should own the queue.
  5. Callbacks — register via runtime callback APIs (
    docs/how-to/runtime/add-runtime-callbacks.md
    ) for telemetry/latency, not inside inference adapters.
  1. 选择API或配置文件:在笔记本/测试场景使用Python代码;在可复现的部署场景使用YAML配置 +
    physicalai run
    命令。
    • 完成标志:入口点与用户任务匹配。
  2. Python最小化循环(参考
    docs/how-to/runtime/run-policy-on-robot.md
    ):
    python
    from physicalai.runtime import PolicyRuntime, SyncExecution
    from physicalai.inference import InferenceModel
    from physicalai.robot import SO101
    from physicalai.capture import UVCCamera
    
    runtime = PolicyRuntime(
        fps=30,
        robot=SO101(port="/dev/ttyACM0"),
        model=InferenceModel("./exports/act_policy"),
        cameras={"wrist": UVCCamera(device="/dev/video0", width=640, height=480)},
        execution=SyncExecution(),
    )
    with runtime:
        runtime.run(duration_s=60)
    • 完成标志:组件成功连接,且循环在测试环境或使用模拟设备的试运行中正常运行。
  3. YAML配置 —— 为机器人、模型、摄像头、执行器嵌套
    class_path
    /
    init_args
    ;运行命令:
    bash
    physicalai run --config runtime.yaml --run.duration_s=60
  4. 执行模式 —— 根据
    docs/how-to/runtime/use-execution-modes.md
    选择同步模式或RTC模式;当
    PolicyRuntime
    应管理队列时,不要围绕
    InferenceModel.select_action
    构建临时计时逻辑。
  5. 回调函数 —— 通过运行时回调API(参考
    docs/how-to/runtime/add-runtime-callbacks.md
    )注册遥测/延迟相关回调,不要在推理适配器内部实现。

Validation loop

验证循环

bash
uv run pytest tests/unit/runtime/ -q
Use fake robots/cameras from runtime tests when hardware is unavailable.
bash
uv run pytest tests/unit/runtime/ -q
当硬件不可用时,使用运行时测试中的模拟机器人/摄像头。

Required checks

必要检查

  • fps
    and camera read rates are consistent.
  • Action dimensions match robot
    send_action
    expectations.
  • Config
    class_path
    targets are importable without training packages.
  • Document breaking changes to runtime config schema in
    docs/reference/config-schema.md
    .
  • fps
    与摄像头读取速率保持一致。
  • 动作维度符合机器人
    send_action
    的预期。
  • 配置中的
    class_path
    目标无需依赖训练包即可导入。
  • docs/reference/config-schema.md
    中记录运行时配置架构的重大变更。

References

参考资料

  • docs/how-to/runtime/run-policy-on-robot.md
  • docs/how-to/config/write-runtime-config.md
  • docs/how-to/runtime/run-policy-on-robot.md
  • docs/how-to/config/write-runtime-config.md