i7 接口参考
===========

本页用于 i7，公共约定见 :doc:`../sdk/api_common`。
共用状态结构保留的头部或五轴躯干字段不代表 i7 装配这些单元。
底盘相对运动等扩展操作依赖控制器后端；未验证能力不可仅凭方法存在判断可用。

.. _3-robot-生命周期与状态:

3. ``Robot`` 生命周期与状态
---------------------------

.. _31-robot:

3.1 ``Robot(...)``
~~~~~~~~~~~~~~~~~~

**摘要：** 创建 Robot 客户端；构造过程不建立网络连接。默认 ``Control`` 模式会在
``connect()`` 时参与控制仲裁；``ReadOnly`` 模式只建立 Observer 状态链路，不占用控制租约。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   explicit Robot(const std::string &ip);
   Robot(const std::string &ip, RobotOptions options);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   low_level.Robot(ip: str)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. list-table::
   :header-rows: 1
   :widths: 20 80

   * - 参数
     - 说明
   * - ``ip``
     - 控制器 IPv4/IPv6 地址或可解析主机名
   * - ``options``
     - ``app_name`` 用于诊断，\ ``priority`` 用于控制权仲裁；
       ``connect_timeout``\ （C++）或 ``connect_timeout_ms``\ （Python）设置 TCP
       建连超时，默认 5 秒且必须大于 0

**返回值：** C++ 和 Python 构造调用均返回新对象；创建原生句柄
失败时抛出异常。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   srobots::Robot robot("192.168.6.1");

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot = low_level.Robot("192.168.6.1")

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _37-control-state:

控制状态与只读回退
~~~~~~~~~~~~~~~~~~~~~~~~

``isConnected()`` 表示控制链路或内部 Observer 链路任意一条可用；它不表示当前拥有
控制租约。使用 ``hasControl()`` 获取瞬时提示，使用 ``requireControl()`` 主动重新参与
仲裁；控制连接被抢占后，SDK 保留 ``CONTROL_PREEMPTED`` 作为写操作
错误，并自动尝试建立 Observer；只读状态查询和状态订阅在 Observer 成功时继续工作。

Observer 回退支持基于 ``RobotState`` 的 ``getLatestState()``、状态订阅、``getMode()``、
``isEnabled()``、``hasFault()`` 和 ``waitOperational()``。运动、使能、模式切换及其他控制
RPC 始终要求 ``hasControl() == true``。``info()`` 和 ``getModel()`` 依赖控制握手阶段缓存的
metadata/URDF；纯 ``ReadOnly`` 实例不保证具备这些缓存。

``setAutoControlRecovery(true)`` 默认关闭。打开后，SDK 只在 Observer 收到 Server 的
``Available`` hint 上升沿时尝试恢复控制，不会因为 hint 主动抢占其他 owner；恢复失败
仍保留只读状态链路，并等待下一次 ``Unavailable -> Available`` 上升沿后重试，不会在
同一个 ``Available`` 状态下循环建连。``onControlStateChanged()`` 报告 ``Control``、
``ReadOnly``、``Recovering`` 和 ``Offline`` 状态及原因。


.. _32-connect:

3.2 ``connect()``
~~~~~~~~~~~~~~~~~

**摘要：** 建立 RPC、实时状态和实时命令通道。TCP 建连受构造 options 中的超时
约束，默认最多等待 5 秒。

**参数：** 无。

**返回值：** C++ 返回 ``ResultCode``\ ；Python 成功时返回 ``None``\ ，失败时抛出
``RobotError``\ 。
错误码会保留控制权仲裁拒绝和连接失败的具体原因。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = robot.connect();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot.connect()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _33-disconnect:

3.3 ``disconnect()``
~~~~~~~~~~~~~~~~~~~~

**摘要：** 关闭控制器连接并释放连接相关资源。

**参数：** 无。

**返回值：** C++ 返回 ``ResultCode``\ ；Python 成功时返回 ``None``\ ，失败时抛出
``RobotError``\ ；
从 C++ ``Robot`` 回调内同步调用时返回 ``PreconditionFailed``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = robot.disconnect();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot.disconnect()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _34-isconnected--is_connected:

3.4 ``isConnected()`` / ``is_connected()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 查询客户端当前是否连接。

**参数：** 无。

**返回值：** 两种语言均返回布尔值；\ ``true`` 表示已连接，\ ``false`` 表示未连接。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   if (robot.isConnected()) { /* connected */ }

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   connected = robot.is_connected()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _35-ondisconnected:

3.5 ``onDisconnected()``
~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 注册意外断开回调。Python 使用 ``on_disconnected()``\ 。

============ ====================================================
参数         说明
============ ====================================================
``callback`` 接收 ``DisconnectReason`` 的回调；可能在内部线程执行
============ ====================================================

**返回值：** C++ 返回 ``ResultCode``\ ；Python 成功时无返回值，
失败时抛出 ``RobotError``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = robot.onDisconnected([](srobots::DisconnectReason reason) {
     // 仅记录状态或通知其他线程，避免在回调中阻塞。
   });

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot.on_disconnected(lambda reason: print("disconnected", reason))

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>


.. _36-hasfault--has_fault:

3.6 ``hasFault()`` / ``has_fault()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 查询机器人系统是否存在活动故障。

**参数：** 无。

**返回值：** 两种语言均返回布尔值；\ ``true`` 表示存在故障，\ ``false`` 表示当前
未报告故障。Python 在通信失败时抛出 ``RobotError``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const bool faulted = robot.hasFault();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   faulted = robot.has_fault()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _37-clearfaultblocking--clear_fault_blocking--clearfault:

3.7 ``clearFaultBlocking()`` / ``clear_fault_blocking()`` / ``clearFault()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 请求清除故障，并阻塞等待清除结果。

=============== =========================
参数            说明
=============== =========================
``timeout_sec`` 最长等待秒数，默认 ``30``
=============== =========================

**返回值：** C++ 返回 ``ResultCode``\ ；Python 成功时返回 ``None``\ ，超时或请求失败时
抛出 ``RobotError``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = robot.clearFaultBlocking(10);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot.clear_fault_blocking(timeout_sec=10)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _38-enable:

3.8 ``enable()``
~~~~~~~~~~~~~~~~

**摘要：** 使能机器人执行机构。调用前必须确认无故障、急停已释放且现场安全。

**参数：** 无。

**返回值：** C++ 返回 ``ResultCode``\ ；Python 成功时返回 ``None``\ ，失败时抛出
``RobotError``\ 。

服务端配置 ``enable_disable_units`` 决定全局使能／去使能的模块范围。
IX 可配置 ``[LeftArm, RightArm, Torso, Head]``；I7 自动使能的升降模块可不列入。
省略此配置时，服务端保留双臂和适用夹爪的行为。列表不会触发启动自动使能。

配置化服务端等待所选模块完成后统一回包；某模块使能失败时停止后续使能，并
返回失败，前面已经使能的模块保持现状。服务端总等待预算为 2.5 秒，SDK 的
Enable／Disable RPC 等待上限为 3 秒。旧服务端的全局使能范围仍由旧实现决定。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = robot.enable();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot.enable()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _39-disable:

3.9 ``disable()``
~~~~~~~~~~~~~~~~~

**摘要：** 去使能机器人执行机构。

**参数：** 无。

**返回值：** C++ 返回 ``ResultCode``\ ；Python 成功时返回 ``None``\ ，失败时抛出
``RobotError``\ 。

使用与 ``enable()`` 相同的服务端模块列表。某模块去使能失败时，服务端仍尝试
其余模块，统一返回失败及首个失败模块。未列入的 I7 自动升降模块不受此调用影响。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = robot.disable();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot.disable()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _310-isenabled--is_enabled:

3.10 ``isEnabled()`` / ``is_enabled()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 查询指定运动单元是否已使能。

支持左右臂，以及机器人连接信息中轴数非零的 ``Torso`` 和 ``Head``。
I7 可查询单轴躯干，查询其不存在的头部返回 ``NotSupported``；IX 可查询五轴
躯干和两轴头部。查询读取对应模块的反馈，不会触发使能。反馈同时包含已使能
和故障／急停标志时，返回失败而非已使能。

========= ==================================
参数      说明
========= ==================================
``unit``  要查询的 ``MotionUnit``
``error`` 仅 C++；可选输出参数，接收失败详情
========= ==================================

**返回值：** 已使能返回 ``true``\ ；未使能或查询失败返回 ``false``\ 。C++ 可通过
``error`` 区分这两种情况；Python 查询失败时抛出 ``RobotError``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   srobots::ResultCode error;
   const bool enabled = robot.isEnabled(srobots::MotionUnit::LeftArm, &error);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   enabled = robot.is_enabled(low_level.MotionUnit.LEFT_ARM)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _311-getmode--get_mode:

3.11 ``getMode()`` / ``get_mode()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 查询指定运动单元的当前控制模式；不改变模式。

========= ==================================
参数      说明
========= ==================================
``unit``  要查询的 ``MotionUnit``
``error`` 仅 C++；可选输出参数，接收失败详情
========= ==================================

