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

# 使用 simulation_sample_amr_simple_motion 在仿真器中控制 AMR

> 此示例应用演示了在仿真器中控制 AMR。

`simulation_sample_amr_simple_motion` 是一个仿真示例应用，使用基于 Python 的 ROS 节点在仿真器中控制 QRB 自主移动机器人 (AMR) 的运动。

[QRB ROS Simulation](https://github.com/qualcomm-qrb-ros/qrb_ros_simulation) 包提供了仿真环境。它允许你通过向 `/qrb_robot_base/cmd_vel` topic 发布 ROS 消息来控制 QRB AMR 的运动。

<Note>
  **注意**

  有关更多信息，请参见 GitHub 上的 [simulation\_sample\_amr\_simple\_motion](https://github.com/qualcomm-qrb-ros/qrb_ros_samples/tree/main/robotics/simulation_sample_amr_simple_motion)。
</Note>

<video
  autoPlay
  muted
  loop
  playsInline
  width={1200}
  height={480}
  src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-staging/zh/SDKs/QIR-SDK-2.0/media/80-65220-2-qirp-sdk-qsg/simulation_sample_amr_simple_motion_result.mp4"
  style={{
width: "80%",
display: "block",
margin: "0 auto" }}
/>

<p style={{ textAlign: 'center', fontWeight: 'bold' }}>
  图：`simulation_sample_amr_simple_motion` 的示例效果
</p>

## `simulation_sample_amr_simple_motion` 的流水线流程

<img
  src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-staging/zh/SDKs/QIR-SDK-2.0/media/80-65220-2-qirp-sdk-qsg/simulation-amr-simple-motion-pipeline.svg"
  style={{
width: "100%",
display: "block",
margin: "0 auto" }}
/>

<p style={{ textAlign: 'center', fontWeight: 'bold' }}>
  图：`simulation_sample_amr_simple_motion` 的流水线流程
</p>

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

<table>
  <thead>
    <tr>
      <th style={{ width: '30%' }}>ROS 节点</th>
      <th style={{ width: '70%' }}>说明</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`qrb_ros_simulation`</td>
      <td>`qrb ros simulation` 是一个 ROS 包，用于搭建 Qualcomm 机器人仿真环境。有关详细信息，请参见 [QRB ROS Simulation](https://github.com/qualcomm-qrb-ros/qrb_ros_simulation)。 </td>
    </tr>
  </tbody>
</table>

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

<table>
  <thead>
    <tr>
      <th style={{ width: '20%' }}>ROS topic</th>
      <th style={{ width: '30%' }}>类型</th>
      <th style={{ width: '20%' }}>发布者</th>
      <th style={{ width: '30%' }}>说明</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`/qrb_robot_base/cmd_vel`</td>
      <td>`geometry_msgs::msg::Twist` </td>
      <td>`simulation_sample_amr_simple_motion`</td>
      <td>指示机器人运动的速度命令。 </td>
    </tr>
  </tbody>
</table>

## 前提条件

你已完成 [设置运行示例应用的环境](./set-up-env-for-sample-app) 中的以下设置（跳过 **设置主机 docker** 的设置）。

<Accordion title="试一试">
  * 设置设备
  * 设置主机计算机

  ### 设置仿真环境

  <Steps>
    <Step title="在主机计算机上构建仿真环境">
      根据 [QRB ROS Simulation](https://github.com/qualcomm-qrb-ros/qrb_ros_simulation) 的 **README** 完成以下操作。确保设备和主机在同一本地网络上，并可通过 ROS 通信相互通信。

      1. 在 Ubuntu24.04 主机或 Docker 上设置开发环境。
      2. 从源码构建。
    </Step>

    <Step title="在主机上运行 QRB Robot Base AMR">
      ```bash theme={null}
      # Set the ROS_DOMAIN_ID
      export ROS_DOMAIN_ID=123
      ros2 launch qrb_ros_sim_gazebo gazebo_robot_base.launch.py namespace:=qrb_robot_base enable_laser:=false
      ```
    </Step>
  </Steps>
</Accordion>

## 开箱即用运行 `simulation_sample_amr_simple_motion`

在开发套件上，运行以下命令：

<Accordion title="试一试">
  ```bash theme={null}
  # setup runtime environment
  source /usr/share/qirp-setup.sh

  # Set the ROS_DOMAIN_ID
  export ROS_DOMAIN_ID=123

  ros2 run simulation_sample_amr_simple_motion simple_motion
  ```
</Accordion>

**结果**

如果 ROS 节点成功启动，会出现从 `=== AMR Simple Motion Control Usage: ===` 开始的日志。

然后，你可以输入运动控制命令，并在主机计算机上检查仿真器中 QRB AMR 的运动状态。

## 构建并运行 `simulation_sample_amr_simple_motion`

<Accordion title="试一试">
  <Note>
    **注意**

    * `<qir_version>`：QIR SDK 的版本，请参见 [QIR SDK 2.0 发布说明](./release-notes)。
    * `<qir_decompressed_path>`：QIR SDK 解压的路径。
  </Note>

  <Steps>
    <Step title="在主机计算机上构建并打包">
      1. 构建示例应用项目。
         ```bash theme={null}
         # Set up the QIR SDK  environment
         cd <decompressed_workspace>/images/iq-9075-evk/qirpsdk_artifacts/iq-9075-evk
         tar -zxf qirp-sdk_<qir_version>.tar.gz
         cd <qir_decompressed_path>/qirp-sdk
         source setup.sh
         # build sample
         cd <qir_decompressed_path>/qirp-sdk/qirp-samples/robotics/simulation_sample_amr_simple_motion
         colcon build
         ```
      2. 打包并将示例应用推送到设备。
         ```bash theme={null}
         # package and push build result of sample
         cd <qir_decompressed_path>/qirp-sdk/qirp-samples/robotics/simulation_sample_amr_simple_motion/install/simulation_sample_amr_simple_motion
         tar -czf simulation_sample_amr_simple_motion.tar.gz lib share
         scp simulation_sample_amr_simple_motion.tar.gz root@[ip-addr]:/opt/
         ```
    </Step>

    <Step title="在开发套件上安装并运行">
      1. 安装示例应用。
         ```bash title="SSH Session" theme={null}
         # Install sample package
         tar --no-overwrite-dir --no-same-owner -zxf /opt/simulation_sample_amr_simple_motion.tar.gz -C /usr/ros/jazzy/
         ```
      2. 按照 [开箱即用运行 simulation\_sample\_amr\_simple\_motion](#run-out-of-the-box-simulation_sample_amr_simple_motion) 中的步骤运行示例应用。
    </Step>
  </Steps>
</Accordion>
