> 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/yong-yu-fei-gps-dao-hang-de-he-ke-tuo-slam.md).

# 用于非 GPS 导航的赫克托 SLAM

## 用于非GPS导航的ROS和Hector SLAM[¶](https://ardupilot.org/dev/docs/ros-slam.html#ros-and-hector-slam-for-non-gps-navigation)

本页介绍如何使用 [RPLidarA2 激光雷达](http://wiki.ros.org/rplidar)设置 ROS 和 [Hector SLAM](http://wiki.ros.org/hector_slam)，为 ArduPilot 提供本地位置估计，以便它可以在没有 GPS 的情况下运行。

这些指令在用[APSync](https://ardupilot.org/dev/docs/apsync-intro.html#apsync-intro)闪存的[NVidia TX2](https://ardupilot.org/dev/docs/companion-computer-nvidia-tx2.html#companion-computer-nvidia-tx2)上进行了测试，然后[按照此处所述安装了](https://ardupilot.org/dev/docs/ros-install.html#ros-install)ROS和MAVROS。

他们还在[RaspberryPi 3 B +](https://ardupilot.org/dev/docs/raspberry-pi-via-mavlink.html#raspberry-pi-via-mavlink)上进行了测试，并安装了ROS和MAVROS，如此[处所述](https://ardupilot.org/dev/docs/ros-install.html#ros-install)。

注意

这些页面正在进行中

### 安装 RPLidar 和 Pixhawk[¶](https://ardupilot.org/dev/docs/ros-slam.html#mounting-the-rplidar-and-pixhawk)

[![../\_images/ros-pixhawk-rplidara2-orientation.png](https://ardupilot.org/dev/_images/ros-pixhawk-rplidara2-orientation.png)](https://ardupilot.org/dev/_images/ros-pixhawk-rplidara2-orientation.png)

RPLidar 的方向应使其 USB 电缆线指向与飞行控制器上的箭头相同的方向。

USB 电缆应插入运行 ROS 的配套计算机上的 USB 端口。

### 检查 RPLidar 的串行端口[¶](https://ardupilot.org/dev/docs/ros-slam.html#check-the-rplidar-s-serial-port)

* 将 RPLidarA2 插入配套计算机。如果使用安装在AUVidea J2板上的TX120，请确保激光雷达已插入较低的USB端口。

```
ls -l /dev/tty*
```

* 激光雷达应显示为 /dev/ttyUSB0 或 /dev/ttyACM0。
* 如果您键入“lsusb”，则设备还应列为“Cygnal Integrated Products， Inc. CP210x UART Bridge / myAVR mySmartUSB 灯”
* 允许任何人通过输入以下两个命令之一从设备读取，具体取决于上面找到的串行端口

```
sudo usermod -a -G dialout $USER
```

### 安装更多软件包[¶](https://ardupilot.org/dev/docs/ros-slam.html#install-more-packages)

* 将 ROS 桌面安装完整：

```
sudo apt-get install ros-kinetic-desktop-full
```

* 或者安装这些单独的软件包中的每一个（此列表尚未完成）：

```
sudo apt-get install ros-kinetic-tf ros-kinetic-tf-conversions ros-kinetic-laser-geometry
sudo apt-get install ros-kinetic-cv-bridge ros-kinetic-image-transport
sudo apt-get install qt4-qmake qt4-dev-tools
sudo apt-get install protobuf-compiler
```

### 创建卡特金工作区[¶](https://ardupilot.org/dev/docs/ros-slam.html#create-a-catkin-workspace)

在您的主目录中：

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

### 安装 RPLidar 节点和 Hector SLAM[¶](https://ardupilot.org/dev/docs/ros-slam.html#install-rplidar-node-and-hector-slam)

在工作区中安装 RPLidar 节点和 Hector SLAM 软件

```
cd $HOME/catkin_ws/src
git clone https://github.com/Slamtec/rplidar_ros.git
git clone https://github.com/tu-darmstadt-ros-pkg/hector_slam.git
```

使用您喜欢的编辑器打开Hector SLAM的启动文件，该文件可以在$HOME/[catkin\_ws/src/hector\_slam/hector\_mapping/launch/mapping\_default.launch](https://github.com/tu-darmstadt-ros-pkg/hector_slam/blob/catkin/hector_mapping/launch/mapping_default.launch)中找到，并修改“base\_frame”，“odom\_frame”并注释掉“tf”行，如下所示：

```
<arg name="base_frame" default="base_link"/>
<arg name="odom_frame" default="base_link"/>

<node pkg="tf" type="static_transform_publisher" name="base_to_laser_broadcaster" args="0 0 0 0 0 0 base_link laser 100" />
```

编辑 Hector SLAM 的 hector\_imu\_attitude\_to\_tf/launch/example.launch 文件，该文件位于 [$HOME/catkin\_ws/src/hector\_slam/hector\_imu\_attitude\_to\_tf/launch/example.launch](https://github.com/tu-darmstadt-ros-pkg/hector_slam/blob/catkin/hector_imu_attitude_to_tf/launch/example.launch)，并通过将“thumper\_imu”替换为“/mavros/imu[/](https://github.com/tu-darmstadt-ros-pkg/hector_slam/blob/catkin/hector_imu_attitude_to_tf/launch/example.launch)data”来更改它以消耗来自飞行控制器的 IMU 数据（通过 mavros），使其如下所示：

```
<remap from="imu_topic" to="/mavros/imu/data" />
```

编辑 Hector SLAM 的 tutorial.launch 文件，该文件位于 [$HOME/catkin\_ws/src/hector\_slam/hector\_slam\_launch/launch/tutorial.launch](https://github.com/tu-darmstadt-ros-pkg/hector_slam/blob/catkin/hector_slam_launch/launch/tutorial.launch)，并将“use\_sim\_time”行更改为如下所示：

```
<param name="/use_sim_time" value="false"/>
```

继续编辑 [tutorial.launch](https://github.com/tu-darmstadt-ros-pkg/hector_slam/blob/catkin/hector_slam_launch/launch/tutorial.launch) 并添加一个新行（就在现有包含行的正下方），以便包含上面修改的 [example.launch](https://github.com/tu-darmstadt-ros-pkg/hector_slam/blob/catkin/hector_imu_attitude_to_tf/launch/example.launch) 文件：

```
<include file="$(find hector_imu_attitude_to_tf)/launch/example.launch"/>
```

默认情况下，一旦启动，Hector SLAM 将弹出一个窗口以实时显示地图，但这可以通过注释掉 [tutorial.launch](https://github.com/tu-darmstadt-ros-pkg/hector_slam/blob/catkin/hector_slam_launch/launch/tutorial.launch) 文件的一行来禁用，使其如下所示：

```
<!--node pkg="rviz" type="rviz" name="rviz"
  args="-d $(find hector_slam_launch)/rviz_cfg/mapping_demo.rviz"/-->
```

### 构建包[¶](https://ardupilot.org/dev/docs/ros-slam.html#build-the-packages)

```
cd $HOME/catkin_ws
catkin build
source devel/setup.bash
```

### 启动赫克托·斯拉姆[¶](https://ardupilot.org/dev/docs/ros-slam.html#start-hector-slam)

将RPLidarA2插入配套计算机，然后打开四个终端，每种终端类型：

```
cd catkin_ws
source devel/setup.bash
```

然后在 1 号航站楼：

```
roscore
```

在 2 号航站楼：

```
roslaunch rplidar_ros rplidar.launch
```

在终端 3 中（对于 RaspberryPi，我们建议在[另一](http://wiki.ros.org/ROS/Tutorials/MultipleMachines)台机器上运行它这里解释）：

```
roslaunch hector_slam_launch tutorial.launch
```

在 4 号航站楼：

按照[与 ROS 连接页面上](https://ardupilot.org/dev/docs/ros-connecting.html#ros-connecting)的说明启动 mavros，其中涉及运行如下命令：

```
roslaunch mavros apm.launch fcu_url:=udp://:14855@
```

### 配置 ArduPilot[¶](https://ardupilot.org/dev/docs/ros-slam.html#configure-ardupilot)

使用地面站（即任务规划器）连接到飞行控制器，并检查是否设置了如下所示的参数：

* [AHRS\_EKF\_TYPE](https://ardupilot.org/copter/docs/parameters.html#ahrs-ekf-type) = 2（默认值）使用 EKF2（在编写此页面时，EKF3 尚不支持外部仓位估计）
* [EK2\_ENABLE](https://ardupilot.org/copter/docs/parameters.html#ek2-enable) = 1（默认值）
* [EK3\_ENABLE](https://ardupilot.org/copter/docs/parameters.html#ek3-enable) = 0（默认值）
* [GPS\_TYPE](https://ardupilot.org/copter/docs/parameters.html#gps-type) = 0 禁用 GPS
* [EK2\_GPS\_TYPE](https://ardupilot.org/copter/docs/parameters.html#ek2-gps-type) = 3 以禁用 EKF 对 GPS 的使用
* [COMPASS\_ENABLE](https://ardupilot.org/copter/docs/parameters.html#compass-enable) = 0，[COMPASS\_USE](https://ardupilot.org/copter/docs/parameters.html#compass-use) = 0，[COMPASS\_USE2](https://ardupilot.org/copter/docs/parameters.html#compass-use2) = 0，[COMPASS\_USE3](https://ardupilot.org/copter/docs/parameters.html#compass-use3) = 0 禁用 EKF 对指南针的使用，而是依赖 ROS 和 Hector SLAM 的航向

更改上述任何值后，重新启动飞行控制器。

如果一切正常，视觉位置估计应该开始从ROS流入ArduPilot。这可以通过使用任务规划器（或类似工具）连接到飞行控制器并检查飞行数据屏幕的消息选项卡（左下角）来确认来自 EKF 的消息，如下所示：

```
EKF2 IMU1 initial pos NED = 0.0,0.0,0.0 (m)
EKF2 IMU1 is using external nav data
EKF2 IMU0 initial pos NED = 0.0,0.0,0.0 (m)
EKF2 IMU0 is using external nav data
```

使用任务规划器（或类似工具）转到“飞行数据”屏幕，右键单击地图，然后选择“在此处设置主页”>>“设置EKF原点”。车辆应立即出现在您单击的地图上。

### 视频[¶](https://ardupilot.org/dev/docs/ros-slam.html#video)

注意

我们热衷于改进ArduPilot对ROS的支持，因此如果您发现问题（例如似乎不支持的命令），请在[ArduPilot问题列表中](https://github.com/ArduPilot/ardupilot/issues)报告它们，标题包含“ROS”，我们将尝试尽快解决这些问题。