**返回值：** 当前 ``Mode``\ ；无法确定时可能返回 ``UNKNOWN``\ 。查询 ``DualArm`` 时，
如果左右臂模式不一致，C++ 通过 ``error`` 返回 ``PreconditionFailed``\ ，Python 抛出
``RobotError``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto mode = robot.getMode(srobots::MotionUnit::LeftArm);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   mode = robot.get_mode(low_level.MotionUnit.LEFT_ARM)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _312-waitoperational--wait_operational:

3.12 ``waitOperational()`` / ``wait_operational()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 阻塞等待机器人进入可运行状态。

**参数：** 无。

**返回值：** C++ 和 Python 返回 ``ResultCode``\ 。两臂均使能时成功，等待
超时使用 ``TIMEOUT``\ ，连接中断时使用对应连接错误码。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = robot.waitOperational();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   code = robot.wait_operational()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _313-info--get_info--getinfo:

3.13 ``info()`` / ``get_info()`` / ``getInfo()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 获取机器人静态信息。

**参数：** 无。

**返回值：** C++ 返回 ``RobotInfo``\ ；Python 返回包含对应字段的 ``dict``\ ；
连接成功后，
``software_ver``/``softwareVer`` 包含握手期间取得的控制器版本。

躯干和头部的实际轴数由配置决定。C++ 使用 ``DoF_torso``、``DoF_head``、
``has_head``、``torso_position_unit``；躯干单位枚举为
``JointPositionUnit::Meter`` 或 ``JointPositionUnit::Radian``。
Python 对应字段为 ``dof_torso``、``dof_head``、``has_head``、
``torso_position_unit``；躯干单位字符串为 ``"m"``、
``"rad"``，未指定时为 ``"unspecified"``。

I7 躯干为 1 轴、单位 m，头部为 0 轴；IX 躯干为 5 轴、头部为 2 轴，单位均为 rad。
头部位置单位固定为 rad，无需配置或通过握手单独传递。
速度单位为相应的位置单位每秒。配置轴数不会因未使能或掉线而缩减。
状态数组仍保留躯干 5、头部 2 的容量，只使用实际轴数对应的前缀。
``info()`` 包含字符串与限位容器，应在控制循环外读取并保存所需字段。

本次更新要求 SDK 与 Server 同步升级。连接握手缺少轴数/单位信息或信息不一致时，
SDK 返回 ``VersionMismatch``，不根据机型名称猜测。此信息仅描述结构与单位，
不代表模块已经支持特定控制模式或使能操作。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const srobots::RobotInfo info = robot.info();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   info = robot.get_info()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _314-queryreachability--query_reachability:

3.14 ``queryReachability()`` / ``query_reachability()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 查询指定机械臂末端位姿所在的可达工作空间区域。当前仅支持
``SRobot-i7``
模型；分类器只使用位姿中的位置 ``[x, y, z]``，但七个输入值（包括四元数）都必须是有限数。
边界点属于工作空间内部。

================= ==============================================
参数              说明
================= ==============================================
``arm``           ``ArmId.Left`` / ``ArmId.Right``；Python 使用 ``ArmId.LEFT`` / ``RIGHT``
``ee_pose``       7 个元素 ``[x, y, z, qx, qy, qz, qw]``，位置单位为 m
================= ==============================================

**返回值：** C++ 返回 ``WorkspaceQueryResult`` ，其中 ``valid`` 表示查询是否有效，
``reachable``、``near_dexterous`` 和 ``dexterous`` 表示对应区域属性，
``region`` 为 ``Unreachable``、 ``Reachable``、 ``NearDexterous``、 ``Dexterous``
或 ``Invalid``。Python 返回包含相同布尔字段的 ``dict`` ，但 ``region`` 为
``"unreachable"``、 ``"reachable"``、 ``"near_dexterous"``、 ``"dexterous"``
或 ``"invalid"`` 字符串。

未知模型或工作空间数据不可用时，C++ 抛出 ``RobotError``，错误码为
``ResultCode::NotSupported``；输入不是七个元素、包含非有限数或查询结果无效时，
分别抛出参数错误或无效查询错误。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const std::array<double, 7> pose{-0.10, -0.50, 1.70, 0.0, 0.0, 0.0, 1.0};
   const auto result = robot.queryReachability(srobots::ArmId::Right, pose);
   if (result.valid && result.region == srobots::WorkspaceRegion::Dexterous) {
     // 位姿位于灵巧工作空间。
   }

.. container:: sdk-example-reference

   参考示例：``examples/cpp/read_robot_model_and_workspace.cpp``

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   from srobots import low_level

   result = robot.query_reachability(
       low_level.ArmId.RIGHT,
       [-0.10, -0.50, 1.70, 0.0, 0.0, 0.0, 1.0],
   )
   if result["valid"]:
       print(result["region"])

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>


.. _315-getlateststate--get_latest_state--waitforlateststate:

3.15 ``getLatestState()`` / ``get_latest_state()`` / ``waitForLatestState()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 获取最新完整状态快照。阻塞读取等待比该读取器上次所见更新的状态；
没有新状态不等同于连接失败。

============= =================================
参数          说明
============= =================================
``out_state`` 仅 C++；成功时写入 ``RobotState``
``blocking``  是否等待新状态，默认 ``true``
============= =================================

**返回值：** C++ 返回是否写入状态；Python 返回 ``(ok, state)``\ 。
仅当返回 ``true`` 或 ``ok`` 为 ``true`` 时使用状态值。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   srobots::RobotState state;
   if (robot.getLatestState(state, true)) {
     const auto &q = state.left.q;
   }

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   ok, state = robot.get_latest_state(blocking=True)
   if ok:
       left_q = list(state.left.q)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _316-subscribestate--subscribe_state:

3.16 ``subscribeState()`` / ``subscribe_state()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 注册周期性状态回调。回调在内部线程执行，必须快速返回。

============= ======================================
参数          说明
============= ======================================
``callback``  接收状态快照的回调
``user_data`` 仅 Python；可选用户对象，默认 ``None``
============= ======================================

**返回值：** C++ 返回 ``ResultCode``\ ；Python 成功时无返回值，
失败时抛出 ``RobotError``\ 。Python 未提供 ``user_data`` 时调用
``callback(state)``\ ，提供后调用 ``callback(state, user_data)``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = robot.subscribeState([](const srobots::RobotState &state) {
     const auto timestamp = state.timestamp_remote_us;
   });

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot.subscribe_state(lambda state: print(state.timestamp_remote_us))

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _317-主要状态类型:

3.17 主要状态类型
~~~~~~~~~~~~~~~~~

.. list-table::
   :header-rows: 1

   * - 类型
     - 主要字段
   * - ``RobotState``
     - ``timestamp_remote_us``\ 、\ ``timestamp_local_us``\ 、\ ``duration_us``\ 、\ ``left``\ 、\ ``right``\ 、\ ``torso``\ 、夹爪、底盘、灵巧手和整机状态
   * - ``ArmState``
     - ``status``\ 、\ ``mode``\ 、\ ``q``\ 、\ ``dq``\ 、\ ``tau``\ 、\ ``drive_error_code``\ 、\ ``eepose``\ 、\ ``ee_wrench``
   * - ``GripperState``
     - ``status``\ 、\ ``mode``\ 、\ ``q``\ 、\ ``dq``\ 、\ ``tau``\ 、\ ``drive_error_code``
   * - ``TorsoState``
     - ``status``\ 、\ ``mode``\ 、\ ``q``\ 、\ ``dq``\ 、\ ``tau``\ 、\ ``drive_error_code``
   * - ``HandState``
     - ``status``\ 、\ ``joint_count``\ 、\ ``q``\ 、\ ``tau``\ 、\ ``grasp_state``
   * - ``ChassisIoTelemetry``
     - ``vx``\ 、\ ``vy``\ 、\ ``wz``\ 、\ ``batt_pct``


字段单位和有效范围：

- ``timestamp_remote_us``\ 、\ ``timestamp_local_us`` 和 ``duration_us`` 的单位均为
  微秒；状态对象拥有全部嵌套数据，读取后可独立保存。
- ``ArmState.q``\ 、\ ``dq`` 和 ``tau`` 分别为 7 个 rad、rad/s 和 N·m 值；
  ``eepose`` 按 ``[x, y, z, qx, qy, qz, qw]`` 排列，\ ``ee_wrench`` 按
  ``[fx, fy, fz, mx, my, mz]`` 排列。
- ``TorsoState`` 的单位由机器人躯干结构决定：按直线位移定义的配置使用 m 和
  m/s；IX 五个旋转关节使用 rad 和 rad/s。IX 的顺序和接口限制见
  :doc:`IX 接口使用指南 <../sdk/ix_interface_guide>`。\ ``ChassisIoTelemetry.vx``、
  ``vy`` 和 ``wz`` 使用 m/s、m/s 和 rad/s。
- 灵巧手数组的容量为 ``SROBOTS_HAND_DOF = 12``\ ，仅前 ``joint_count`` 个元素
  有效；每个 ``drive_error_code`` 数组中的零值表示对应驱动器未报告错误。
- ``HandState.finger_force`` 保留五指的法向、切向 X 和切向 Y 力，单位为 N，
  传输分辨率为 0.01 N，范围为 [-327.68, 327.67] N。``valid_mask`` 的
  低三位分别标记三个分量是否有效；全零表示不可用。

