IX 接口参考
===========

公共单位、生命周期与错误处理见 :doc:`../sdk/api_common`。
完整目标与执行限制见 :doc:`../sdk/ix_interface_guide`。

.. _10-高层运动数据类型:

10. 高层运动数据类型
--------------------

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

   * - 类型
     - 摘要
     - 主要参数或字段
   * - ``JointWaypoint``
     - 关节位置或速度路点
     - ``target``、 ``target_velocity``、 ``reference_type``、持续时间、动态比例
   * - ``EePoseWaypoint``
     - 末端位姿路点
     - ``target_pose``、 ``target_speed_m_s``、 ``reference_type``、持续时间、动态比例
   * - ``EeVelocityWaypoint``
     - 末端速度路点
     - ``target_twist``、 ``reference_type``、持续时间、动态比例
   * - ``JointMotion``
     - 关节位置运动
     - ``waypoints``、 ``max_joint_speed_deg_s``
   * - ``JointVelocityMotion``
     - 关节速度运动
     - ``waypoints``、 ``max_joint_speed_deg_s``
   * - ``TorsoJointWaypoint`` / ``TorsoJointMotion``
     - IX 五轴躯干 MoveJ（C++、Python）
     - 五轴目标/目标速度、参考类型、动态比例和时间参数
   * - ``HeadJointWaypoint`` / ``HeadJointMotion``
     - IX 两轴头部 MoveJ（C++、Python）
     - 两轴目标/目标速度、参考类型、动态比例和时间参数
   * - ``EePoseMotion``
     - 末端位姿运动
     - ``waypoints``、 ``ik_options``、 ``path_policy``、速度限制
   * - ``DualArmEePoseMotion``
     - 双臂末端位姿运动
     - 左右两侧各一个 ``EePoseMotion``
   * - ``EeVelocityMotion``
     - 末端速度运动
     - ``waypoints``、 ``max_joint_speed_deg_s``
   * - ``WholeBodyJointWaypoint`` / ``WholeBodyJointMotion``
     - 头、躯干和双臂共 21 轴有限 MoveJ
     - 完整 2/5/7/7 目标，WholeBody scope，空 arms
   * - ``WholeBodyPoseTarget``
     - 完整全身目标帧
     - 头、双手、躯干、双脚位姿及时间戳/序号
   * - ``WholeBodyTargetMotion``
     - 全身目标运动
     - ``target``
   * - ``IkOptions``
     - 末端位姿 IK 选项
     - 迭代、容差、阻尼、步长、超时、近似解策略
   * - ``EePoseCircleOptions``
     - MoveC 圆弧选项
     - 输入几何、半径、方向、旋转方向、长短弧
   * - ``RobotControlConfig``
     - 默认控制配置
     - 机械臂范围、速度、平滑度、精度、速度比例、完成稳定时间
   * - ``CompletionCriteria``
     - 完成判定
     - 关节/末端容差、稳定时间、超时
   * - ``Result<T>``
     - C++ 高层提交和等待结果
     - ``ok()``、 ``value()``、 ``error()``、 ``message()``

构造示例：

.. raw:: html

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

.. code:: cpp

   srobots::hl::JointMotion motion;
   motion.waypoints.push_back({target_q});
   motion.max_joint_speed_deg_s = 30.0;

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

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

.. code:: python

   motion = high_level.JointMotion(
       [high_level.JointWaypoint(target_q)],
       max_joint_speed_deg_s=30.0,
   )

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

机械臂关节向量为 7 个元素，IX 躯干和头部关节向量分别为 5 和 2 个元素；末端
位姿为 7 个元素，笛卡尔速度为 6 个元素。
``MotionSpec`` 是八种运动类型的 C++ ``std::variant``\ ，其中
``TorsoJointMotion`` 和 ``HeadJointMotion`` 用于 IX 有限长度 MoveJ 或独立 OnlineChunk，
``DualArmEePoseMotion`` 用于同时提交左右末端位姿路点，
``WholeBodyTargetMotion`` 用于完整全身目标帧。


.. _11-高层-nrt-api:

11. 高层 NRT API
----------------

.. _111-nrtrobot:

11.1 ``nrt::Robot(...)``
~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 由控制器 IP 创建拥有连接的 IX 运动对象。构造不连接，
必须显式调用 ``connect()``。构造参数为 ``ip`` 和可选的 ``RobotOptions``。
生命周期、状态和外设操作共享同一 session 与控制授权。

**返回值：** 新高层对象。Python 调用失败抛出 ``high_level.RobotError``，
其 ``code`` 属性给出结果码。运动提交与等待使用后文的 Result / MotionHandle 契约。

.. raw:: html

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

.. code:: cpp

   srobots::hl::nrt::Robot hl_robot("192.168.6.1");
   hl_robot.connect();
   hl_robot.moveGripper(srobots::MotionUnit::LeftHandGripper, 0.02);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

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

.. code:: python

   hl_robot = high_level.nrt.Robot("192.168.6.1")
   hl_robot.connect()
   # 检查型号、故障、控制权、使能和目标后，再调用 move_async()。
   hl_robot.disconnect()

.. container:: sdk-example-reference

   参考示例：``examples/python/ix_high_level_movej.py``

.. raw:: html

   </details>

.. _112-set_default_control_config--default_control_config:

11.2 ``set_default_control_config()`` / ``default_control_config()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 设置或读取后续提交使用的默认控制配置。

========== ======================
参数       说明
========== ======================
``config`` ``RobotControlConfig``
========== ======================

**返回值：** 设置方法无返回值；读取方法返回当前配置。Python 读取入口是同名
只读属性 ``default_control_config``\ 。

.. raw:: html

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

.. code:: cpp

   hl_robot.set_default_control_config(config);
   const auto &current = hl_robot.default_control_config();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

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

.. code:: python

   hl_robot.set_default_control_config(config)
   current = hl_robot.default_control_config

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _113-move_async--moveasync:

11.3 ``move_async()`` / ``moveAsync()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 向控制器提交完整 NRT 运动，并立即返回句柄。

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

   * - 参数
     - 说明
   * - ``scope``
     - ``SingleArm`` 或 ``Group``
   * - ``arms``
     - ``ArmId`` 列表
   * - ``motion``
     - C++/Python 八种高层运动规格之一
   * - ``completion``
     - 可选完成条件；省略时由默认控制配置生成
   * - ``planning_mode``
     - 可选规划器；省略时为 ``Standard``

**返回值：** C++ 返回 ``Result<MotionHandle>``\ ，可通过 ``ok()``\ 、\ ``value()``\ 、
``error()`` 和 ``message()`` 检查结果；Python 成功时返回 ``MotionHandle``\ ，失败时
抛出带 ``code`` 和 ``message`` 属性的 ``high_level.RobotError``\ 。

.. raw:: html

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

