> ## 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)。
</Note>

## `simulation_sample_pick_and_place` 的管线流程

<img 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-architecture.png" alt="image" />

## `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 话题

<table>
  <thead>
    <tr>
      <th style={{width: '35%' }}>ROS 话题</th>
      <th style={{ width: '25%' }}>类型</th>
      <th astyle={{ width: '40%' }}>说明</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td align="left"><code>/joint\_states</code></td>
      <td align="left"><code>sensor\_msgs/msg/JointState</code></td>
      <td align="left">所有机器人关节控制信息的实时数据。</td>
    </tr>

    <tr>
      <td align="left"><code>/hand\_controller/controller\_state</code></td>
      <td align="left"><code>control\_msgs.msg.ControllerState</code></td>
      <td align="left">夹爪控制器的当前状态和状态信息。</td>
    </tr>

    <tr>
      <td align="left"><code>/rm\_group\_controller/controller\_state</code></td>
      <td align="left"><code>control\_msgs.msg.ControllerState</code></td>
      <td align="left">机械臂控制器的当前状态和状态信息。</td>
    </tr>

    <tr>
      <td align="left"><code>/robot\_description</code></td>
      <td align="left"><code>std\_msgs.msg.String</code></td>
      <td align="left">用于机器人建模和可视化的 XML 格式 URDF 机器人描述。</td>
    </tr>

    <tr>
      <td align="left"><code>/robot\_description\_semantic</code></td>
      <td align="left"><code>std\_msgs.msg.String</code></td>
      <td align="left">用于 MoveIt 规划和配置的 SRDF 语义机器人描述。</td>
    </tr>
  </tbody>
</table>

## 前提条件

您已完成[为运行示例应用设置环境](./set-up-env-for-sample-app)中的以下设置。

* 设置设备
* 设置主机 docker

### 设置仿真环境

1. 在主机上，根据 [QRB ROS Simulation](https://github.com/qualcomm-qrb-ros/qrb_ros_simulation) 的 **README** 完成以下操作，构建 Qualcomm 机器人仿真环境。确保设备和主机位于同一局域网内，并且可以通过 ROS 通信相互通信。
   1. 在 Ubuntu24.04 主机或 Docker 上设置开发环境。
   2. 从源码构建。
2. 在主机上运行 `qrb ros simulation`。打开一个终端并运行以下命令，启动 `Gazebo` 仿真环境：
   ```powershell theme={null}
   # Set the ROS_DOMAIN_ID
   (ssh) source install/setup.sh
   (ssh) export ROS_DOMAIN_ID=55
   (ssh) 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` 按钮开始仿真，然后打开另一个终端并运行以下命令，启动控制器管理器：
   ```powershell theme={null}
   # Set the ROS_DOMAIN_ID
   (ssh) source install/setup.sh
   (ssh) export ROS_DOMAIN_ID=55
   (ssh) ros2 launch qrb_ros_sim_gazebo gazebo_rml_63_gripper_load_controller.launch.py
   ```

## 运行开箱即用的 `simulation_sample_pick_and_place`

1. 在开发套件上，打开一个终端并运行以下命令，启动 `moveit` ROS move group：
   ```cpp theme={null}
   # setup runtime environment
   (ssh) source /usr/share/qirp-setup.sh
   # Set the ROS_DOMAIN_ID
   (ssh) export ROS_DOMAIN_ID=55
   (ssh) ros2 launch simulation_sample_pick_and_place simulation_sample_pick_and_place.launch.py
   ```
   如果 ROS 节点启动成功，将出现以 `[move_group-1] You can start planning now!` 开头的日志。

2. 打开另一个终端并运行以下命令，启动抓取和放置示例应用：
   ```cpp theme={null}
   # setup runtime environment
   (ssh) source /usr/share/qirp-setup.sh
   # Set the ROS_DOMAIN_ID
   (ssh) export ROS_DOMAIN_ID=55
   (ssh) ros2 run simulation_sample_pick_and_place qrb_ros_arm_pick_place
   ```

**结果**

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

## 构建并运行 `simulation_sample_pick_and_place`

1. 在主机的终端中，运行以下命令：

   <Note>
     **注意**

     * `<qir_version>`：QIR SDK 的版本，请参阅 [QIR SDK 2.0 发行说明](../../Key-Documents/QIR-SDK-Release-Notes/robotics-sdk-qli2.0-062026)。
     * `<qir_decompressed_path>`：您解压 QIR SDK 的路径。
   </Note>

   1. 构建示例应用项目。

      ```powershell theme={null}
      # Set up the QIR SDK  environment
      (ssh) tar -zxf qirp-sdk_<qir_version>.tar.gz
      (ssh) cd <qir_decompressed_path>/qirp-sdk
      (ssh) source setup.sh
      # Build the sample
      (ssh) cd <qir_decompressed_path>/qirp-sdk/qirp-samples/robotics/simulation_sample_pick_and_place
      (ssh) chmod +x scripts/build.sh
      (ssh) bash scripts/build.sh
      ```
   2. 打包示例应用并推送到设备。
      ```powershell theme={null}
      # package and push build result of sample
      (ssh) cd <qir_decompressed_path>/qirp-sdk/qirp-amples/robotics/simulation_sample_pick_and_place/install
      (ssh) tar -czf simulation_sample_pick_and_place.tar.gz lib share
      (ssh) scp simulation_sample_pick_and_place.tar.gz root@[ip-addr]:/opt/
      ```
2. 在开发套件上，运行以下命令：
   1. 安装示例应用。
      ```python theme={null}
      # Install sample package
      (ssh) 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) 中的步骤运行示例应用。