.. _318-robotstatelocalslot--robotstatelocalreader:

3.18 ``RobotStateLocalSlot`` / ``RobotStateLocalReader``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 在进程内发布和读取最新 ``RobotState``\ 。每个
``RobotStateLocalReader`` 独立记录上次读到的远端时间戳，因此只返回对该读取器
而言更新的样本。

+----------------------------------+-----------------------------------+
| API                              | 说明                              |
+==================================+===================================+
| ``slot.publish(state)``          | 发布状态并唤醒等待中的读取器      |
+----------------------------------+-----------------------------------+
| ``slot.close()`` / ``reopen()``  | 结束或恢复阻塞等待                |
+----------------------------------+-----------------------------------+
| ``slot.reset()``                 | 清空样本、时间戳和关闭状态        |
+----------------------------------+-----------------------------------+
| ``reader.init(&slot)``           | 绑定数据槽并重置读取进度          |
+----------------------------------+-----------------------------------+
| ``reader.latest(out, blocking)`` | 阻塞或非阻塞读取新样本            |
+----------------------------------+-----------------------------------+
| ``reader.latest(out, timeout)``  | 最多等待指定                      |
|                                  | ``std::chrono::milliseconds``     |
+----------------------------------+-----------------------------------+

**返回值：** ``latest()`` 读到新样本时返回 ``true``\ ；未绑定数据槽、没有新样本、
超时或数据槽关闭且没有更新样本时返回 ``false``\ 。
Python 也提供同名数据槽和读取器。动态语言的
``reader.latest()`` 直接返回新状态；无新样本、超时或关闭时返回 ``None``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   srobots::RobotStateLocalSlot slot;
   srobots::RobotStateLocalReader reader(&slot);
   slot.publish(state);

   srobots::RobotState snapshot;
   const bool updated =
       reader.latest(snapshot, std::chrono::milliseconds(100));

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   slot = low_level.RobotStateLocalSlot()
   reader = low_level.RobotStateLocalReader(slot)
   slot.publish(state)
   latest = reader.latest(blocking=False)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _4-模式与低层命令:

4. 模式与低层命令
-----------------

.. _41-switchmode--switch_mode:

4.1 ``switchMode()`` / ``switch_mode()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 切换指定运动单元的控制模式。命令类型必须与目标模式匹配。

======== ===================
参数     说明
======== ===================
``unit`` 目标 ``MotionUnit``
``mode`` 目标 ``Mode``
======== ===================

**返回值：** C++ 返回 ``ResultCode``\ ；Python 成功时返回 ``None``\ ，失败时抛出
``RobotError``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = robot.switchMode(srobots::MotionUnit::LeftArm,
                                      srobots::Mode::NRT_JOINT_POSITION);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot.switch_mode(low_level.MotionUnit.LEFT_ARM,
                     low_level.Mode.NRT_JOINT_POSITION)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _42-executertcommands--execute_rt_commands:

4.2 ``executeRTCommands()`` / ``execute_rt_commands()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 一次发送一项或多项 RT 命令。该 API 不维持控制周期，调用方必须按
控制器要求持续调用。

======================= ===============================================
参数                    说明
======================= ===============================================
``cmds`` / ``commands`` RT 命令视图数组；数组内容必须符合运动单元和模式
``n``                   仅 C++；命令数
======================= ===============================================

直接构造 C++ ``RTCommandView`` 时，必须同时填写所用指针及其
``left_size``\ 、\ ``right_size``\ 、\ ``pose_size``\ 、\ ``wrench_size``\ ；未使用的指针保持为空，
对应长度设为 ``0``\ 。Python 绑定根据数组长度自动填写这些字段。

**返回值：** C++ 返回 ``ResultCode``\ ；Python 成功时返回 ``None``\ ，参数、模式或
通信失败时抛出 ``RobotError``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code =
       robot.executeRTCommands(commands.data(), commands.size());

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot.execute_rt_commands([command])

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _43-executenrtcommands--execute_nrt_commands:

4.3 ``executeNRTCommands()`` / ``execute_nrt_commands()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 一次提交一项或多项 NRT 命令。

======================= ===============================================
参数                    说明
======================= ===============================================
``cmds`` / ``commands`` NRT 命令视图数组；机械臂关节数组必须有 7 个元素
``n``                   仅 C++；命令数
======================= ===============================================

直接构造 C++ ``NRTCommandView`` 时，必须为可选位姿和力/力矩数据填写
``pose_size`` 和 ``wrench_size``\ ；Python 绑定根据数组长度自动填写。

**返回值：** C++ 返回 ``ResultCode``\ ；Python 成功时返回 ``None``\ ，参数、模式或
通信失败时抛出 ``RobotError``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code =
       robot.executeNRTCommands(commands.data(), commands.size());

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot.execute_nrt_commands([command])

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _44-movert:

4.4 ``moveRT()``
~~~~~~~~~~~~~~~~

**摘要：** C++ 提供编译期类型安全的 RT 命令模板。Python 的 ``move_rt()`` 接受一个或多个动态命令视图，并复用第 4.2 节的验证。

低层 NRT 和 RT 的躯干、头部关节数组可以使用实际轴数，或使用完整预留容量。
例如 I7 躯干接受长度 1 或 5，只读取第一个元素，其余元素完全忽略，不要求为零。
长度 2、3、4 属于维度错误。IX 躯干需要 5 个有效元素。
只有有效前缀参与数值校验；对不存在的模块发命令返回 ``NotSupported``。
RT 包仍为固定布局，NRT 消息只携带有效关节数据。轴数适配不增加 RT 路径的动态分配。

=========== ====================================
参数        说明
=========== ====================================
``cmds...`` 一个或多个 RT ``JointStreamCommand``
=========== ====================================

**返回值：** ``ResultCode``\ ；非 RT 类型在编译期报错，运行时错误由返回码表示。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = robot.moveRT(left_command, right_command);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot.move_rt(left_command, right_command)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _45-movenrt:

4.5 ``moveNRT()``
~~~~~~~~~~~~~~~~~

**摘要：** C++ 提供编译期类型安全的 NRT 命令模板。Python 的 ``move_nrt()`` 接受一个或多个动态命令视图。

=========== =====================================
参数        说明
=========== =====================================
``cmds...`` 一个或多个 NRT ``JointStreamCommand``
=========== =====================================

**返回值：** ``ResultCode``\ ；非 NRT 类型在编译期报错，运行时错误由返回码表示。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = robot.moveNRT(left_command, right_command);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot.move_nrt(left_command, gripper_command)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _46-resetzeroposition:

4.6 ``resetZeroPosition()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 重置指定运动单元的零位。Python 使用
``reset_zero_position(unit)``\ 。

======== =======================
参数     说明
======== =======================
``unit`` 要重置的 ``MotionUnit``
======== =======================

**返回值：** C++ 返回 ``ResultCode``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code =
       robot.resetZeroPosition(srobots::MotionUnit::Torso);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot.reset_zero_position(low_level.MotionUnit.Torso)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>


.. _5-夹爪底盘与躯干:

5. 夹爪、底盘与躯干
-------------------

.. _51-movegripper--move_gripper:

5.1 ``moveGripper()`` / ``move_gripper()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 向左或右夹爪发送位置、速度和力命令。

============ ===========================================
参数         说明
============ ===========================================
``unit``     ``LeftHandGripper`` 或 ``RightHandGripper``
``position`` 目标位置，默认 ``0.0``
``velocity`` 目标速度，默认 ``0.0``
``force``    目标力，默认 ``50.0``
============ ===========================================

**返回值：** C++ 返回 ``ResultCode``\ ；Python 成功时返回 ``None``\ ，失败时抛出
``RobotError``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = robot.moveGripper(
       srobots::MotionUnit::LeftHandGripper, 0.02, 0.05, 20.0);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot.move_gripper(low_level.MotionUnit.LEFT_HAND_GRIPPER,
                      position=0.02, velocity=0.05, force=20.0)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _52-opengripper--closegripper:

5.2 ``openGripper()`` / ``closeGripper()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 夹爪全开或全闭便捷操作。Python 使用 ``move_gripper()`` 指定位置。

======== ================
参数     说明
======== ================
``unit`` 目标夹爪运动单元
======== ================

**返回值：** C++ 返回 ``ResultCode``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto open_code =
       robot.openGripper(srobots::MotionUnit::LeftHandGripper);
   const auto close_code =
       robot.closeGripper(srobots::MotionUnit::LeftHandGripper);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot.move_gripper(low_level.MotionUnit.LeftGripper,
                      position=0.0, velocity=0.1, force=20.0)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>


.. _53-getgripperforceprotect--get_gripper_force_protect:

5.3 ``getGripperForceProtect()`` / ``get_gripper_force_protect()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 查询全局夹爪力保护配置。

=========== ====================
参数        说明
=========== ====================
``enabled`` 仅 C++；接收开关状态
=========== ====================

**返回值：** C++ 返回 ``ResultCode`` 并写入 ``enabled``\ ；Python 返回布尔值，失败时
抛出 ``RobotError``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   bool enabled = false;
   const auto code = robot.getGripperForceProtect(enabled);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   enabled = robot.get_gripper_force_protect()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _54-setgripperforceprotect--set_gripper_force_protect:

5.4 ``setGripperForceProtect()`` / ``set_gripper_force_protect()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 设置全局夹爪力保护；控制器必须处于 ``Standby`` 或 ``Initializing``\ 。

=========== ===============================
参数        说明
=========== ===============================
``enabled`` ``true`` 开启，\ ``false`` 关闭
=========== ===============================

**返回值：** C++ 返回 ``ResultCode``\ ；Python 成功时返回 ``None``\ ，失败时抛出
``RobotError``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = robot.setGripperForceProtect(true);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot.set_gripper_force_protect(True)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _55-chassismovevelocity--move_chassis_velocity:

5.5 ``Chassis::moveVelocity()`` / ``move_chassis_velocity()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 发送底盘速度命令。

====== ==========
参数   说明
====== ==========
``vx`` 前后线速度
``vy`` 横向线速度
``wz`` 偏航角速度
====== ==========

**返回值：** C++ 返回 ``ResultCode``\ ；Python 成功时返回 ``None``\ ，失败时抛出
``RobotError``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = robot.chassis().moveVelocity(0.1, 0.0, 0.0);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot.move_chassis_velocity(0.1, 0.0, 0.0)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _56-submitmoverelative--submit_chassis_move_relative--submitchassismoverelative:

5.6 ``submitMoveRelative()`` / ``submit_chassis_move_relative()`` / ``submitChassisMoveRelative()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 提交一次底盘相对位移，并取得命令 ID。

================ ===================
参数             说明
================ ===================
``x``\ 、\ ``y`` 相对平移距离
``yaw``          相对偏航角
``command_id``   仅 C++；接收命令 ID
================ ===================

**返回值：** C++ 返回 ``ResultCode`` 并写入 ``command_id``\ ；Python 返回命令 ID，
失败时抛出 ``RobotError``\ 。

**坐标系与适用范围：** ``x``\ 、\ ``y`` 和 ``yaw`` 是**提交瞬间**
``base_link`` 坐标系下的相对 SE(2) 位移：正 ``x`` 为当时车头前进方向，正 ``y``
为当时左移，正 ``yaw`` 为逆时针转向。IX mobile MuJoCo 的执行器会在接收命令时读取
底盘的 world pose，并把这个 body-relative 增量冻结为一个 world-frame 目标；执行过程
产生的内部速度同样处于 world frame。因此，本接口不会改变
``moveChassisVelocity()`` / ``move_chassis_velocity()`` 的既有 WORLD-frame 速度语义。

目前 M8 executor 只由 ``robot_ix_urdf_mobile_mujoco.yaml`` 明确启用。fixed IX、旧
IX、Gento 和 SHM-only chassis simulator 不会因为调用该 API 而新增相对位移执行器。
调用方应在提交前切换到 chassis velocity mode，并通过 5.7 的状态接口等待终态；不应
把全零位移当作取消操作。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   std::uint64_t id = 0;
   const auto code = robot.chassis().submitMoveRelative(0.2, 0.0, 0.0, id);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   command_id = robot.submit_chassis_move_relative(0.2, 0.0, 0.0)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _57-getmoverelativestatus--get_chassis_move_relative_status--getchassismoverelativestatus:

5.7 ``getMoveRelativeStatus()`` / ``get_chassis_move_relative_status()`` / ``getChassisMoveRelativeStatus()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 查询相对移动的阶段、错误、消息和进度。

============== ==========================================
参数           说明
============== ==========================================
``command_id`` 提交时返回的命令 ID
``status``     仅 C++；接收 ``ChassisMoveRelativeStatus``
============== ==========================================

**返回值：** C++ 返回 ``ResultCode`` 并写入 ``status``\ ；Python 返回状态对象，失败
时抛出 ``RobotError``\ 。

M8 的正常生命周期为 ``Pending → Running → Succeeded``。``progress`` 始终位于
``[0, 1]``，成功时为 ``1``。超时、MuJoCo plant/state 错误、失去控制权或离开 chassis
velocity mode 会进入 ``Failed`` 并携带非零 ``error_code``；显式取消和有效的新的
``moveChassisVelocity()`` 速度流抢占会进入 ``Canceled``。终态公布后，底盘仍可能按既有
加速度限幅进行一小段受控减速，应用应等待 applied chassis feedback 归零，而不是把
终态瞬间误判为机械速度已经为零。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   srobots::ChassisMoveRelativeStatus status;
   const auto code = robot.chassis().getMoveRelativeStatus(id, status);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   status = robot.get_chassis_move_relative_status(command_id)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _58-cancelmoverelative--cancel_chassis_move_relative--cancelchassismoverelative:

5.8 ``cancelMoveRelative()`` / ``cancel_chassis_move_relative()`` / ``cancelChassisMoveRelative()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 取消指定底盘相对移动。

============== ===============
参数           说明
============== ===============
``command_id`` 要取消的命令 ID
============== ===============

**返回值：** C++ 返回 ``ResultCode``\ ；Python 成功时返回 ``None``\ ，失败时抛出
``RobotError``\ 。

取消针对提交返回的同一个 ``command_id``。服务端接受取消请求后发布 ``Canceled``，并将
内部速度请求切换为受控停车；重复取消已经终态的任务会返回错误。若同一控制 owner 先发出
新的有效 WORLD-frame 速度命令，该速度命令会取得控制权并以 ``Canceled`` 终止活动的
相对位移任务，两个控制源不会并行驱动底盘。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = robot.chassis().cancelMoveRelative(id);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot.cancel_chassis_move_relative(command_id)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>


.. _59-torsomoveabsolute--move_torso_absolute:

5.9 ``Torso::moveAbsolute()`` / ``move_torso_absolute()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 以指定速度移动按直线位移定义的躯干到绝对位置。API 标识沿用现有
拼写 ``Torso``\ 。该接口使用 m 和 m/s，不作为 IX 五轴旋转关节的控制入口；
IX 的运动入口见 :doc:`../ix/index`。

========================= ==================
参数                      说明
========================= ==================
``target_m`` / ``target`` 目标位置，单位 m
``speed_mps`` / ``speed`` 目标速度，单位 m/s
========================= ==================

**返回值：** C++ 返回 ``ResultCode``\ ；Python 成功时返回 ``None``\ ，失败时抛出
``RobotError``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = robot.torso().moveAbsolute(0.10, 0.02);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot.move_torso_absolute(target=0.10, speed=0.02)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _510-torsoresetzeroposition:

5.10 ``Torso::resetZeroPosition()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 重置躯干零位。Python 使用
``robot.reset_zero_position(MotionUnit.TORSO)``\ 。

**参数：** 无。

**返回值：** C++ 返回 ``ResultCode``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = robot.torso().resetZeroPosition();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot.reset_zero_position(low_level.MotionUnit.Torso)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>


.. _511-torsogetstate--getposition:

5.11 ``Torso::getState()`` / ``getPosition()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 获取躯干完整状态或当前位置。Python 使用
``get_torso_state()`` / ``get_torso_position()``\ 。

**参数：** 无。

**返回值：** 分别返回 ``std::optional<TorsoState>`` 和
``std::optional<double>``\ ；没有可用状态时返回 ``std::nullopt``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto state = robot.torso().getState();
   const auto position = robot.torso().getPosition();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   state = robot.get_torso_state()
   position = robot.get_torso_position()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>


.. _512-运动单元便捷对象:

5.12 运动单元便捷对象
~~~~~~~~~~~~~~~~~~~~~

**摘要：** C++ 可通过 ``leftArm()``\ 、\ ``rightArm()``\ 、\ ``leftGripper()``\ 、
``rightGripper()``\ 、\ ``torso()`` 和 ``chassis()`` 取得借用型便捷对象。返回对象引用的
生命周期不超过所属 ``Robot``\ 。动态语言直接在 ``Robot`` 上提供对应方法，
无需管理借用型子对象。