.. code:: cpp

   auto result = hl_robot.move_async(
       srobots::hl::MotionScope::SingleArm,
       {srobots::ArmId::Left}, motion);
   if (!result.ok()) {
     // 处理 result.error() 和 result.message()。
   }
   auto handle = std::move(result).value();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

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

.. code:: python

   handle = hl_robot.move_async(high_level.MotionScope.SingleArm,
                                [high_level.ArmId.Left], motion)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _114-start_motion_streaming--startmotionstreaming:

11.4 ``start_motion_streaming()`` / ``startMotionStreaming()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 启动可追加或替换路点的流式 NRT 运动。

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

   * - 参数
     - 说明
   * - ``scope``
     - ``SingleArm`` 或 ``Group``
   * - ``arms``
     - ``ArmId`` 列表
   * - ``motion``
     - 初始运动规格
   * - ``completion``
     - 可选完成条件
   * - ``planning_mode``
     - 可选规划器；省略时为 ``Standard``

**返回值：** 与 ``move_async()`` 相同：C++ 返回 ``Result<MotionHandle>``\ ，Python
返回句柄或抛出 ``high_level.RobotError``\ 。

.. raw:: html

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

.. code:: cpp

   auto result = hl_robot.start_motion_streaming(
       srobots::hl::MotionScope::SingleArm,
       {srobots::ArmId::Left}, motion);
   if (!result.ok()) {
     // 处理提交错误。
   }
   auto handle = std::move(result).value();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

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

.. code:: python

   handle = hl_robot.start_motion_streaming(
       high_level.MotionScope.SingleArm, [high_level.ArmId.Left], motion)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

11.5 NRT 运动模式与调用对照
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

本文档说明文档/API 中常见的几种运动模式（MoveJ、movej_pose2、MoveL、SpeedJ、SpeedL、停止速度流）如何用当前 SDK 已有的 move_async 接口实现，以及涉及的全部参数。

不涉及任何封装层代码；应用侧自行组装 JointMotion / EePoseMotion 等结构体后调用 nrt.Robot.move_async()（C++ 为 srobots::hl::nrt::Robot::move_async()）。


11.5.1 统一调用入口
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


所有 NRT 点位/速度运动均通过：

.. code-block:: text

   move_async(scope, arms, motion [, completion]) → MotionHandle


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

   * - 参数
     - Python 类型
     - C++ 类型
     - 说明
   * - scope
     - MotionScope
     - sr_hl_motion_scope
     - SingleArm：单臂；Group：双臂协同（同一 motion 作用于 listed arms）
   * - arms
     - list[ArmId]
     - std::vector<sr_arm_id>
     - [ArmId.Left] / [ArmId.Right] / [Left, Right]
   * - motion
     - 见下文各模式
     - JointMotion 等
     - C++/Python 八选一；决定运动族
   * - completion
     - CompletionCriteria（可选）
     - sr_hl_completion_criteria（可选）
     - 何时判定 motion 完成；省略则用 SDK 默认

最小示例：

.. raw:: html

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

.. code-block:: python

   from srobots import high_level as hl

   nrt = hl.nrt.Robot("<机器人 IP>")
   nrt.connect()

   handle = nrt.move_async(hl.MotionScope.SingleArm, [hl.ArmId.Left], motion)
   handle.wait(timeout_sec=10.0)
   nrt.disconnect()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

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

.. code-block:: cpp

   #include "srobots/hl/nrt/robot.hpp"

   srobots::hl::nrt::Robot nrt("<机器人 IP>");
   nrt.connect();

   auto submitted = nrt.move_async(SR_HL_MOTION_SCOPE_SINGLE_ARM, {SR_ARM_LEFT}, motion);
   if (!submitted.ok()) {
       // 处理 submitted.error() 和 submitted.message()。
       return;
   }
   auto handle = submitted.value();
   auto completed = handle.wait(10.0);
   // 检查 completed；超时不等于运动已停止。
   nrt.disconnect();


.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

11.5.1.1 scope / arms 选取建议
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


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

   * - 场景
     - scope
     - arms
   * - 单臂关节/位姿/速度
     - SingleArm
     - [Left] 或 [Right]
   * - 双臂相同关节目标
     - Group
     - [Left, Right]
   * - 左右臂不同 EE 目标
     - 分别两次 SingleArm
     - 各 [Left] / [Right]

11.5.1.2 MotionHandle 常用方法
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


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

   * - 方法
     - 说明
   * - valid()
     - 提交是否成功
   * - motion_id()
     - 运动 ID
   * - wait(timeout_sec)
     - 阻塞等待完成
   * - status()
     - 当前 phase / message
   * - stop(policy)
     - 停止；速度流结束后常用 HoldPosition

11.5.2 模式对照总表
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


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

   * - 文档/API 名称
     - move_async 的 motion 类型
     - 关键区分字段
     - 典型用途
   * - MoveJ
     - JointMotion
     - family = JOINT
     - 关节空间点到点
   * - movej_pose2
     - EePoseMotion
     - path_policy = JointSmooth
     - 给定 EE 位姿，关节空间平滑到达（经 IK）
   * - MoveL
     - EePoseMotion
     - path_policy = EePoseSmooth
     - 给定 EE 位姿，笛卡尔直线（经 IK）
   * - SpeedJ
     - JointVelocityMotion
     - family = JOINT_VELOCITY
     - 关节速度流
   * - SpeedL
     - EeVelocityMotion
     - family = EE_VELOCITY
     - 末端 twist 速度流
   * - speed_stop
     - （无新 motion）
     - handle.stop(HoldPosition)
     - 停止速度流并保持
   * - 关节步进
     - JointMotion
     - reference_type = Relative，target = 关节增量
     - 在当前关节角基础上步进
   * - 位置步进
     - EePoseMotion
     - 应用层读当前 eepose，xyz 加增量后 Absolute 提交
     - EE 位置沿轴步进（经 IK）
   * - 姿态步进
     - EePoseMotion
     - 应用层读当前 eepose，更新四元数后 Absolute 提交
     - EE 姿态绕轴步进（经 IK）

MoveC（圆弧）：使用 ``EePoseMotion`` 并将 ``path_policy`` 设为
``EePoseSmoothCircle``\ ，再通过 ``circle_options`` 指定途经点/目标半径、方向、
旋转方向与长短弧。也可以用多个 ``EePoseWaypoint`` 拼近似圆弧，参见示例
``high_level_nrt_eepose_circle.py``\ 。


11.5.3 MoveJ — 关节空间运动
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


11.5.3.1 实现方式
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


组装 JointMotion，路点目标为 7 维关节角（rad）。

11.5.3.2 示例
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

.. raw:: html

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


.. code-block:: python

   waypoint = hl.JointWaypoint(
       target=[0.0, 0.1, 0.2, 0.0, -0.1, 0.0, 0.05],  # 7 关节角 rad
       reference_type=hl.ReferenceType.Absolute,
       minimum_time_sec=2.0,
       target_velocity=[0.0] * 7,
   )
   motion = hl.JointMotion([waypoint], max_joint_speed_deg_s=40.0)

   handle = nrt.move_async(hl.MotionScope.SingleArm, [hl.ArmId.Left], motion)
   # 可选：传入 completion
   # handle = nrt.move_async(scope, arms, motion, completion)

