physicalai-runtime-adding-a-robot-integration

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Adding a Robot Integration

添加机器人集成

Robots satisfy the structural
Robot
protocol in
src/physicalai/robot/interface.py
— no base class inheritance required. References:
src/physicalai/robot/so101/
,
src/physicalai/robot/trossen/
(WidowX). Connection helpers:
src/physicalai/robot/connect.py
; validation:
src/physicalai/robot/verify.py
.
机器人需满足
src/physicalai/robot/interface.py
中的结构化
Robot
协议——无需继承基类。参考示例:
src/physicalai/robot/so101/
src/physicalai/robot/trossen/
(WidowX机械臂)。连接辅助工具:
src/physicalai/robot/connect.py
;验证工具:
src/physicalai/robot/verify.py

Workflow

工作流程

  1. Read
    references/robot-protocol.md
    and an existing integration (SO-101 for serial servos, WidowX for arms).
    • Done when: required methods and observation shape are listed.
  2. Implement connect lifecycle: idempotent
    connect()
    ,
    disconnect()
    ,
    is_connected()
    .
  3. Observations: return a type exposing
    joint_positions
    ,
    timestamp
    (
    time.monotonic()
    ), optional
    sensor_data
    /
    images
    ; implement
    state
    property when inference expects more than positions.
  4. Actions:
    send_action(action, *, goal_time=...)
    with
    action
    shape matching training data conventions; document joint order via
    joint_names
    .
  5. Optional extra in
    pyproject.toml
    (
    physicalai[so101]
    ,
    physicalai[trossen]
    ); lazy-import vendor SDKs.
  6. Export public class from
    physicalai.robot
    when user-facing.
  7. Tests under
    tests/unit/robot/
    with mocked hardware.
    • Done when:
      uv run pytest tests/unit/robot -k <name>
      passes.
  8. Verification CLI/docs — wire
    verify.py
    patterns if the robot supports automated checks.
  1. **阅读
    references/robot-protocol.md
    **及现有集成示例(面向串行舵机的SO-101、面向机械臂的WidowX)。
    • 完成标志:列出所需方法和观测数据格式。
  2. 实现连接生命周期:幂等的
    connect()
    disconnect()
    is_connected()
    方法。
  3. 观测数据:返回一个包含
    joint_positions
    timestamp
    time.monotonic()
    )的类型,可选择性包含
    sensor_data
    /
    images
    ;当推理需要位置之外的更多信息时,实现
    state
    属性。
  4. 动作控制
    send_action(action, *, goal_time=...)
    方法,其中
    action
    的格式需匹配训练数据约定;通过
    joint_names
    记录关节顺序。
  5. 可选扩展包:在
    pyproject.toml
    中配置(
    physicalai[so101]
    physicalai[trossen]
    );延迟导入厂商SDK。
  6. 导出:若面向用户使用,需从
    physicalai.robot
    导出公开类。
  7. 测试:在
    tests/unit/robot/
    下编写基于硬件模拟的测试。
    • 完成标志:执行
      uv run pytest tests/unit/robot -k <name>
      测试通过。
  8. 验证CLI/文档:如果机器人支持自动化检查,按照
    verify.py
    的模式进行配置。

Required checks

必查项

  • isinstance(robot, Robot)
    at runtime (
    @runtime_checkable
    protocol).
  • No action sent when disconnected.
  • Joint count and
    joint_names
    stay stable across connect/disconnect.
  • Security: validate user-supplied port/path strings; no shell invocation with unsanitized device paths.
  • 运行时需检查
    isinstance(robot, Robot)
    @runtime_checkable
    协议)。
  • 未连接状态下不得发送动作指令。
  • 关节数量和
    joint_names
    在连接/断开过程中需保持稳定。
  • 安全性:验证用户提供的端口/路径字符串;不得使用未净化的设备路径执行shell命令。

References

参考资料

  • references/robot-protocol.md
  • docs/explanation/robots.md
  • references/robot-protocol.md
  • docs/explanation/robots.md