.. list-table::
   :header-rows: 1

   * - API
     - 参数
     - 返回值
     - 最小示例
   * - ``Arm::switchMode(mode)``
     - 目标 ``Mode``
     - ``ResultCode``
     - ``robot.leftArm().switchMode(Mode::NRT_JOINT_POSITION);``
   * - ``Arm::movePosition(q, isRt)``
     - 7 维位置；是否使用 RT，默认 ``false``
     - ``ResultCode``
     - ``robot.leftArm().movePosition(q);``
   * - ``Arm::moveVelocity(dq, isRt)``
     - 7 维速度；是否使用 RT，默认 ``false``
     - ``ResultCode``
     - ``robot.leftArm().moveVelocity(dq);``
   * - ``Arm::moveTorque(tau)``
     - 7 维力矩（N·m） ；仅 RT
     - ``ResultCode``
     - ``robot.leftArm().moveTorque(tau);``
   * - ``Arm::getMode()``
     - 无
     - 当前 ``Mode``
     - ``auto mode = robot.leftArm().getMode();``
   * - ``Arm::getState(state)``
     - 状态输出参数
     - ``ResultCode``
     - ``auto code = robot.leftArm().getState(state);``
   * - ``Gripper::switchMode(mode)``
     - 目标 ``Mode``
     - ``ResultCode``
     - ``robot.leftGripper().switchMode(mode);``
   * - ``Gripper::getMode()``
     - 无
     - 当前 ``Mode``
     - ``auto mode = robot.leftGripper().getMode();``
   * - ``Gripper::open()``
     - 无
     - ``ResultCode``
     - ``robot.leftGripper().open();``
   * - ``Gripper::close()``
     - 无
     - ``ResultCode``
     - ``robot.leftGripper().close();``
   * - ``Gripper::movePosition(q)``
     - 夹爪位置数组
     - ``ResultCode``
     - ``robot.leftGripper().movePosition(q);``
   * - ``Torso::switchMode(mode)``
     - 目标 ``Mode``
     - ``ResultCode``
     - ``robot.torso().switchMode(mode);``
   * - ``Torso::getMode()``
     - 无
     - 当前 ``Mode``
     - ``auto mode = robot.torso().getMode();``
   * - ``Torso::movePosition(q)``
     - 躯干位置数组
     - ``ResultCode``
     - ``robot.torso().movePosition(q);``
   * - ``Chassis::switchMode(mode)``
     - 目标 ``Mode``
     - ``ResultCode``
     - ``robot.chassis().switchMode(mode);``
   * - ``Chassis::getMode()``
     - 无
     - 当前 ``Mode``
     - ``auto mode = robot.chassis().getMode();``


便捷对象只是第 4、5 节低层能力的类型化入口，不建立独立连接。该类型化子对象
只适用于 C++；Python 使用本节 tab 中对应的 ``Robot`` 方法。

.. raw:: html

   <details>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   auto &arm = robot.leftArm();
   const auto mode = arm.getMode();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   mode = robot.get_mode(low_level.MotionUnit.LeftArm)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _513-handcommand--gethandcapability:

5.13 ``handCommand()`` / ``getHandCapability()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

按关节名、时长控制与图形编辑器见 :doc:`../sdk/hand_poses`。

**摘要：** 控制多自由度灵巧手，并查询关节数量、关节范围、支持的动作和后端名称。
Python 方法名为 ``hand_command()`` 和 ``get_hand_capability()``\ 。

================== ==========================================================
参数               说明
================== ==========================================================
``unit``           左手或右手对应的运动单元
``action``         ``OPEN``\ 、\ ``CLOSE``\ 、\ ``HOLD``\ 、\ ``POSE`` 或
                   ``SET_JOINTS``
``targets``        ``SET_JOINTS`` 使用的关节索引与目标位置列表
``pose_name``      ``POSE`` 使用的预设姿态名称
================== ==========================================================


.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto capability = robot.getHandCapability(
       srobots::MotionUnit::LeftHandGripper);
   const auto code = robot.handCommand(
       srobots::MotionUnit::LeftHandGripper,
       srobots::HandAction::Open);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   capability = robot.get_hand_capability(
       low_level.MotionUnit.LeftHandGripper)
   robot.hand_command(
       low_level.MotionUnit.LeftHandGripper,
       low_level.HandAction.Open)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

6. 运动学模型
-------------

Python 也公开运动学模型。Python 使用 snake_case 方法，传入 ``ArmState`` 或 ``RobotState``
快照，矩阵仍按列优先返回。

.. _61-getmodel:

6.1 ``getModel()``
~~~~~~~~~~~~~~~~~~

**摘要：** 创建绑定到指定机械臂的运动学模型。Python 使用
``robot.get_model(arm)``\ 。

======= ===========================
参数    说明
======= ===========================
``arm`` ``LeftArm`` 或 ``RightArm``
======= ===========================

**返回值：** 返回可移动、不可复制的 ``Model``\ ；未连接或同步 URDF 不可用时抛出
异常。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   auto model = robot.getModel(srobots::MotionUnit::LeftArm);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   model = robot.get_model(low_level.MotionUnit.LeftArm)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _62-modelzerojacobian:

6.2 ``Model::zeroJacobian()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 计算指定坐标帧的 6×7 几何雅可比矩阵。

========= ===============================
参数      说明
========= ===============================
``frame`` ``kFlange`` 或 ``kEndEffector``
``state`` ``ArmState`` 或 ``RobotState``
========= ===============================

**返回值：** 按列优先排列的 42 元素数组。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto jacobian = model.zeroJacobian(srobots::Model::Frame::kEndEffector,
                                            state);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   jacobian = model.zero_jacobian(
       low_level.ModelFrame.EndEffector, state)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _63-modelpose:

6.3 ``Model::pose()``
~~~~~~~~~~~~~~~~~~~~~

**摘要：** 计算指定坐标帧在模型根坐标系中的齐次变换。

========= ===============================
参数      说明
========= ===============================
``frame`` ``kFlange`` 或 ``kEndEffector``
``state`` ``ArmState`` 或 ``RobotState``
========= ===============================

**返回值：** 按列优先排列的 16 元素数组。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto pose = model.pose(srobots::Model::Frame::kEndEffector, state);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   pose = model.pose(low_level.ModelFrame.EndEffector, state)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _64-modelsetee--robotsetee:

6.4 ``Model::setEE()`` / ``Robot::setEE()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 设置法兰到末端执行器的变换。\ ``Model::setEE()`` 更新本地模型；
``Robot::setEE()`` 将配置发送到控制器。

========== ===================================
参数       说明
========== ===================================
``arm``    仅 ``Robot::setEE()``\ ；目标机械臂
``F_T_EE`` 4×4 列优先齐次变换
========== ===================================

**返回值：** ``Model::setEE()`` 成功时无返回值，失败时抛出异常；
``Robot::setEE()`` 返回 ``ResultCode``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   model.setEE(transform);
   const auto code =
       robot.setEE(srobots::MotionUnit::LeftArm, transform);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   model.set_ee(transform)
   robot.set_ee(low_level.MotionUnit.LeftArm, transform)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _65-modelgetee--modelarm:

6.5 ``Model::getEE()`` / ``Model::arm()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 查询本地模型的末端变换或所属机械臂。

**参数：** 无。

**返回值：** ``getEE()`` 返回 16 元素变换数组；\ ``arm()`` 返回 ``MotionUnit``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto transform = model.getEE();
   const auto arm = model.arm();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   transform = model.get_ee()
   arm = model.arm()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _7-关节记录与回放:

7. 关节记录与回放
-----------------

记录文件可在回放时产生真实运动。必须验证文件来源、目标机器人配置、参与运动的
单元、传输方式、速度比例和物理工作空间。

Python 的失败会转换为带数值错误码的 ``RobotError``\ 。

C++ 和 Python 同时提供可取消的 ``AsyncTask`` 版本（Observer 不提供回放）。
任务支持有效性、状态、完成情况和进度查询，以及取消、等待和结果读取；具体名称和
超时单位以各语言接口为准。

.. _71-startjointrecording--start_joint_recording:

7.1 ``startJointRecording()`` / ``start_joint_recording()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 在控制器侧开始关节记录。

=========== =========================================================
参数        说明
=========== =========================================================
``options`` ``JointRecordingOptions``\ ，包含名称、覆盖策略和采样频率
=========== =========================================================

**返回值：** C++ 返回 ``ResultCode``\ ；Python 成功时返回 ``None``\ 。


.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = robot.startJointRecording(options);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot.start_joint_recording(options)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _72-stopjointrecording--stop_joint_recording:

7.2 ``stopJointRecording()`` / ``stop_joint_recording()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 停止当前记录并取得元数据。

录制由发起 ``start_joint_recording`` 的 Robot 或 Observer 会话持有。
服务端检测到该会话断开后会自动结束录制并释放占用；另一控制会话在动作全部
完成后断开，不会停止 Observer 发起的录制。若断线中断了动作或未完成的 RPC，
文件仍会关闭，但结束标记保留不完整原因，不能作为完整动作记录回放。

Python 的 ``stop_joint_recording_async()`` 和 ``list_joint_records_async()``
任务在 ``wait()`` / ``result()`` 失败时抛出 ``RobotError``，包含 ``code`` 和
``operation``。启用 SDK 控制台日志可查看服务端的具体拒绝原因。

============ ====================
参数         说明
============ ====================
``metadata`` 仅 C++；可选输出参数
============ ====================

**返回值：** C++ 返回 ``ResultCode`` 并可写入元数据；Python 返回元数据。


.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   srobots::JointRecordMetadata metadata;
   const auto code = robot.stopJointRecording(&metadata);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   metadata = robot.stop_joint_recording()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _73-listjointrecords--list_joint_records:

7.3 ``listJointRecords()`` / ``list_joint_records()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 列出控制器上的全部关节记录。

========= ===================================
参数      说明
========= ===================================
``error`` 仅 C++ 可选重载；接收列表查询错误码
========= ===================================

**返回值：** ``JointRecordMetadata`` 列表。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto records = robot.listJointRecords();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   records = robot.list_joint_records()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _74-deletejointrecord--delete_joint_record:

7.4 ``deleteJointRecord()`` / ``delete_joint_record()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 删除控制器上的指定记录。

======== ========
参数     说明
======== ========
``name`` 记录名称
======== ========

**返回值：** C++ 返回 ``ResultCode``\ ；Python 成功时返回 ``None``\ 。