.. container:: sdk-example-reference

   参考示例：``examples/python/high_level_nrt_joint_motion.py``

.. raw:: html

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

.. code-block:: cpp

   srobots::hl::JointWaypoint wp;
   wp.target = {0.0, 0.1, 0.2, 0.0, -0.1, 0.0, 0.05};
   wp.minimum_time_sec = 2.0;
   wp.target_velocity = srobots::hl::JointVector{};

   srobots::hl::JointMotion motion;
   motion.waypoints.push_back(wp);
   motion.max_joint_speed_deg_s = 40.0;

   auto handle = nrt.move_async(SR_HL_MOTION_SCOPE_SINGLE_ARM, {SR_ARM_LEFT}, motion);

.. container:: sdk-example-reference

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

.. raw:: html

   </details>

11.5.3.3 参数
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


JointMotion（motion 级）

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

   * - 字段
     - 类型
     - 默认
     - 说明
   * - waypoints
     - JointWaypoint[]
     - 必填
     - 路点序列
   * - max_joint_speed_deg_s
     - float?
     - 未设
     - 整段运动关节角速度上限（deg/s）

JointWaypoint（路点级）

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

   * - 字段
     - 类型
     - 默认
     - 说明
   * - target
     - [7] float
     - —
     - 目标关节角（rad）；SpeedJ 时复用为 关节速度
   * - target_velocity
     - [7] float?
     - 未设
     - 路点处目标关节速度（rad/s）；MoveJ 末点建议 [0]*7
   * - reference_type
     - uint
     - 0
     - 0=绝对（相对零位/基座），1=相对当前
   * - minimum_time_sec
     - float
     - 0
     - 到达该路点的最短时间（s）
   * - max_total_duration_sec
     - float
     - 0
     - 该路点最长允许时间（s）；0 表示不限制
   * - hold_target_duration_sec
     - float
     - 0
     - 到达后在目标处保持时间（s）
   * - relative_dynamics_factor
     - 结构体
     - 全 1.0
     - 速度/加速度/jerk 相对缩放；见 §8

推荐 completion（MoveJ）

省略时使用 SDK 默认（Reached + Auto target）。一般无需修改。


11.5.4 movej_pose2 — EE 位姿 + 关节平滑
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


11.5.4.1 实现方式
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


组装 EePoseMotion，设置：

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

   * - C++
     - Python
   * - ``EePosePathPolicy::JointSmooth``
     - ``EePosePathPolicy.JointSmooth``

经 IK 将 EE 位姿转为关节轨迹，不保证笛卡尔直线。

11.5.4.2 示例
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

.. raw:: html

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


.. code-block:: python

   waypoint = hl.EePoseWaypoint(
       [0.4, 0.0, 0.3, 0.0, 0.0, 0.0, 1.0],  # x,y,z,qx,qy,qz,qw
       hl.ReferenceType.Absolute,
       minimum_time_sec=3.0,
       target_speed_m_s=0.12,
   )
   ik = hl.IkOptions()
   ik.max_iterations = 120
   ik.position_tolerance_m = 0.002
   ik.orientation_tolerance_rad = 0.02
   ik.timeout_sec = 0.05

   motion = hl.EePoseMotion(
       [waypoint],
       ik_options=ik,
       path_policy=hl.EePosePathPolicy.JointSmooth,
       default_target_speed_m_s=0.2,
       max_joint_speed_deg_s=25.0,
   )

   completion = hl.CompletionCriteria(target=hl.CompletionTarget.EePose)
   handle = nrt.move_async(hl.MotionScope.SingleArm, [hl.ArmId.Left], motion, completion)

.. container:: sdk-example-reference

   参考示例：``examples/python/high_level_nrt_eepose_motion.py``

.. raw:: html

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

.. code-block:: cpp

   srobots::hl::EePoseWaypoint wp;
   wp.target_pose = {0.4, 0.0, 0.3, 0.0, 0.0, 0.0, 1.0};
   wp.minimum_time_sec = 3.0;
   wp.target_speed_m_s = 0.12;

   srobots::hl::IkOptions ik;
   ik.max_iterations = 120;
   ik.position_tolerance_m = 0.002;

   srobots::hl::EePoseMotion motion;
   motion.waypoints.push_back(wp);
   motion.ik_options = ik;
   motion.path_policy = srobots::hl::EePosePathPolicy::JointSmooth;

   sr_hl_completion_criteria completion{};
   completion.target = SR_HL_COMPLETION_TARGET_EE_POSE;
   auto handle = nrt.move_async(SR_HL_MOTION_SCOPE_SINGLE_ARM, {SR_ARM_LEFT},
                                 motion, completion);


.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

11.5.4.3 参数
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


EePoseMotion（motion 级）

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

   * - 字段
     - 类型
     - 默认
     - 说明
   * - waypoints
     - EePoseWaypoint[]
     - 必填
     - EE 路点序列
   * - path_policy
     - EePosePathPolicy
     - JointSmooth
     - movej_pose2 用 JointSmooth
   * - ik_options
     - IkOptions
     - 见下表
     - 位姿 → 关节 IK 配置
   * - default_target_speed_m_s
     - float?
     - 未设
     - 路点未指定 target_speed_m_s 时的默认线速度
   * - max_joint_speed_deg_s
     - float?
     - 未设
     - 关节角速度上限（deg/s）
   * - circle_options
     - EePoseCircleOptions?
     - 未设
     - EePoseSmoothCircle 使用的 MoveC 几何参数

EePoseWaypoint（路点级）

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

   * - 字段
     - 类型
     - 默认
     - 说明
   * - target_pose
     - [7] float
     - —
     - [x,y,z,qx,qy,qz,qw]（m + 四元数）
   * - target_speed_m_s
     - float?
     - 未设
     - 该路点 EE 线速度（m/s）
   * - reference_type
     - uint
     - 0
     - 0 绝对 / 1 相对
   * - minimum_time_sec
     - float
     - 0
     - 最短时间（s）
   * - max_total_duration_sec
     - float
     - 0
     - 最长时间（s）
   * - hold_target_duration_sec
     - float
     - 0
     - 保持时间（s）
   * - relative_dynamics_factor
     - 结构体
     - 默认
     - 见 §8

IkOptions

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

   * - 字段
     - 默认
     - 说明
   * - max_iterations
     - 80
     - 最大迭代次数
   * - position_tolerance_m
     - 0.002
     - 位置收敛容差（m）
   * - orientation_tolerance_rad
     - 0.02
     - 姿态收敛容差（rad）
   * - damping
     - 1e-4
     - 阻尼，缓解奇异
   * - max_step_norm_rad
     - 0.2
     - 单步关节增量上限（rad）
   * - timeout_sec
     - 0.02
     - 单次 IK 超时（s）
   * - allow_approximate_solution
     - False
     - 是否接受近似解

