> For the complete documentation index, see [llms.txt](https://yuelan-icus-organization.gitbook.io/pei-tao-ji-suan-ji/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yuelan-icus-organization.gitbook.io/pei-tao-ji-suan-ji/ros/ju-you-aruco-ban-jian-ce-gong-neng-de-ros.md).

# 具有 Aruco 板检测功能的 ROS

## 具有ArduCopter，ROS和Aruco板检测功能的室内自主飞行[¶](https://ardupilot.org/dev/docs/ros-aruco-detection.html#indoor-autonomous-flight-with-arducopter-ros-and-aruco-boards-detection)

本维基页面描述了如何设置能够实现室内自主飞行的系统。 该系统基于带有Raspberry Pi 3和Raspberry Pi相机模块v2的四轴飞行器。来自相机的图像用于计算树莓派上的姿势估计，并将结果作为MAVLink消息发送到飞行控制器。 相机是向下看的，在地板上有一个Aruco板，如下所示：

[![../\_images/ros-aruco-board.png](https://ardupilot.org/dev/_images/ros-aruco-board.png)](https://ardupilot.org/dev/_images/ros-aruco-board.png)

系统使用 [ROS](http://www.ros.org/) 来完成它必须执行的所有任务。来自Raspberry Pi相机的图像由[raspicam\_node](https://github.com/UbiquityRobotics/raspicam_node)捕获，姿势估计由[aruco\_gridboard](https://github.com/anbello/aruco_gridboard)的修改版本计算，并使用[mavros](http://wiki.ros.org/mavros)将相关消息发送到飞行控制器。所有这些ROS软件包以及我们稍后将看到的其他软件包都在Raspberry Pi 3上运行。

ROS节点raspicam\_node发布相机/图像和相机/camera\_info主题，节点aruco\_gridboard订阅这些主题并向mavros/vision\_pose/pose主题发布camera\_pose消息，mavros将ROS消息翻译成MAVLink消息并发送到飞控。

在开始使用系统之前，SET\_GPS\_GLOBAL\_ORIGIN消息和SET\_HOME\_POSITION随[脚本](https://github.com/anbello/aruco_gridboard/blob/master/script/set_origin.py)一起发送。

四轴飞行器上的飞行控制器和Raspberry Pi 3通过串行端口连接，而Rapsberry Pi 3和台式PC通过WiFi连接。台式 PC 仅用于配置和可视化目的。来自 ROS 的 [rviz](http://wiki.ros.org/rviz) 用于在 PC 上进行可视化。

### 系统组件[¶](https://ardupilot.org/dev/docs/ros-aruco-detection.html#components-of-the-system)

* 带有ArduCopter 160.3-dev的革命飞行控制器的小型四轴飞行器（7毫米）和以下相关参数：

```
AHRS_EKF_TYPE 2
BRD_RTC_TYPES 2
EKF2_ENABLE 1
EKF3_ENABLE 0
EK2_GPS_TYPE 3
EK2_POSNE_M_NSE 0.1
EK2_VELD_M_NSE 0.1
EK2_VELNE_M_NSE 0.1
EK2_EXTNAV_DELAY 80
GPS_TYPE 0
COMPASS_USE 0
COMPASS_USE2 0
COMPASS_USE3 0
SERIAL1_BAUD 921   (the serial port used to connect to Raspberry Pi)
SERIAL1_PROTOCOL 2
SYSID_MYGCS 1   (to accept control from mavros)
VISO_TYPE 0
```

* 在四轴飞行器上有一个树莓派3（通过串行端口连接到飞行控制器）和一个树莓派相机
* 在Raspberry Pi上，有带有raspicam\_node，aruco\_gridboard和mavros软件包的ROS Kinetic。

### 重现系统的说明[¶](https://ardupilot.org/dev/docs/ros-aruco-detection.html#instructions-to-reproduce-the-system)

#### 在四轴飞行器上的树莓派 3 上[¶](https://ardupilot.org/dev/docs/ros-aruco-detection.html#on-the-raspberry-pi-3-on-quadcopter)

* 使用 Ubiquity Robotics [Raspberry Pi 映像](https://downloads.ubiquityrobotics.com/pi.html)安装 Ubuntu 16.04 和 ROS Kinetic
* 编辑 /boot/config.txt 以在 /dev/ttyAMA0 上具有更高的串行速度（以 921600 波特连接）

```
find the row with #init_uart_clock=3000000 and change it in this way:
init_uart_clock=16000000
at the end of the file comment all lines after # Allow UART and Bluetooth ...
add the line:
dtoverlay=pi3-disable-bt
save
reboot
```

* 将串行端口与飞控上的一个遥测端口连接
* 按照 Ubiquity Robotics 网站上的[说明](https://learn.ubiquityrobotics.com/connect_network)使用 WiFi 连接到 PC
* 编辑 mavros 配置文件 apm\_config.yaml 以使用 MAVLink 的 SYSTEM\_TIME 和 TIMESYNC 消息同步飞行控制器和配套计算机 （Raspberry Pi） 时钟，如本[维基](https://ardupilot.org/dev/docs/ros-timesync.html)所示
* 按照本[维基](http://wiki.ros.org/camera_calibration/Tutorials/MonocularCalibration)中的说明校准相机
* 在 \~/catkin\_ws/src 中克隆这个[aruco\_gridboard](https://github.com/anbello/aruco_gridboard)分支
* 全部构建

```
cd ~/catkin_ws
catkin_make
```

#### 在台式电脑上[¶](https://ardupilot.org/dev/docs/ros-aruco-detection.html#on-the-desktop-pc)

* 在 Ubuntu 16.04 上安装 [ROS Kinetic](http://wiki.ros.org/kinetic/Installation/Ubuntu)（也许较新版本的工作方式相同，但未经测试）
* 安装 ros-kinetic-joy-teleop （sudo apt install ros-kinetic-joy-teleop） 并为您的操纵杆进行配置 - 我们使用操纵杆而不是RC，因为使用2.4GHz RC会干扰WiFi视频流。在 mavros 中有一个罗技 F710 操纵杆的配置文件，在aruco\_gridboard包中，我们为 Xbox one 操纵杆添加了配置文件。
* 安装 mavros （sudo apt install ros-kinetic-mavros\*）
* 如果您不熟悉 ROS[，请按照教程](http://wiki.ros.org/ROS/Tutorials)进行操作
* 编辑 \~/.bashrc 并附加以下行：

```
export ROS_MASTER_URI="http://ubiquityrobot.local:11311"
```

* 创建一个Catkin工作区（在Raspberry Pi上，这不是必需的，因为它已经在Ubiquity Robotics图像中）

```
cd $HOME
mkdir -p catkin_ws/src
cd catkin_ws
catkin_init_workspace
```

* 在 \~/catkin\_ws/src 中克隆这个[aruco\_gridboard](https://github.com/anbello/aruco_gridboard)分支
* 全部构建

```
cd ~/catkin_ws
catkin_make
```

在PC上，您还必须运行您选择的GCS来配置四轴飞行器，查看遥测数据，查看MAVLink检查器，设置飞行模式并发出命令。所有这些事情也可以通过ROS消息和服务来完成，但这样可能会更容易。

### 启动所有 ROS 节点[¶](https://ardupilot.org/dev/docs/ros-aruco-detection.html#starting-all-ros-node)

现在要启动系统工作所需的所有节点，请在不同的术语上给出以下命令（或使用 CTRL+SHIFT+T 的选项卡） （在本例中，192.168.10.16 是 PC，192.168.10.10 是四轴飞行器上的树莓派）

选项卡1

```
ssh ubuntu@ubiquityrobot
(login)
ubuntu@ubiquityrobot:~/catkin_ws$ roslaunch aruco_gridboard detection_rpicam.launch
```

选项卡2

```
ssh ubuntu@ubiquityrobot
(login)
ubuntu@ubiquityrobot:~/catkin_ws$ roslaunch mavros apm.launch fcu_url:=/dev/ttyAMA0:921600 gcs_url:=tcp-l://192.168.10.10:2000
```

选项卡3

```
ssh ubuntu@ubiquityrobot
(login)
ubuntu@ubiquityrobot:~/catkin_ws$ rosrun aruco_gridboard set_origin.py (only after receiving EK2 ...)
```

选项卡4

```
andrea@galileo:~/catkin_ws$ rosrun rqt_reconfigure rqt_reconfigure (for setting camera params then exit)
andrea@galileo:~/catkin_ws$ roslaunch mavros_extras teleop.launch
```

选项卡5

```
andrea@galileo:~/catkin_ws$ rosrun rviz rviz -d catkin_ws/src/aruco_gridboard/data/aruco_grid.rviz
```

此时应该可以看到 /mavros/vision\_pose/pose 和 /mavros/local\_position/pose，表示为 3 个轴，在 rviz 上，并将四轴飞行器与相机朝向 Aruco 板，您应该看到两个姿势彼此靠近。将GCS连接到四轴飞行器（tcp 192.168.10.10 2000），应该可以在地图上看到四轴飞行器，设置飞行模式并发出命令。

如果最后一点没问题，则可以在悬停模式下完成第一次测试，将四轴飞行器武装起来，起飞并使用操纵杆悬停在 Aruco 板上，然后降落。

最后一步（目前）是使用随附的脚本之一测试全自主飞行，为此打开另一个术语或选项卡

```
ssh ubuntu@ubiquityrobot
(login)
ubuntu@ubiquityrobot:~/catkin_ws$ rosrun aruco_gridboard mavros_control1.py
```

您应该看到四轴飞行器臂，起飞，沿着广场飞行并降落，如本页开头的视频所示。

### 一些有用的链接[¶](https://ardupilot.org/dev/docs/ros-aruco-detection.html#some-useful-links)

* 博客文章 [使用 ArduCopter、ROS 和 Aruco 板检测的室内自主飞行](https://discuss.ardupilot.org/t/indoor-autonomous-flight-with-arducopter-ros-and-aruco-boards-detection/34699)： 与此处描述的系统类似，但在四轴飞行器上有一个Raspberry Pi 0（而不是Raspberry Pi 3），由于计算资源有限，aruco\_gridboard节点在台式PC上运行，相关数据（主要是图像和姿态估计）使用ROS消息与四轴飞行器交换。
* 博客文章使用[SKYVIPER进行视觉定位实验](https://discuss.ardupilot.org/t/vision-positionning-experiments-using-skyviper/38348)： 这里描述了一个类似于前一个的系统，代替 DIY 四轴飞行器，使用了 Skyviper 一个，因此它应该更容易复制。