.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = robot.deleteJointRecord("calibration-run");

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot.delete_joint_record("calibration-run")

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _75-downloadjointrecord--download_joint_record:

7.5 ``downloadJointRecord()`` / ``download_joint_record()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 将控制器上的记录下载到本地文件。

============== ==========================================
参数           说明
============== ==========================================
``name``       控制器记录名称
``local_path`` 本地目标路径；应用程序应限制允许的目标目录
============== ==========================================

**返回值：** C++ 返回 ``ResultCode``\ ；Python 成功时返回 ``None``\ 。


.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = robot.downloadJointRecord("calibration-run", "/tmp/run.mcap");

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot.download_joint_record("calibration-run", "/tmp/run.mcap")

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _76-replayjointrecord--replay_joint_record:

.. _76-replaymotionrecord--replay_motion_record:

7.6 ``replayMotionRecord()`` / ``replay_motion_record()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 从本地记录回放关节、末端位姿、混合命令或语义运动；该操作可能立即产生运动。

``replayMotionRecord`` / ``replay_motion_record`` 是统一回放入口；同步和
``Async`` / ``_async`` 版本使用相同规则。C++ 和 Python 的高层
NRT Robot 也提供对应转发方法。``MotionReplayOptions``、``MotionReplaySource``、
``MotionReplayTarget``、``MotionReplayTransport`` 是推荐名称；原 ``JointReplay*``
名称作为兼容别名保留，不改变选项布局、枚举值、默认值或 NRT/RT 执行语义。

旧 joint 入口的迁移
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

``replayJointRecord`` / ``replay_joint_record`` 及其异步版本保留为关节回放入口，
校验通过后转发到统一 motion 实现。以下行为有意收紧，旧调用不会自动改成位姿回放：

* 显式 ``target=EePose`` 返回 ``NotSupported``。
* 对用户命令录制，无论 ``target=Auto`` 还是 ``JointQ``，选中的机械臂包含位姿
  命令时，均在切换模式、恢复起点或发送运动之前拒绝整次回放；不会过滤掉位姿
  命令后继续执行其余关节命令。未选中的机械臂不参与该检查。
* ``HighLevelSemantic`` 和 ``RpcSemantic`` 来源统一使用 motion 入口；joint
  入口返回 ``NotSupported``，即使这份语义录制恰好只包含关节运动。
* 状态录制中的 TCP 位姿是测量值，关节回放读取 q，不因同时存在位姿测量而拒绝。
  joint 入口对此来源的 ``Auto`` 按 ``JointQ`` 处理。

已有 EePose、混合或语义回放代码应将函数调用迁移到 motion 名称，选项可以原样
传入。例如 ``robot.replayJointRecord(path, options)`` 改为
``robot.replayMotionRecord(path, options)``；Python 对应改为
``robot.replay_motion_record(path, options)``。仅回放关节的调用可以保留旧入口。
录制、列表、下载、删除函数名与文件格式保持不变。

输入格式和机型配置
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

状态来源兼容两种输入格式：原有包含 ``joint_record/robot_state`` 的单个
MCAP，以及 robot-state-recorder 生成的目录。目录必须包含
``manifest.pb.json`` 和 ``topics/``；SDK 自动读取 ``/robot_state/raw`` 中的
左右臂及配置的躯干、头部状态，并读取左右灵巧手 NRT topic。灵巧手命令使用
``ring_timestamp_ns`` 与状态时间轴对齐，发送时重新生成会话和命令 ID。
目录状态中的单轴夹爪反馈从 ``left_gripper.gripper.q`` 和
``right_gripper.gripper.q`` 提取，按状态时间轴插值，并用于回到起始位置和
夹爪回放。每侧夹爪有反馈时回放，没有反馈时自动跳过；已有反馈必须是单轴
有限数值。显式关闭某侧夹爪回放仍然生效。灵巧手数据
不会被当作单轴夹爪反馈。目录的 ``Auto`` 目标使用关节位置回放。
目录模式不回放底盘，选择 ``replay_chassis`` 会返回不支持。

目录中的状态消息兼容旧躯干字段名 ``torsor``。SDK 优先使用文件描述中的
``torso``，该字段不存在时才读取 ``torsor``；两种名称采用相同的数据校验、
起始位置恢复和轨迹生成逻辑。

目录回放使用连接握手提供的实际轴数和躯干位置单位，必须先连接机器人。
I7 的躯干为 1 轴，位置单位为 m，不回放头部；IX 的躯干为 5 轴、头部为
2 轴，位置单位为 rad。读取、插值、回到起始位置和 NRT/RT 发送均使用这一配置，
不进行单位换算。躯干和头部数组可以是实际长度，也可以是固定容量长度
（分别为 5 和 2）；只读取有效前缀，未使用的尾部及未配置模块的数据均忽略，
不要求占位值为零。有效轴数据长度不符、包含非有限数值，或已配置模块的数据
在录制过程中出现或消失时，回放准备返回错误。

历史目录缺少来源轴数和单位时，必须由调用方保证录制与回放使用同机型、相同
关节配置。SDK 按当前连接机器人的配置解释文件，无法根据容量数组自动识别
误用的其他机型录制，也不支持跨机型轨迹转换。文件解析和轨迹预生成在回放
准备阶段进行；逐帧命令封装使用固定容量数组，不动态分配内存。

统一 RPC 语义回放
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

新 server 会在同一 MCAP 内额外写入 ``motion_record/events``。选择
``MotionReplaySource::RpcSemantic``（Python ``MotionReplaySource.RpcSemantic``）可回放混合的 high-level NRT 与
low-level RPC 命令，不依赖 server 与 supervisor 之间的 Unix socket 数据包。
旧的采样回放来源保持原行为，不会自动切换。

IX 专用整身运动不属于 i7 回放内容；不同型号的记录不可直接混用。

录制应在建立运动占用之前开始：先连接、使能、配置，再开始录制，然后执行
``switch_mode`` 或高层提交。录制开始前已存在的 motion ID 不会被猜测重建；
录制必须包含其创建命令。高层运动结束后再停止录制。

支持高层 submit / append / replace / finish / stop、模式和运动生命周期、
NRT 关节/笛卡尔命令、夹爪/灵巧手、躯干、底盘速度和相对移动。
不包含用户 UDP RT 流、导航、标定、回零或恢复操作。录制中出现不支持的
状态修改、控制权丢失、失败 RPC（可能已执行部分批次）或队列溢出时，
记录不作为可回放的完整程序。

第一版仅支持 ``speed_scale=1.0`` 和 NRT 传输。命令按单调时钟的原时间轴
发送，允许 20 ms 的发送调度误差；不会为等待前一动作而推迟后续命令。
高层终态在命令发送结束后校验，最多等待 5 秒。冲突、超时或取消会执行
停止清理并断开控制连接，调用方需重新连接后再操作。

默认先用 ``move_to_start_interp_sec`` 插值回录制起点，并等待反馈到位。
双臂、夹爪、躯干和灵巧手恢复关节位置；底盘不会恢复世界坐标位置。
回放使用全日志，不使用旧采样来源的单部件筛选、重采样和目标转换选项。
回放结束后继续发送 low-level 命令前，请重新 ``switch_mode`` 同步 SDK 的占用缓存。
运动配置、工具、负载和机器人型号须与录制时一致；文件不能替代现场安全检查。

============== ============================================
参数           说明
============== ============================================
``local_path`` 本地记录文件
``options``    ``MotionReplayOptions``\ ；默认使用类型默认值
============== ============================================

**返回值：** C++ 返回 ``ResultCode``\ ；Python 成功时返回 ``None``\ 。


.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = robot.replayMotionRecord("/tmp/run.mcap", options);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   robot.replay_motion_record("/tmp/run.mcap", options)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _8-observerclient:

8. ``ObserverClient``
---------------------

``ObserverClient`` 使用独立连接读取状态和管理记录，不发送常规运动命令。记录管理
操作与第 7 节相同；
Python 将原始包公开为 ``bytes``\ ；
两种语言都提供原始包订阅。Server 关闭 Observer TCP 连接时，客户端立即进入断线
状态；TCP 仍连接但连续 1 秒没有收到有效 UDP 状态包时也按网络断线处理。超时判断使用
单调时钟，不受系统时间调整影响；阻塞状态读取会被唤醒并报告 ``NETWORK_ERROR``。

.. _81-observerclient:

8.1 ``ObserverClient(...)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 创建只读观察客户端；构造过程不建立连接。

====================== ==========
参数                   说明
====================== ==========
``server_ip`` / ``ip`` 控制器地址
====================== ==========

**返回值：** 新客户端；创建失败时抛出异常。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   srobots::ObserverClient observer("192.168.6.1");

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   observer = low_level.ObserverClient("192.168.6.1")

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _82-connect:

8.2 ``connect()``
~~~~~~~~~~~~~~~~~

**摘要：** 连接 Observer TCP 服务和状态 UDP 通道。

======================== ===================================================
参数                     说明
======================== ===================================================
``observer_tcp_port``    控制器 Observer 端口，默认 ``9530``
``local_state_udp_port`` 本地 UDP 端口；\ ``0`` 表示自动选择
``connect_timeout_ms``   Python TCP 建连超时，默认 ``5000``，必须大于 ``0``
======================== ===================================================