推荐 completion（movej_pose2 / MoveL）

两种语言均设置 ``target = EePose``、位置容差 ``0.005 m``、姿态容差
``0.03 rad``、稳定时间 ``0 s`` 和超时 ``2 s``；字段分别使用各语言的
snake_case 或 camelCase 命名。


11.5.5 MoveL — EE 位姿 + 笛卡尔直线
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


11.5.5.1 实现方式
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


与 movej_pose2 相同结构（EePoseMotion），仅 path_policy 不同：

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

   * - C++
     - Python
   * - ``EePosePathPolicy::EePoseSmooth``
     - ``EePosePathPolicy.EePoseSmooth``

11.5.5.2 示例
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

.. raw:: html

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

.. code:: cpp

   motion.path_policy = srobots::hl::EePosePathPolicy::EePoseSmooth;
   auto result = nrt.move_async(
       srobots::hl::MotionScope::SingleArm,
       {srobots::ArmId::Left}, motion, completion);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

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

.. code:: python

   motion = hl.EePoseMotion(
       [waypoint], ik_options=ik,
       path_policy=hl.EePosePathPolicy.EePoseSmooth)
   handle = nrt.move_async(
       hl.MotionScope.SingleArm, [hl.ArmId.Left], motion, completion)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

其余字段与 11.5.4 完全相同。


11.5.5.3 movej_pose2 vs MoveL
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


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

   * -
     - movej_pose2
     - MoveL
   * - motion 类型
     - EePoseMotion
     - EePoseMotion
   * - path_policy
     - JointSmooth
     - EePoseSmooth
   * - 路径特点
     - 关节空间平滑，EE 路径不保证直线
     - 规划为 EE 笛卡尔直线（经 IK）
   * - 参数
     - 相同
     - 相同

11.5.6 SpeedJ — 关节速度流
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


11.5.6.1 实现方式
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


组装 JointVelocityMotion。注意：路点类型仍为 JointWaypoint，但 target 表示关节速度（rad/s），不是位置。

11.5.6.2 示例
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

.. raw:: html

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


.. code-block:: python

   waypoint = hl.JointWaypoint(
       [0.0, 0.03, 0.0, 0.0, 0.0, 0.0, 0.0],  # 关节速度 rad/s
       hl.ReferenceType.Absolute,
       hold_target_duration_sec=1e9,  # 长时间保持速度指令
   )
   motion = hl.JointVelocityMotion([waypoint])

   completion = hl.CompletionCriteria(
       mode=hl.CompletionMode.Commanded,
       timeout_sec=1e9,
   )
   handle = nrt.move_async(hl.MotionScope.SingleArm, [hl.ArmId.Left], motion, completion)

   # 运行一段时间后停止
   import time
   time.sleep(1.0)
   handle.stop(hl.HighLevelStopPolicy.HoldPosition)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

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

.. code-block:: cpp

   srobots::hl::JointWaypoint wp;
   wp.target = {0.0, 0.03, 0.0, 0.0, 0.0, 0.0, 0.0};  // rad/s
   wp.hold_target_duration_sec = 1.0e9;

   srobots::hl::JointVelocityMotion motion;
   motion.waypoints.push_back(wp);

   sr_hl_completion_criteria completion{};
   completion.mode = SR_HL_COMPLETION_COMMANDED;
   completion.timeout_sec = 1.0e9;

   auto handle = nrt.move_async(SR_HL_MOTION_SCOPE_SINGLE_ARM, {SR_ARM_LEFT},
                                 motion, completion);
   std::this_thread::sleep_for(std::chrono::seconds(1));
   handle.stop(SR_HL_STOP_HOLD_POSITION);


.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

11.5.6.3 参数
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


JointVelocityMotion（motion 级）

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

   * - 字段
     - 类型
     - 说明
   * - waypoints
     - JointWaypoint[]
     - 速度路点；target = 关节速度
   * - max_joint_speed_deg_s
     - float?
     - 关节角速度上限

JointWaypoint（速度模式下路点级）

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

   * - 字段
     - 说明
   * - target
     - 7 维关节速度（rad/s）
   * - hold_target_duration_sec
     - 该速度指令保持时长（s）；常用 1e9 表示持续流式
   * - 其余
     - 同 §3.4

推荐 completion（SpeedJ / SpeedL）

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

   * - 字段
     - 推荐值
     - 说明
   * - mode
     - Commanded
     - 指令轨迹发完/保持期满即完成，而非等反馈到位
   * - timeout_sec
     - 很大（如 1e9）
     - 避免速度流被默认 2s 超时打断

11.5.7 SpeedL — 末端 twist 速度流
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


11.5.7.1 实现方式
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


组装 EeVelocityMotion，路点为 EeVelocityWaypoint。

11.5.7.2 示例
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

.. raw:: html

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


.. code-block:: python

   twist = hl.EeVelocityWaypoint(
       [0.01, 0.0, 0.0, 0.0, 0.0, 0.0],  # vx,vy,vz, wx,wy,wz
       hold_target_duration_sec=1e9,
   )
   motion = hl.EeVelocityMotion([twist])

   completion = hl.CompletionCriteria(
       mode=hl.CompletionMode.Commanded,
       timeout_sec=1e9,
   )
   handle = nrt.move_async(hl.MotionScope.SingleArm, [hl.ArmId.Left], motion, completion)
   time.sleep(1.0)
   handle.stop(hl.HighLevelStopPolicy.HoldPosition)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

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

.. code-block:: cpp

   srobots::hl::EeVelocityWaypoint wp;
   wp.target_twist = {0.01, 0.0, 0.0, 0.0, 0.0, 0.0};
   wp.hold_target_duration_sec = 1.0e9;

   srobots::hl::EeVelocityMotion motion;
   motion.waypoints.push_back(wp);
   // completion 同 SpeedJ


.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

11.5.7.3 参数
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


EeVelocityMotion（motion 级）

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

   * - 字段
     - 说明
   * - waypoints
     - EeVelocityWaypoint[]
   * - max_joint_speed_deg_s
     - 可选关节速度上限

EeVelocityWaypoint（路点级）

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

   * - 字段
     - 类型
     - 说明
   * - target_twist
     - [6] float
     - [vx,vy,vz, wx,wy,wz]（m/s, rad/s）
   * - reference_type
     - uint
     - 0 绝对 / 1 相对
   * - hold_target_duration_sec
     - float
     - 速度保持时间（s）
   * - minimum_time_sec
     - float
     - 最短时间
   * - max_total_duration_sec
     - float
     - 最长时间
   * - relative_dynamics_factor
     - 结构体
     - 见 §8

11.5.8 公共子结构：RelativeDynamicsFactor
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


