> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 使用 simulation_sample_pick_and_place 在仿真器中启用抓取和放置

此抓取和放置仿真示例应用使用基于 C++ 的机器人操作 ROS 2 节点 `simulation_sample_pick_and_place` 演示使用 `MoveIt2` 进行运动规划和使用 `Gazebo` 进行物理仿真的自主抓取和放置操作。

> [!NOTE]
>
> **注意**
>
> 有关更多信息，请参见 GitHub 上的 [simulation\_sample\_pick\_and\_place](https://github.com/qualcomm-qrb-ros/qrb_ros_samples/tree/stable-simulation_sample_pick_and_place/1.0.1)。

<video autoPlay muted loop playsInline width="2024" height="824" src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-prod/zh/SDKs/QIR-SDK-2.0/media/80-65220-2-qirp-sdk-qsg/simulation-sample-pick-and-place.mp4" />

图：`simulation_sample_pick_and_place` 的示例效果

## `simulation_sample_pick_and_place` 的流水线流程

![image](https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-prod/zh/SDKs/QIR-SDK-2.0/media/80-65220-2-qirp-sdk-qsg/simulation-sample-pick-and-place-architecture.png)

## `simulation_sample_pick_and_place` 流水线中使用的 ROS 节点

| ROS 节点 | 说明 |
| :- | :- |
| `qrb_ros_simulation` | 一个用于搭建 Qualcomm 机器人仿真环境的 ROS 包。有关详细信息，请参见 [QRB ROS Simulation](https://github.com/qualcomm-qrb-ros/qrb_ros_simulation)。 |
| `simulation_sample_pick_and_place` | 抓取和放置的源代码。 |
| `moveit_ros_move_group` | 一个提供 MoveIt ROS MoveGroup 接口的 ROS 包。有关详细信息，请参见 [MoveIt MoveGroup](https://moveit.picknik.ai/humble/doc/examples/move_group_interface/move_group_interface_tutorial.html)。 |

## `simulation_sample_pick_and_place` 流水线中使用的 ROS topic

<table>
  <thead>
    <tr>
      <th>ROS Topic</th>
      <th>类型</th>
      <th>说明</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td align="left">`/joint_states`</td>
      <td align="left">`sensor_msgs/msg/JointState`</td>
      <td align="left">所有机器人关节控制信息的实时数据。</td>
    </tr>

    <tr>
      <td align="left">`/hand_controller/controller_state`</td>
      <td align="left">`control_msgs.msg.ControllerState`</td>
      <td align="left">夹爪控制器的当前状态和状态信息。</td>
    </tr>

    <tr>
      <td align="left">`/rm_group_controller/controller_state`</td>
      <td align="left">`control_msgs.msg.ControllerState`</td>
      <td align="left">机械臂控制器的当前状态和状态信息。</td>
    </tr>

    <tr>
      <td align="left">`/robot_description`</td>
      <td align="left">`std_msgs.msg.String`</td>
      <td align="left">XML 格式的 URDF 机器人描述，用于机器人建模和可视化。</td>
    </tr>

    <tr>
      <td align="left">`/robot_description_semantic`</td>
      <td align="left">`std_msgs.msg.String`</td>
      <td align="left">用于 MoveIt 规划和配置的 SRDF 语义机器人描述。</td>
    </tr>
  </tbody>
</table>

## 主机上的前提条件

> [accordion] 试一试
>
> 你已完成 [设置运行示例应用的环境](https://dragonwingdocs.qualcomm.com/zh/SDKs/QIR-SDK-2.0/set-up-env-for-sample-app.md) 中的以下设置。
>
> * 设置设备
> * 设置主机 docker
>
> ### 设置仿真环境
>
> **1. 在主机计算机上构建仿真环境**
>
> 按照[设置主机 Docker](https://dragonwingdocs.qualcomm.com/zh/SDKs/QIR-SDK-2.0/set-up-env-for-sample-app.md#set-up-the-host-docker)中的步骤构建 Qualcomm 机器人仿真环境，确保设备和主机在同一本地网络上，并可通过 ROS 通信相互通信。
>
> **2. 启动 Gazebo 仿真环境**
>
> 在主机上运行 `qrb ros simulation`。打开终端并运行以下命令以启动 `Gazebo` 仿真环境：
>
> ```bash title="SSH Session" theme={null}
> # Set the ROS_DOMAIN_ID
> source install/setup.sh
> export ROS_DOMAIN_ID=55
> ros2 launch qrb_ros_sim_gazebo gazebo_rml_63_gripper.launch.py world_model:=warehouse initial_x:=2.2 initial_y:=-2 initial_z:=1.025 initial_yaw:=3.14159 initial_pitch:=0.0 initial_roll:=0.0 use_sim_time:=true
> ```
>
> **3. 启动控制器管理器**
>
> 在 `Gazebo` 中选择 `Play` 按钮以启动仿真，然后打开另一个终端并运行以下命令以启动控制器管理器：
>
> ```bash title="SSH Session" theme={null}
> # Set the ROS_DOMAIN_ID
> source install/setup.sh
> export ROS_DOMAIN_ID=55
> ros2 launch qrb_ros_sim_gazebo gazebo_rml_63_gripper_load_controller.launch.py
> ```

## 在设备上开箱即用运行 `simulation_sample_pick_and_place`

> [accordion] 试一试
>
> **1. 启动 moveit ROS move group**
>
> 在开发套件上，打开一个终端并运行以下命令：
>
> ```bash title="SSH Session" theme={null}
> # setup runtime environment
> source /usr/share/qirp-setup.sh
> # Set the ROS_DOMAIN_ID
> export ROS_DOMAIN_ID=55
> ros2 launch simulation_sample_pick_and_place simulation_sample_pick_and_place.launch.py
> ```
>
> 如果 ROS 节点成功启动，会出现从 `[move_group-1] You can start planning now!` 开始的日志。
>
> **2. 启动抓取和放置示例应用**
>
> 打开另一个终端并运行以下命令：
>
> ```bash title="SSH Session" theme={null}
> # setup runtime environment
> source /usr/share/qirp-setup.sh
> # Set the ROS_DOMAIN_ID
> export ROS_DOMAIN_ID=55
> ros2 run simulation_sample_pick_and_place qrb_ros_arm_pick_place
> ```

**结果**

如果 ROS 节点成功启动，你可以在 Gazebo 中看到机械臂执行抓取和放置操作。

## 构建并运行 `simulation_sample_pick_and_place`

> [accordion] 试一试
>
> > [!NOTE]
> >
> > **注意**
> >
> > * `<qir_version>`：QIR SDK 的版本，请参见 [QIR SDK 2.0 发布说明](https://dragonwingdocs.qualcomm.com/zh/SDKs/QIR-SDK-2.0/release-notes.md)。
> > * `<qir_decompressed_path>`：你解压 QIR SDK 的路径。
>
> **1. 在主机计算机上构建并打包**
>
> 1. 构建示例应用项目。
>    ```bash title="SSH Session" theme={null}
>    # Set up the QIR SDK  environment
>    tar -zxf qirp-sdk_<qir_version>.tar.gz
>    cd <qir_decompressed_path>/qirp-sdk
>    source setup.sh
>    # Build the sample
>    cd <qir_decompressed_path>/qirp-sdk/qirp-samples/robotics/simulation_sample_pick_and_place
>    chmod +x scripts/build.sh
>    bash scripts/build.sh
>    ```
> 2. 打包并将示例应用推送到设备。
>    ```bash title="SSH Session" theme={null}
>    # package and push build result of sample
>    cd <qir_decompressed_path>/qirp-sdk/qirp-samples/robotics/simulation_sample_pick_and_place/install
>    tar -czf simulation_sample_pick_and_place.tar.gz lib share
>    scp simulation_sample_pick_and_place.tar.gz root@[ip-addr]:/opt/
>    ```
>
> **2. 在开发套件上安装并运行**
>
> 1. 安装示例应用。
>    ```bash title="SSH Session" theme={null}
>    # Install sample package
>    tar --no-overwrite-dir --no-same-owner -zxf /opt/simulation_sample_pick_and_place.tar.gz -C /usr/ros/jazzy/
>    ```
> 2. 按照 [开箱即用运行 simulation\_sample\_pick\_and\_place](#run-out-of-the-box-simulation_sample_pick_and_place) 中的步骤运行示例应用。