**返回值：** C++ 返回 ``ResultCode``\ ；Python 成功时返回 ``None``\ 。


.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   srobots::ObserverConnectOptions options;
   options.connect_timeout = std::chrono::milliseconds(5000);
   const auto code = observer.connect(options);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   observer.connect(
       observer_tcp_port=9530,
       local_state_udp_port=0,
       connect_timeout_ms=5000,
   )

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _83-close--disconnect:

8.3 ``close()`` / ``disconnect()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 关闭 Observer 连接；Python 的 ``disconnect()`` 是
``close()`` 的别名。

**参数：** 无。

**返回值：** C++ 返回 ``ResultCode``\ ；Python 成功时返回 ``None``\ ，失败时抛出
``RobotError``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = observer.close();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   observer.close()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _84-connected--is_connected:

8.4 ``connected()`` / ``is_connected()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 查询 Observer 是否连接。

**参数：** 无。

**返回值：** C++ 返回 ``ResultCode`` 并通过 ``out_connected`` 写入布尔值；Python
返回布尔值，失败时抛出 ``RobotError``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   bool ready = false;
   const auto code = observer.connected(ready);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   ready = observer.is_connected()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _85-latest:

8.5 ``latest()``
~~~~~~~~~~~~~~~~

**摘要：** 获取不超过指定年龄的最新原始实时数据包。Python 的
``latest_packet()`` 返回 ``bytes`` 或 ``None``\ 。

================== ====================================
参数               说明
================== ====================================
``out``            接收 ``net::RtPacket``
``max_age``        可接受的最大包龄
``out_has_sample`` 是否写入了满足包龄要求的新数据
``blocking``       无合格数据时是否等待，默认 ``false``
================== ====================================

**返回值：** ``ResultCode``\ 。\ ``OK`` 且 ``out_has_sample == false`` 表示没有符合条件的
新数据，不是错误。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   net::RtPacket packet;
   bool has_sample = false;
   const auto code = observer.latest(
       packet, std::chrono::milliseconds(100), has_sample, false);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   packet = observer.latest_packet(max_age_ms=100)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _86-getlateststate--get_latest_state:

8.6 ``getLatestState()`` / ``get_latest_state()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 获取最新解码状态。

================== ===========================
参数               说明
================== ===========================
``out_state``      仅 C++；接收状态
``blocking``       是否等待状态，默认 ``true``
================== ===========================

**返回值：** C++ 返回是否写入新状态的 ``bool``，读取错误时抛出 ``RobotError``\ ；
Python 返回 ``(has_sample, state)``\ 。


.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   srobots::RobotState state;
   const bool has_sample = observer.getLatestState(state, true);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   has_sample, state = observer.get_latest_state(blocking=True)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _87-setcallback--clearcallback:

8.7 ``setCallback()`` / ``clearCallback()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** C++ 替换或清除原始数据包回调。Python 使用
``subscribe_packet()`` / ``unsubscribe_packet()``\ 。

====== ==============================
参数   说明
====== ==============================
``cb`` ``setCallback()`` 的数据包回调
====== ==============================

**返回值：** ``ResultCode``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto set_code =
       observer.setCallback([](const net::RtPacket &packet) { /* inspect */ });
   const auto clear_code = observer.clearCallback();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   observer.subscribe_packet(on_packet)
   observer.unsubscribe_packet()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _88-latest_state:

8.8 ``latest_state()``
~~~~~~~~~~~~~~~~~~~~~~

**摘要：** Python 获取最新解码状态的可空便捷接口。C++ 使用
``getLatestState()``\ 。

============ ============================
参数         说明
============ ============================
``blocking`` 是否等待状态，默认 ``false``
============ ============================

**返回值：** 有可用状态时返回 ``RobotState``\ ，否则返回 ``None``\ 。

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   state = observer.latest_state(blocking=False)
   if state is not None:
       left_q = list(state.left.q)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   srobots::RobotState state;
   const bool has_sample = observer.getLatestState(state, false);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _89-subscribestate--unsubscribestate:

8.9 ``subscribeState()`` / ``unsubscribeState()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** C++ 设置原始数据包回调并订阅，或取消订阅并清除回调。回调在接收
线程执行。Python 的原生回调在 Observer 接收线程触发。

====== =======================================
参数   说明
====== =======================================
``cb`` ``subscribeState()`` 的轻量、非阻塞回调
====== =======================================

**返回值：** ``ResultCode``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto subscribe_code =
       observer.subscribeState([](const net::RtPacket &packet) { /* enqueue */ });
   const auto unsubscribe_code = observer.unsubscribeState();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   observer.subscribe_packet(on_packet)
   observer.unsubscribe_packet()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _9-scheduler:

9. ``Scheduler``
----------------

两种语言均提供 ``Scheduler``\ 。调度器回调接收最新 ``RobotState`` 并返回
``MotionResult``\ 。Python 使用原生调度器。

.. _91-scheduler:

9.1 ``Scheduler(...)``
~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 为已有 ``Robot`` 创建周期任务调度器；构造会阻塞到初始化完成。

========= ========================================
参数      说明
========= ========================================
``robot`` 生命周期必须覆盖调度器的已连接 ``Robot``
========= ========================================

**返回值：** 新调度器；初始化失败时抛出异常。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   srobots::sdk::Scheduler scheduler(robot);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   scheduler = low_level.Scheduler(robot)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _92-addtask:

9.2 ``AddTask()``
~~~~~~~~~~~~~~~~~

**摘要：** 在启动前添加一项周期任务。

============= ==================================================
参数          说明
============= ==================================================
``callback``  接收 ``RobotState`` 并返回 ``MotionResult`` 的回调
``task_name`` 唯一任务名
============= ==================================================

**返回值：** ``ResultCode``\ 。空回调、重名任务或调度器已经启动时返回对应错误码。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = scheduler.AddTask([](const srobots::RobotState &) {
     return srobots::MotionResult::InProgress;
   }, "state-task");

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   scheduler.add_task(
       lambda state: low_level.MotionResult.InProgress,
       "state-task")

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _93-start:

9.3 ``Start()``
~~~~~~~~~~~~~~~

**摘要：** 启动所有已添加任务，并阻塞到任务线程启动完成。

**参数：** 无。

**返回值：** ``ResultCode``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = scheduler.Start();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   scheduler.start()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _94-stop:

9.4 ``Stop()``
~~~~~~~~~~~~~~

**摘要：** 请求所有任务停止。

**参数：** 无。

**返回值：** ``ResultCode``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = scheduler.Stop();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   scheduler.stop()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _95-join:

9.5 ``Join()``
~~~~~~~~~~~~~~

**摘要：** 等待全部任务线程退出并释放运行资源；不得从任务线程内部调用。

**参数：** 无。

**返回值：** ``ResultCode``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const auto code = scheduler.Join();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   scheduler.join()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _96-num_tasks:

9.6 ``num_tasks()``
~~~~~~~~~~~~~~~~~~~

**摘要：** 查询已添加任务数。

**参数：** 无。

**返回值：** ``size_t`` 任务数。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   const std::size_t count = scheduler.num_tasks();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>


.. _15-navclient:

15. ``NavClient``
-----------------

``NavClient`` 是独立于 ``Robot`` 的导航服务客户端，覆盖建图、定位、导航与任务。
C++ 包含 ``<nav_client.h>`` 并使用 ``srobots::NavClient``\ ；Python 使用
``from srobots import nav`` 和 ``nav.NavClient``\ ；构造对象不会建立网络连接。

C++ 方法返回 ``ResultCode``\ ，调用方必须检查结果；Python 方法失败时抛出
``RuntimeError``\ ；状态查询不是订阅，应用应限制轮询频率。建图与定位会启动或停止控制器
侧进程，调用前应确认现场安全，并为停止操作和状态收敛设置超时。

导航服务最多允许 10 个客户端同时连接。所有会话都可查询状态，但控制命令使用单一
owner：首个被接受的控制命令所属 ``app_name`` 获得控制权，其他应用的控制命令返回
``BUSY`` 。owner 连接中断且任务仍在运行时，相同 ``app_name`` 重连可恢复控制。

TCP 建连和单次 RPC 的客户端超时均为 5 秒。传输超时后当前连接会失效，调用方必须
重新 ``connect`` 。C++ 状态接口即使返回 ``BUSY`` 、 ``TIMEOUT`` 或 ``FAILED`` ，
也会先填写完整状态结构；Python 直接返回该快照。调用方应检查
``phase/state/message`` 诊断字段。

.. _151-navclient-lifecycle:

15.1 构造、连接与关闭
~~~~~~~~~~~~~~~~~~~~~

================== ==============================================
接口               说明
================== ==============================================
``NavClient(ip)``  创建客户端；默认 Python 地址为 ``127.0.0.1``
``connect()``      连接导航服务；默认端口 9532，建连超时 5 秒
``connected()``    C++ 通过输出参数返回连接状态
``is_connected()`` Python 返回 ``bool``
``close()``        断开连接；Python 别名为 ``disconnect()``
================== ==============================================