用于路点上的 relative_dynamics_factor：

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

   * - 字段
     - 默认
     - 说明
   * - velocity
     - 1.0
     - 速度缩放（0~1）
   * - acceleration
     - 1.0
     - 加速度缩放
   * - jerk
     - 1.0
     - jerk 缩放
   * - max_dynamics
     - False
     - True 时尽量用最大动力学能力

11.5.9 CompletionCriteria 全字段
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


move_async 第 4 参数，控制 何时认为 motion 结束。

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

   * - 字段
     - 默认
     - 说明
   * - mode
     - Reached
     - Reached：反馈进入容差；Commanded：指令轨迹完成
   * - target
     - Auto
     - Auto / Joint / EePose / Both：按关节或 EE 判定
   * - position_tolerance_rad
     - 0.01
     - 关节位置容差（rad）
   * - velocity_tolerance_rad_s
     - 0.03
     - 关节速度容差（rad/s）
   * - ee_position_tolerance_m
     - 0.005
     - EE 位置容差（m）
   * - ee_orientation_tolerance_rad
     - 0.03
     - EE 姿态容差（rad）
   * - settle_time_sec
     - 0.0
     - 进入容差后需稳定的时间
   * - timeout_sec
     - 2.0
     - 等待完成的总超时（s）

各模式推荐：

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

   * - 模式
     - mode
     - target
   * - MoveJ
     - Reached（默认）
     - Auto
   * - movej_pose2 / MoveL
     - Reached
     - EePose
   * - SpeedJ / SpeedL
     - Commanded
     - Auto

11.5.10 speed_stop — 停止速度流
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


不是新的 move_async 调用，而是对已返回的 MotionHandle 调用：

.. raw:: html

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

.. code:: cpp

   handle.stop(SR_HL_STOP_HOLD_POSITION);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

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

.. code:: python

   handle.stop(hl.HighLevelStopPolicy.HoldPosition)


.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

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

   * - policy
     - 说明
   * - HoldPosition
     - 停止速度指令并保持当前位置
   * - Auto
     - 由控制器自动决定停止行为

11.5.11 数据流示意
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


.. code-block:: text

   应用层
     ├─ 组装 JointMotion / EePoseMotion / JointVelocityMotion / EeVelocityMotion
     └─ nrt.Robot.move_async(scope, arms, motion [, completion])
           └─ MotionSpecView → C API → RPC → Supervisor
                 └─ MotionHandle（wait / stop / append / replace）


11.5.12 相关源码与示例索引
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


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

   * - 内容
     - 路径
   * - Motion 结构体定义
     - include/cpp/high_level/srobots/hl/common/motion_spec.hpp
   * - NRT Robot / 默认 completion
     - include/cpp/high_level/srobots/hl/nrt/robot.hpp
   * - MotionHandle（stop/wait）
     - include/cpp/high_level/srobots/hl/nrt/motion_handle.hpp
   * - Python 绑定
     - src/api_impl/python/robot_hl_py.cpp

示例程序：

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

   * - 场景
     - C++
     - Python
   * - MoveJ 示例
     - examples/cpp/high_level_nrt_joint_motion.cpp
     - examples/python/high_level_nrt_joint_motion.py
   * - movej_pose2 示例
     - 无
     - examples/python/high_level_nrt_eepose_motion.py
   * - 多路点 EE（含 MoveL 思路）
     - 无
     - examples/python/high_level_nrt_eepose_circle.py
   * - 双臂 Group MoveJ
     - examples/cpp/nrt_dual_arm_step_to_zero.cpp
     - examples/python/high_level_nrt_dual_arm_joint_motion.py

11.5.13 快速查阅：模式 → motion 类型 → 关键字段
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


.. code-block:: text

   MoveJ       → JointMotion         → waypoints[].target = 关节角
   movej_pose2 → EePoseMotion        → path_policy = JointSmooth
   MoveL       → EePoseMotion        → path_policy = EePoseSmooth
   SpeedJ      → JointVelocityMotion → waypoints[].target = 关节速度
   SpeedL      → EeVelocityMotion    → waypoints[].target_twist = 6D twist
   speed_stop  → MotionHandle.stop   → HoldPosition
   关节步进    → JointMotion         → waypoints[].reference_type = Relative
   位置步进    → EePoseMotion        → 绝对 target_pose（应用层 xyz 增量）
   姿态步进    → EePoseMotion        → 绝对 target_pose（应用层姿态增量）


11.6 NRT 运动完整参数
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

本文档按 SDK 源码 对 nrt.Robot.move_async()（C++：srobots::hl::nrt::Robot::move_async()）做 全量参数枚举。

定义来源：

- include/cpp/high_level/srobots/hl/common/motion_spec.hpp
- include/c/srobot.h
- include/cpp/high_level/srobots/hl/nrt/robot.hpp
- src/api_impl/python/robot_hl_py.cpp


11.6.1 函数签名（顶层 5 个参数）
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. raw:: html

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

.. code:: cpp

   auto result = nrt.move_async(scope, arms, motion, completion, planning_mode);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

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

.. code:: python

   handle = nrt.move_async(scope, arms, motion [, completion, planning_mode])


.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>


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

   * - 参数
     - Python 类型
     - C++ 类型
     - 默认值
     - 作用
   * - scope
     - MotionScope
     - sr_hl_motion_scope
     - 无
     - 运动作用范围：SingleArm（单臂）或 Group（多臂协同，同一 motion 作用于 arms 列表中的臂）
   * - arms
     - list[ArmId]
     - std::vector<sr_arm_id>
     - 无
     - 参与运动的臂：Left / Right；Group 时可 [Left, Right]
   * - motion
     - 见下文 8 种之一
     - MotionSpec variant
     - 无
     - 运动规格，决定运动族（含 IX 躯干/头部 MoveJ）
   * - completion
     - CompletionCriteria
     - sr_hl_completion_criteria
     - 省略时自动生成
     - 何时判定 motion 完成；省略时用 Robot.default_control_config() 推导（见 §8）
   * - planning_mode
     - MotionPlanningMode
     - MotionPlanningMode
     - Standard
     - 选择标准规划或 OnlineChunk；与 streaming 生命周期和 path policy 相互独立

返回值：MotionHandle（不是 move_async 的入参，但常与速度流配合使用）。


11.6.2 motion 八种类型（八选一）
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


C++ ``MotionSpec`` 和 Python 接受以下八种 motion：


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

   * - motion 类型
     - C family
     - 用途
   * - JointMotion
     - SR_HL_MOTION_JOINT
     - 关节空间点位（MoveJ、关节步进）
   * - JointVelocityMotion
     - SR_HL_MOTION_JOINT_VELOCITY
     - 关节速度流（SpeedJ）
   * - TorsoJointMotion
     - SR_HL_MOTION_TORSO_JOINT
     - IX 五轴躯干 MoveJ / OnlineChunk；SingleArm scope、空 arms，C++/Python
   * - HeadJointMotion
     - SR_HL_MOTION_HEAD_JOINT
     - IX 两轴头部 MoveJ / OnlineChunk；SingleArm scope、空 arms，C++/Python
   * - EePoseMotion
     - SR_HL_MOTION_EE_POSE
     - 末端位姿运动（movej_pose2 / MoveL）
   * - EeVelocityMotion
     - SR_HL_MOTION_EE_VELOCITY
     - 末端 twist 速度流（SpeedL）
   * - DualArmEePoseMotion
     - SR_HL_MOTION_EE_POSE
     - 左右臂各自使用 EePoseMotion 的双臂 group 运动
   * - WholeBodyTargetMotion
     - SR_HL_MOTION_WHOLE_BODY_TARGET
     - 完整全身目标帧，仅用于支持该能力的 streaming executor

11.6.2.1 JointMotion（motion 级，2 个字段）
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


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

   * - 字段
     - 类型
     - 默认
     - 作用
   * - waypoints
     - JointWaypoint[]
     - 必填
     - 关节路点序列，至少 1 个
   * - max_joint_speed_deg_s
     - float?
     - 未设置
     - 整段运动的关节角速度上限（deg/s）；Supervisor 会换算为 rad/s 用于规划

11.6.2.2 JointVelocityMotion（motion 级，2 个字段）
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


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

   * - 字段
     - 类型
     - 默认
     - 作用
   * - waypoints
     - JointWaypoint[]
     - 必填
     - 速度路点；此时 target 表示 关节速度（rad/s），不是位置
   * - max_joint_speed_deg_s
     - float?
     - 未设置
     - 关节角速度上限（deg/s）

11.6.2.3 EePoseMotion（motion 级，7 个字段）
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


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

   * - 字段
     - 类型
     - 默认
     - 作用
   * - waypoints
     - EePoseWaypoint[]
     - 必填
     - 末端位姿路点序列
   * - ik_options
     - IkOptions
     - 见 §5
     - 每个路点做 IK（位姿→关节）时的求解参数
   * - path_policy
     - EePosePathPolicy
     - JointSmooth
     - JointSmooth：关节空间平滑（movej_pose2）；EePoseSmooth：笛卡尔直线（MoveL）
   * - default_target_speed_m_s
     - float?
     - 未设置
     - 路点未设 target_speed_m_s 时的默认 EE 线速度（m/s）
   * - max_joint_speed_deg_s
     - float?
     - 未设置
     - 关节角速度上限（deg/s）
   * - circle_options
     - EePoseCircleOptions?
     - 未设置
     - EePoseSmoothCircle 使用的 MoveC 几何参数

11.6.2.4 EeVelocityMotion（motion 级，2 个字段）
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


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

   * - 字段
     - 类型
     - 默认
     - 作用
   * - waypoints
     - EeVelocityWaypoint[]
     - 必填
     - 末端 twist 速度路点
   * - max_joint_speed_deg_s
     - float?
     - 未设置
     - 关节角速度上限（deg/s）

11.6.3 路点（Waypoint）字段 — 全量
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


11.6.3.1 JointWaypoint（7 个字段）
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


用于 JointMotion 和 JointVelocityMotion。


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

   * - 字段
     - 类型
     - 默认
     - 作用
   * - target
     - [7] float
     - 必填
     - JointMotion：目标关节角（rad）；JointVelocityMotion：目标关节速度（rad/s）
   * - target_velocity
     - [7] float?
     - 未设置
     - 路点处目标关节速度（rad/s）；MoveJ 末点建议 [0]*7。SDK 对 JointMotion/JointVelocityMotion 会 强制最后一个路点 target_velocity 为 0（否则打 warning 并改写）
   * - reference_type
     - uint / ReferenceType
     - 0 (Absolute)
     - 0 Absolute：target 为绝对关节角/速度；1 Relative：target 为相对 上一路点绝对目标（首点相对 motion 起始关节位置）的增量
   * - relative_dynamics_factor
     - RelativeDynamicsFactor
     - 全 1.0
     - 该路点动力学缩放，见 §4
   * - hold_target_duration_sec
     - float
     - 0.0
     - 到达后在目标处保持时长（s）；proto 有该字段，Supervisor 段时长 主要 用 minimum_time_sec / max_total_duration_sec
   * - minimum_time_sec
     - float
     - 0.0
     - 到达该路点的 最短时间（s）；>0 时优先作为段时长
   * - max_total_duration_sec
     - float
     - 0.0
     - 该路点 最长允许时间（s）；minimum_time_sec 未设时可能作为段时长；0 表示不单独限制

target 维度：7（SROBOTS_ARM_DOF），单位 rad 或 rad/s。


11.6.3.2 EePoseWaypoint（7 个字段）
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


用于 EePoseMotion。


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

   * - 字段
     - 类型
     - 默认
     - 作用
   * - target_pose
     - [7] float
     - 必填
     - [x, y, z, qx, qy, qz, qw]（m + 四元数）
   * - target_speed_m_s
     - float?
     - 未设置
     - 该路点 EE 线速度（m/s）；未设则用 motion 的 default_target_speed_m_s；仍无则走 fallback 段时长
   * - reference_type
     - uint
     - 0
     - 0 Absolute 有效；1 Relative 当前 Supervisor 直接报错（"relative ee pose waypoint not supported"）。位置/姿态步进需在应用层算绝对 pose 再提交
   * - relative_dynamics_factor
     - RelativeDynamicsFactor
     - 默认
     - 见 §4
   * - hold_target_duration_sec
     - float
     - 0.0
     - 同 JointWaypoint
   * - minimum_time_sec
     - float
     - 0.0
     - 最短时间；EE 段时长优先级：minimum_time_sec > 由 target_speed_m_s 推算 > max_total_duration_sec > fallback
   * - max_total_duration_sec
     - float
     - 0.0
     - 最长时间上限

11.6.3.3 EeVelocityWaypoint（6 个字段）
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


用于 EeVelocityMotion。


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

   * - 字段
     - 类型
     - 默认
     - 作用
   * - target_twist
     - [6] float
     - 必填
     - [vx, vy, vz, wx, wy, wz]（m/s, rad/s）
   * - reference_type
     - uint
     - 0
     - 语义与关节不同：0 = Base 坐标系；1 = TCP（工具）坐标系；其他值报错
   * - relative_dynamics_factor
     - RelativeDynamicsFactor
     - 默认
     - 见 §4
   * - hold_target_duration_sec
     - float
     - 0.0
     - 同 JointWaypoint
   * - minimum_time_sec
     - float
     - 0.0
     - 该速度指令段的最短时间
   * - max_total_duration_sec
     - float
     - 0.0
     - 该速度指令段的最长时间

target_twist 维度：6（SROBOTS_CART_DOF）。


11.6.4 RelativeDynamicsFactor（路点共用，4 个字段）
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