``connect`` 的 ``app_name`` 用于服务端识别客户端，默认值为 ``simplesdk``\ 。
对象析构会释放连接和内部资源。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   #include <nav_client.h>

   srobots::NavClient client("192.168.6.1");
   auto code = client.connect(9532, "nav-app");
   bool connected = false;
   if (code == srobots::ResultCode::OK) {
     code = client.connected(connected);
   }

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   from srobots import nav

   client = nav.NavClient("192.168.6.1")
   client.connect(port=9532, app_name="nav-app")
   connected = client.is_connected()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _152-navclient-mapping:

15.2 建图
~~~~~~~~~

======================== ===================================================
接口                     说明
======================== ===================================================
``startMapping(name)``   C++ 启动建图
``start_mapping(name)``  Python 启动建图
``getMappingStatus()``   C++ 将状态写入 ``sr_nav_mapping_status``
``get_mapping_status()`` Python 返回 ``MappingStatus``
``stopMapping()``        C++ 请求停止并保存地图
``stop_mapping()``       Python 请求停止并保存地图
======================== ===================================================

``name`` 必须为非空地图名。状态的核心字段为 ``phase``\ 、\ ``map_name``\ 、
``elapsed_sec``\ 、\ ``map_path``\ 、\ ``message`` 和
``localization_ready``\ 。``missing_files`` 与
``map_validation_message`` 用于说明地图为何不能用于定位。

``phase`` 的取值为 ``IDLE``\ 、\ ``STARTING``\ 、\ ``RUNNING``\ 、
``EXITED``\ 、\ ``FAILED``\ 、\ ``STOPPING`` 和 ``STOPPED``\ 。停止调用返回
仅表示请求已提交；应继续查询，直到 ``STOPPED`` 或 ``FAILED``\ 。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   sr_nav_mapping_status status{};
   auto code = client.startMapping("warehouse");
   if (code == srobots::ResultCode::OK) {
     code = client.getMappingStatus(status);
   }

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   client.start_mapping("warehouse")
   status = client.get_mapping_status()
   if status.phase is nav.NavMappingPhase.RUNNING:
       client.stop_mapping()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _153-navclient-localization:

15.3 定位
~~~~~~~~~

=============================== ==============================================
接口                            说明
=============================== ==============================================
``startLocalization(name)``     C++ 使用指定地图启动定位
``start_localization(name)``    Python 使用指定地图启动定位
``getLocalizationState()``      C++ 写入 ``sr_nav_localization_status``
``get_localization_state()``    Python 返回 ``LocalizationStatus``
``getLocalizationPose()``       C++ 写入 ``sr_nav_localization_pose``
``get_localization_pose()``     Python 返回 ``LocalizationPose``
``stopLocalization()``          C++ 请求停止定位
``stop_localization()``         Python 请求停止定位
=============================== ==============================================

定位状态为 ``UNKNOWN``\ 、\ ``STOPPED``\ 、\ ``STARTING``\ 、
``INITIALIZING``\ 、\ ``LOCALIZED``\ 、\ ``LOST``\ 、\ ``ERROR`` 或
``STOPPING``\ 。定位位姿包含 ``x``\ 、\ ``y``\ 、\ ``z``\ 、欧拉角、
``timestamp_ns``\ 、\ ``frame_id``\ 、\ ``valid``\ 、\ ``stale`` 和
``age_ms``\ 。只有 ``valid`` 为真且 ``stale`` 为假时，应用才应采信该位姿。

.. raw:: html

   <details open>
   <summary><strong>C++</strong></summary>

.. code:: cpp

   auto code = client.startLocalization("warehouse");
   sr_nav_localization_status state{};
   sr_nav_localization_pose pose{};
   if (code == srobots::ResultCode::OK) {
     code = client.getLocalizationState(state);
     code = client.getLocalizationPose(pose);
   }

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

   <details>
   <summary><strong>Python</strong></summary>

.. code:: python

   client.start_localization("warehouse")
   state = client.get_localization_state()
   pose = client.get_localization_pose()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>


.. _154-navclient-navigation:

15.4 导航与任务
~~~~~~~~~~~~~~~

导航流程为：``startNavigation`` 启动导航后台，轮询状态直到 ``READY``\ ，
再发送目标或任务。``stopNavigation`` 取消目标并停止导航进程；
``cancelNavigation`` 只取消当前任务，导航后台继续运行。坐标目标使用
``navigateTo``\ ，命名点位使用 ``navigateToPoint``\ 。

=================================== ==========================================
接口                                说明
=================================== ==========================================
``startNavigation()``               启动导航后台（不移动机器人）
``navigateTo(x, y, yaw)``           发送 map 坐标系坐标目标
``navigateToPoint(map, point)``     发送命名点位目标
``cancelNavigation(map)``           取消当前任务，保留导航后台
``stopNavigation()``                取消任务并停止导航后台
``recordNavPoint(map, point)``      把当前位置记录为命名点位
``deleteNavPoint(map, point)``      删除命名点位
``getNavPoints(map)``               列出地图中的命名点位
``getCurrentPoint(map)``            查询当前所属点位名
``track(map, mission, track)``      执行配置的轨迹（Drift-Track）
``catchTrolley(map)``               执行抓取小推车任务
``dropTrolley(map)``                执行放下小推车任务
``getNavigationStatus(status)``     C++ 写入完整状态结构
``get_navigation_status()``         Python 返回 ``NavigationStatus``
=================================== ==========================================

C++ 的状态结构为 ``sr_nav_navigation_status_v3``\ ，调用前设置
``struct_size = sizeof(status)`` 和 ``version = 3``\ 。核心字段包括
``state``\ 、\ ``raw_status``\ 、\ ``progress_percent``\ 、\ ``map_name``\ 、
``point_id``\ 、\ ``point_name``\ 、\ ``goal_id``\ 、\ ``error_code``\ 、
``error_msg``\ 、\ ``distance_remaining_m``\ 、\ ``navigation_time_sec``\ 、
``estimated_time_remaining_sec``\ 、\ ``number_of_recoveries``\ 和
``current_pose``\ （含四元数，\ ``has_current_pose`` 表示是否有效）。
``nav_status`` 取值为 ``IDLE``\ 、\ ``RUNNING``\ 、\ ``DONE``\ 、\ ``ERROR``
和 ``CANCEL``\ 。``ERROR`` 时 ``error_msg`` 非空；失败代码形如
``fail_type_01``\ 至 ``fail_type_12``\ 。

``sr_nav_mission_request`` 提供通用任务入口，与上述便捷方法使用同一 RPC。
``mission_type`` 取值为 ``nav``\ 、\ ``track``\ 、\ ``stop``\ 、
``catch_trolly``\ 、\ ``drop_trolly``\ 、\ ``check_current_point``\ 、
``record_nav_point``\ 、\ ``delete_nav_point`` 或 ``check_nav_points``\ 。
查询类任务通过 ``sr_nav_mission_result.res`` 返回原始 JSON；点位列表使用
``getNavPoints`` / ``get_nav_points`` 获取结构化结果。

.. code:: cpp

   sr_nav_client_navigation_status_v3 status{};
   status.struct_size = sizeof(status);
   status.version = 3;
   client.getNavigationStatus(status);

   client.navigateToPoint("omni_strafe", "start");
   std::vector<srobots::NavPointInfo> points;
   client.getNavPoints("omni_strafe", points);

.. code:: python

   client.navigate_to_point("omni_strafe", "start")
   status = client.get_navigation_status()
   print(status.progress_percent, status.point_name, status.error_code)
   points = client.get_nav_points("omni_strafe")

MoveJ 防碰撞开关
================

C++ ``srobots::Robot`` 提供
``void setMoveJCollisionAvoidanceEnabled(bool enabled)`` 和
``bool getMoveJCollisionAvoidanceEnabled() const``；Python 对应
``set_movej_collision_avoidance_enabled(enabled: bool) -> None`` 和
``get_movej_collision_avoidance_enabled() -> bool``。

显式关闭屏蔽 Supervisor 的 MoveJ 轨迹碰撞检查及其绕行；显式开启同时启用两者，
覆盖 YAML 中这两个开关。尚未设置或会话结束时沿用原 YAML 策略；查询默认 true
表示运行开关未关闭，不证明 YAML 已开启检测。模型路径、净距和其他约束仍按配置执行。
WBC、Torso QP 约束及其反馈要求不受影响，也不增加 OnlineChunk、
WholeBodyJointMotion 或低层 RT/NRT 的保护覆盖。

设置需要当前控制权，并要求运动资源空闲；忙时报告 Busy，不等待运动完成。
状态仅属于当前控制会话，不写 YAML；会话结束后清除覆盖，运行开关恢复默认 true。
查询走实际 Supervisor 状态，支持 Observer 只读连接，不自动获取控制权。
两个方法均为阻塞 RPC，不应在实时回调内调用。

失败时 C++ 和 Python 抛出各自的 RobotError，不返回默认开关值。
当前尚未接入新协议的 Supervisor 报告 NotSupported，不能实际切换。
SET 超时不能证明设置未执行，应查询确认；库与头文件须配套升级。

.. code-block:: python

   # robot 是已连接的 srobots.low_level.Robot。
   # 只查询，不启动运动或修改保护状态。
   enabled = robot.get_movej_collision_avoidance_enabled()