所有 Waypoint 的 relative_dynamics_factor 字段：


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

   * - 字段
     - 默认
     - 作用
   * - velocity
     - 1.0
     - 速度缩放因子（≤0 时 Supervisor 按 1.0 处理）
   * - acceleration
     - 1.0
     - 加速度缩放
   * - jerk
     - 1.0
     - jerk 缩放
   * - max_dynamics
     - false
     - true 时尽量用最大动力学能力（proto 字段；具体效果依赖 Supervisor 规划器）

11.6.5 IkOptions（仅 EePoseMotion，7 个字段）
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


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

   * - 字段
     - 默认
     - 作用
   * - max_iterations
     - 80
     - IK 最大迭代次数
   * - position_tolerance_m
     - 0.002
     - 位置收敛容差（m）
   * - orientation_tolerance_rad
     - 0.02
     - 姿态收敛容差（rad）
   * - damping
     - 1e-4
     - 阻尼，缓解奇异
   * - max_step_norm_rad
     - 0.2
     - 单次迭代关节步长上限（rad）
   * - timeout_sec
     - 0.02
     - 单次 IK 求解超时（s）
   * - allow_approximate_solution
     - false
     - 是否接受近似 IK 解

11.6.6 EePosePathPolicy（仅 EePoseMotion，3 个枚举值）
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


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

   * - 值
     - 作用
   * - JointSmooth
     - 关节空间平滑到达（movej_pose2）；EE 路径不保证直线
   * - EePoseSmooth
     - 笛卡尔空间直线插值 + IK（MoveL）；IX 不支持 OnlineChunk
   * - EePoseSmoothCircle
     - 笛卡尔空间圆弧 + IK（MoveC）；不支持 OnlineChunk

MotionPlanningMode（提交参数）
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

``planning_mode`` 是 ``move_async()`` 和 ``start_motion_streaming()`` 的可选提交参数，
不属于 ``JointMotion`` 或 ``EePoseMotion``。它与 streaming 生命周期相互独立：前者
选择规划器，后者决定 motion 是否保持打开并允许 ``replace()`` / ``finish()``。
省略参数时使用 ``Standard``，不会因为路点多、异步提交或 streaming 自动进入
OnlineChunk；``replace()`` 只更新路点，不能改变已选规划器。

单次 ``move_async()`` 可执行一个有限 OnlineChunk；连续滚动必须在同一个
``start_motion_streaming()`` 返回的 handle 上调用 ``replace()``，多个独立
``move_async()`` 不共享在线规划状态。

IX 的 OnlineChunk 仅接受 ``JointMotion``、``TorsoJointMotion``、``HeadJointMotion``
以及 ``path_policy=JointSmooth`` 的 ``EePoseMotion``。Cartesian ``EePoseSmooth``、
MoveC、速度流和全身目标不能选择 OnlineChunk。每条流固定一个运动单元，只接受
完整绝对窗口的 ``replace()``，不接受 ``append()``。头、躯干分别持有自己的 handle，
不保证跨单元同时切换或同步到达；两者使用 ``SingleUnit`` scope 和空 ``arms``，
旧 ``SingleArm`` 调用保持兼容。机械臂 JointMotion 也接受 SingleUnit；EE pose 仍用 SingleArm。
独立头/躯干只接受关节目标；EE pose 输入及混入关节请求的 EE 字段在提交、Replace
时直接拒绝。EE pose 必须选择手臂；OnlineChunk 的 JointSmooth 只支持一个手臂，
双臂 Group 或携带右臂 EE payload 的请求由 IX supervisor 拒绝。
共用 SDK/server 保留 develop 的 EE OnlineChunk 准入，最终支持范围由 supervisor 决定。
窗口不接受相对目标、时间约束、目标速度或请求级 jerk 缩放（jerk 仅接受未指定或 1）。
单目标插值使用配置的 Ruckig jerk 上限；多路点规划约束速度和加速度。
IX 默认碰撞保护只允许一个未结束的场景运动；独立 handle 不表示允许同时运行。
躯干与手臂、WBC 与头/躯干运动还受运动所有权限制。

``WholeBodyJointMotion`` 通过 ``move_async(MotionScope.WholeBody, [], motion)``
提交头/躯干/左右臂完整 2/5/7/7 关节目标，只支持有限 Standard，不支持 OnlineChunk、
streaming、append 或 replace。每帧四单元共享 command ID 和参考时间，终态等待四单元
消费确认。21 轴联动直接忽略碰撞开关；单单元运动继续使用原碰撞保护。
它占用四个单元，不能与独立 OnlineChunk 或 WBC 运动重叠。新 SDK 头文件/原生绑定
必须与支持专用提交入口的 libsrobot 配套；旧函数表前缀保留兼容。

显式关节空间 OnlineChunk 的 C++ 调用形式如下；后续 ``next_chunk`` 仍是完整的
绝对关节预测窗口，而不是只发送新增尾点：

.. code-block:: cpp

   srobots::hl::JointMotion first_chunk;
   first_chunk.waypoints = first_waypoints;
   auto started = nrt.start_motion_streaming(
       SR_HL_MOTION_SCOPE_SINGLE_ARM, {SR_ARM_LEFT}, first_chunk,
       srobots::hl::MotionPlanningMode::OnlineChunk);
   auto& handle = started.value();
   handle.replace(next_chunk);
   handle.finish();

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

   * - 值
     - 作用
   * - Standard
     - 使用现有 TOPPRA、Ruckig、MoveL 或 MoveC 路由
   * - OnlineChunk
     - JointMotion、TorsoJointMotion、HeadJointMotion 使用在线关节规划；EePoseMotion 的 JointSmooth 先做稀疏 IK

11.6.7 CompletionCriteria（第 4 参数，8 个字段）
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


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

   * - 字段
     - Python 默认
     - 作用
   * - mode
     - CompletionMode.Reached
     - Reached：实测反馈进入容差后完成；Commanded：参考轨迹/指令发完即完成（速度流常用）
   * - target
     - CompletionTarget.Auto
     - 完成判据对象：Auto / Joint / EePose / Both（EE 运动可指定按关节或 EE 判定）
   * - position_tolerance_rad
     - 0.01
     - 关节位置容差（rad）
   * - velocity_tolerance_rad_s
     - 0.03
     - 关节速度容差（rad/s）
   * - ee_position_tolerance_m
     - 0.005
     - EE 位置容差（m）
   * - ee_orientation_tolerance_rad
     - 0.03
     - EE 姿态容差（rad）
   * - settle_time_sec
     - 0.0
     - 进入容差后需 持续稳定 的时间（s）；0 表示首次进入容差即完成
   * - timeout_sec
     - 2.0
     - 等待完成的总超时（s）

11.6.7.1 省略 completion 时的默认值
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


来自 CompletionCriteriaFromRobotControlConfig(default_control_config)：


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

   * - 字段
     - 值
   * - mode
     - Reached
   * - position_tolerance_rad
     - 0.01
   * - velocity_tolerance_rad_s
     - 0.03
   * - settle_time_sec
     - default_control_config.completion_settle_time_sec（默认 0.0）
   * - timeout_sec
     - 2.0
   * - target
     - Auto
   * - ee_position_tolerance_m
     - 由 accuracy preset 推导（Normal≈0.003m, High≈0.001m）
   * - ee_orientation_tolerance_rad
     - 0.03

可通过 nrt.set_default_control_config(...) 间接影响省略 completion 时的行为。


11.6.8 枚举与常量（参数取值）
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


MotionScope
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


- SingleArm = 0
- Group = 1


ArmId
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


- Left / Right


ReferenceType（主要用于 JointWaypoint）
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


- Absolute = 0
- Relative = 1


CompletionMode
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


- Reached = 0
- Commanded = 1

.. _12-motionhandle:

12. ``MotionHandle``
--------------------

.. _121-valid:

12.1 ``valid()``
~~~~~~~~~~~~~~~~

**摘要：** 判断句柄是否绑定有效控制器运动。

**参数：** 无。

**返回值：** 两种语言均返回布尔值。

.. raw:: html

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

.. code:: cpp

   if (!handle.valid()) { /* submission failed */ }

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

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

.. code:: python

   if not handle.valid():
       raise RuntimeError("motion submission failed")

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _122-motion_id--motionid:

12.2 ``motion_id()`` / ``motionId()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 获取控制器分配的运动 ID。

**参数：** 无。

**返回值：** 64 位无符号 ID；无效句柄通常为
``0``\ 。

.. raw:: html

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

.. code:: cpp

   const auto id = handle.motion_id();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

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

.. code:: python

   motion_id = handle.motion_id()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _123-phase:

12.3 ``phase()``
~~~~~~~~~~~~~~~~

**摘要：** 获取句柄缓存的最新运动阶段。

**参数：** 无。

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

.. raw:: html

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

.. code:: cpp

   const auto phase = handle.phase();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

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

.. code:: python

   phase = handle.phase()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _124-status:

12.4 ``status()``
~~~~~~~~~~~~~~~~~

**摘要：** 从控制器查询最新运动状态。

**参数：** 无。

**返回值：** ``MotionStatus``\ ，包含结果码、运动 ID、阶段、活动路点索引、路点数和
消息。

.. raw:: html

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

.. code:: cpp

   const auto status = handle.status();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

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

.. code:: python

   status = handle.status()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _125-wait:

12.5 ``wait()``
~~~~~~~~~~~~~~~

**摘要：** 等待运动进入终态。

============================= ======================================
参数                          说明
============================= ======================================
``timeout`` / ``timeout_sec`` 负值表示无限等待；Python 默认 ``-1.0``
============================= ======================================

**返回值：** C++ 返回 ``Result<MotionStatus>``\ ；成功表示取得了终态，运动本身的
结果仍需检查 ``MotionStatus::result`` 和 ``phase``\ 。超时返回 ``TIMEOUT`` 错误结果。
Python 成功时返回 ``MotionStatus``\ ，等待失败时抛出 ``high_level.RobotError``\ 。


.. raw:: html

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

.. code:: cpp

   auto result = handle.wait(10.0);
   if (result.ok()) {
     const auto &status = result.value();
   }

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

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

.. code:: python

   status = handle.wait(timeout_sec=10.0)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _126-async_wait:

12.6 ``async_wait()``
~~~~~~~~~~~~~~~~~~~~~

**摘要：** 注册一次完成回调；每个句柄只允许注册一次。

============ ================================
参数         说明
============ ================================
``callback`` 接收最终 ``MotionStatus`` 的回调
============ ================================

**返回值：** 注册成功返回 ``true``\ ；句柄无效、回调为空或已经注册时返回 ``false``\ 。

.. raw:: html

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

.. code:: cpp

   handle.async_wait([](const srobots::hl::nrt::MotionStatus &status) {
     // 通知应用线程。
   });

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

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

.. code:: python

   registered = handle.async_wait(lambda status: print(status.phase))

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _127-stop:

12.7 ``stop()``
~~~~~~~~~~~~~~~

**摘要：** 请求停止当前运动。

========== ==========================
参数       说明
========== ==========================
``policy`` 停止策略，默认保持当前位置
========== ==========================

**返回值：** C++ 返回 ``ResultCode``\ ；无效句柄返回 ``NOT_READY``\ 。Python
返回 ``high_level.ResultCode``\ 。

.. raw:: html

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

.. code:: cpp

   const auto code = handle.stop(srobots::hl::StopPolicy::HoldPosition);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

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

.. code:: python

   code = handle.stop(high_level.HighLevelStopPolicy.HoldPosition)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _128-append:

12.8 ``append()``
~~~~~~~~~~~~~~~~~

**摘要：** 向流式运动尾部追加运动数据。

========== ============================
参数       说明
========== ============================
``motion`` 与流式运动兼容的高层运动规格
========== ============================

**返回值：** C++ 和 Python 返回错误码；非流式或无效句柄由错误码指示。


.. raw:: html

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

.. code:: cpp

   const auto code = handle.append(next_motion);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

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

.. code:: python

   code = handle.append(next_motion)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _129-replace:

12.9 ``replace()``
~~~~~~~~~~~~~~~~~~

**摘要：** 替换流式运动中尚未执行的数据。

========== ==================
参数       说明
========== ==================
``motion`` 替换用高层运动规格
========== ==================

**返回值：** C++ 和 Python 返回错误码。

.. raw:: html

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

.. code:: cpp

   const auto code = handle.replace(replacement);

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

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

.. code:: python

   code = handle.replace(replacement)

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _1210-finish:

12.10 ``finish()``
~~~~~~~~~~~~~~~~~~

**摘要：** 通知控制器流式输入已经结束，不再追加数据。

**参数：** 无。

**返回值：** C++ 和 Python 返回错误码；无效句柄返回 ``NOT_READY``\ 。


.. raw:: html

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

.. code:: cpp

   const auto code = handle.finish();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

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

.. code:: python

   code = handle.finish()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _1211-control_config:

12.11 ``control_config()``
~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 查询创建该句柄时保存的控制配置。Python 使用
``control_config()``\ 。

**参数：** 无。

**返回值：** ``const RobotControlConfig &``\ ；引用的生命周期不超过句柄。

.. raw:: html

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

.. code:: cpp

   const auto &config = handle.control_config();

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

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

.. code:: python

   config = handle.control_config

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. _1212-motionstatusterminal:

12.12 ``MotionStatus::terminal()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**摘要：** 判断运动状态是否已经进入完成、中止、错误或停止阶段。

**参数：** 无。

**返回值：** 终态返回 ``true``\ ，否则返回 ``false``\ 。

.. raw:: html

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

.. code:: cpp

   if (handle.status().terminal()) { /* motion ended */ }

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

.. raw:: html

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

.. code:: python

   ended = handle.status().terminal()

.. container:: sdk-example-reference

   参考示例：无

.. raw:: html

   </details>

