airsim_ros_pkgs#

AirSim C++客户端库上的ROS封装。

安装#

以下步骤适用于Linux。如果在Windows上运行AirSim,则可以使用Windows Subsystem for Linux(WSL)来运行ROS包装,请参阅 下面 的说明。如果由于某些问题,您无法或不喜欢在主机Linux上安装ROS和相关工具,您也可以使用Docker尝试,请参阅 为 ROS 封装使用 Docker 中的步骤。

  • 如果默认GCC版本不是8或更高版本(使用GCC--version检查)

    • 使用 gcc >= 8.0.0: sudo apt-get install gcc-8 g++-8
    • 使用 gcc-8 --version 验证安装
  • Ubuntu 16.04

    • 安装 ROS kinetic
    • 安装tf2 sensor 和 mavros 包:sudo apt-get install ros-kinetic-tf2-sensor-msgs ros-kinetic-tf2-geometry-msgs ros-kinetic-mavros*
  • Ubuntu 18.04

    • 安装 ROS melodic
    • 安装 tf2 sensor 和 mavros 包: sudo apt-get install ros-melodic-tf2-sensor-msgs ros-melodic-tf2-geometry-msgs ros-melodic-mavros*
  • Ubuntu 20.04

    • 安装 ROS noetic
    • 安装 tf2 sensor 和 mavros 包: sudo apt-get install ros-noetic-tf2-sensor-msgs ros-noetic-tf2-geometry-msgs ros-noetic-mavros*
  • 安装 catkin_tools sudo apt-get install python-catkin-toolspip install catkin_tools。 如果在 Ubuntu 20.04 则使用 pip install "git+https://github.com/catkin/catkin_tools.git#egg=catkin_tools"

构建#

  • 构建 AirSim
git clone https://github.com/OpenHUTB/air.git;
cd air;
./setup.sh;
./build.sh;
  • 确保已按照上面的安装页面中所述设置ROS的环境变量。为方便起见,将source命令添加到.bashrc中(用特定的版本名替换mediatic):
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
  • 构建 ROS 包
cd ros;
catkin build; # 或 catkin_make

如果默认GCC不是8或更高(使用GCC--version检查),则编译将失败。在这种情况下,请显式使用gcc-8,如下所示

catkin build -DCMAKE_C_COMPILER=gcc-8 -DCMAKE_CXX_COMPILER=g++-8

运行#

source devel/setup.bash;
roslaunch airsim_ros_pkgs airsim_node.launch;
roslaunch airsim_ros_pkgs rviz.launch;

注意

如果在运行roslaunch airsim_ros_pkgs airsim_node.launch时出错,请运行catkin clean,然后重试

使用 AirSim ROS 包装器#

ROS包装器由两个ROS节点组成——第一个是AirSim多旋翼 C++ 客户端库的包装器,第二个是简单的 比例-微分(PD) 位置控制器。 让我们看看这 2 个节点的ROS API:

AirSim ROS 包装器节点#

发布者:#

  • /airsim_node/origin_geo_point airsim_ros_pkgs/GPSYaw 与全球 北东地坐标系 (NED) 坐标系对应的 GPS 坐标。此设置位于 airsim 的 settings.json 文件中,OriginGeopoint 键的值即为该坐标。

  • /airsim_node/VEHICLE_NAME/global_gps sensor_msgs/NavSatFix 这是无人机在 Airsim 中的当前 GPS 坐标。

  • /airsim_node/VEHICLE_NAME/odom_local_ned nav_msgs/Odometry 相对于起飞点的 NED 坐标系里程计(默认名称:odom_local_ned,发射名称和坐标系类型可配置)。

  • /airsim_node/VEHICLE_NAME/CAMERA_NAME/IMAGE_TYPE/camera_info sensor_msgs/CameraInfo

  • /airsim_node/VEHICLE_NAME/CAMERA_NAME/IMAGE_TYPE sensor_msgs/Image RGB or float image depending on image type requested in settings.json.

  • /tf tf2_msgs/TFMessage

  • /airsim_node/VEHICLE_NAME/altimeter/SENSOR_NAME airsim_ros_pkgs/Altimeter This the current altimeter reading for altitude, pressure, and QNH

  • /airsim_node/VEHICLE_NAME/imu/SENSOR_NAME sensor_msgs::Imu IMU sensor data

  • /airsim_node/VEHICLE_NAME/magnetometer/SENSOR_NAME sensor_msgs::MagneticField Meausrement of magnetic field vector/compass

  • /airsim_node/VEHICLE_NAME/distance/SENSOR_NAME sensor_msgs::Range Meausrement of distance from an active ranger, such as infrared or IR

  • /airsim_node/VEHICLE_NAME/lidar/SENSOR_NAME sensor_msgs::PointCloud2 LIDAR pointcloud

订阅者:#

服务:#

参数:#

  • /airsim_node/world_frame_id [string] Set in: $(airsim_ros_pkgs)/launch/airsim_node.launch Default: world_ned Set to "world_enu" to switch to ENU frames automatically

  • /airsim_node/odom_frame_id [string] Set in: $(airsim_ros_pkgs)/launch/airsim_node.launch Default: odom_local_ned If you set world_frame_id to "world_enu", the default odom name will instead default to "odom_local_enu"

  • /airsim_node/coordinate_system_enu [boolean] Set in: $(airsim_ros_pkgs)/launch/airsim_node.launch Default: false If you set world_frame_id to "world_enu", this setting will instead default to true

  • /airsim_node/update_airsim_control_every_n_sec [double] Set in: $(airsim_ros_pkgs)/launch/airsim_node.launch Default: 0.01 seconds. Timer callback frequency for updating drone odom and state from airsim, and sending in control commands. The current RPClib interface to unreal engine maxes out at 50 Hz. Timer callbacks in ROS run at maximum rate possible, so it's best to not touch this parameter.

  • /airsim_node/update_airsim_img_response_every_n_sec [double] Set in: $(airsim_ros_pkgs)/launch/airsim_node.launch Default: 0.01 seconds. Timer callback frequency for receiving images from all cameras in airsim. The speed will depend on number of images requested and their resolution. Timer callbacks in ROS run at maximum rate possible, so it's best to not touch this parameter.

  • /airsim_node/publish_clock [double] Set in: $(airsim_ros_pkgs)/launch/airsim_node.launch Default: false Will publish the ros /clock topic if set to true.

简单 PID 位置控制器节点#

参数:#

  • PD 控制器参数:
  • /pd_position_node/kd_x [double], /pd_position_node/kp_y [double], /pd_position_node/kp_z [double], /pd_position_node/kp_yaw [double] Proportional gains

  • /pd_position_node/kd_x [double], /pd_position_node/kd_y [double], /pd_position_node/kd_z [double], /pd_position_node/kd_yaw [double] Derivative gains

  • /pd_position_node/reached_thresh_xyz [double] Threshold euler distance (meters) from current position to setpoint position

  • /pd_position_node/reached_yaw_degrees [double] Threshold yaw distance (degrees) from current position to setpoint position

  • /pd_position_node/update_control_every_n_sec [double] Default: 0.01 seconds

服务:#

  • /airsim_node/VEHICLE_NAME/gps_goal [Request: srv/SetGPSPosition] Target gps position + yaw. In absolute altitude.

  • /airsim_node/VEHICLE_NAME/local_position_goal [Request: srv/SetLocalPosition] Target local position + yaw in global NED frame.

订阅者:#

  • /airsim_node/origin_geo_point airsim_ros_pkgs/GPSYaw Listens to home geo coordinates published by airsim_node.

  • /airsim_node/VEHICLE_NAME/odom_local_ned nav_msgs/Odometry Listens to odometry published by airsim_node

发布者:#

全局参数#

  • Dynamic constraints. These can be changed in dynamic_constraints.launch:

    • /max_vel_horz_abs [double] Maximum horizontal velocity of the drone (meters/second)

    • /max_vel_vert_abs [double] Maximum vertical velocity of the drone (meters/second)

    • /max_yaw_rate_degree [double] Maximum yaw rate (degrees/second)

杂项#

使用 WSL1 或 WSL2 在 Windows10 上设置构架环境#

这些安装说明描述了如何设置“Windows上Ubuntu上的Bash”(又名“Linux的Windows子系统”)。

它涉及在Windows10中启用内置的Windows Linux环境(WSL),安装兼容的Linux OS映像,最后安装构建环境,就像它是一个普通的Linux系统一样。

完成后,您将能够像在本机linux机器中一样构建和运行ros包装器。

WSL1 vs WSL2#

WSL2 是最新版本的 Windows 10 Linux 子系统。它比 WSL1 快很多倍(如果您使用 /home/... 下的原生​​文件系统,而不是 /mnt/... 下的 Windows 挂载文件夹),因此就速度而言,它是构建代码的首选。

安装完成后,您可以根据自己的喜好在 WSL1 或 WSL2 版本之间切换。

WSL 设置步骤#
  1. 请按照 此处 的说明操作。请确认您要使用的 ROS 版本与您要安装的 Ubuntu 版本兼容。

  2. 恭喜,您现在已在 Windows 下拥有一个可运行的 Ubuntu 子系统,您可以前往 Ubuntu 16 / 18 说明 ,然后了解 如何在 Windows 上运行 Airsim 以及在 WSL 上运行 ROS 封装程序

注意

您可以通过在 Windows 上安装 VcXsrv 来运行 XWindows 应用程序(包括 SITL)。要使用它,请从 Windows 开始菜单找到并运行 XLaunch。在第一个弹出窗口中选择多窗口(Multiple Windows),在第二个弹出窗口中选择启动时不启用客户端(Start no client),在第三个弹出窗口中选择仅启动剪贴板不要选择原生 OpenGL(如果无法连接,请选择禁用访问控制(Disable access control))。您需要设置 DISPLAY 变量以指向您的显示器:在 WSL 中,它是 127.0.0.1:0;在 WSL2 中,它是计算机网络端口的 IP 地址,可以使用以下代码进行设置。此外,在 WSL2 中,您可能需要禁用公共网络的防火墙,或者创建一个例外,以便 VcXsrv 可以与 WSL2 通信。

export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0

诀窍

  • 如果你将这行添加到你的 ~/.bashrc 文件中,你就不需要再次运行这个命令了。
  • 对于代码编辑,您可以在 WSL 中安装 VSCode。
  • Windows 10 内置了“Windows Defender”病毒扫描程序。它会显著降低 WSL 的运行速度。禁用它可以大幅提升磁盘性能,但会增加病毒感染的风险,因此请自行承担风险。以下是众多资源/视频之一,向您展示如何禁用它:如何在 Windows 10 上禁用或启用 Windows Defender
WSL 和 Windows 10 之间的文件系统访问#

在 WSL 中,Windows 驱动器位于 /mnt 目录中。例如,要列出您的 (<用户名>) 文档文件夹中的文档:

`ls /mnt/c/'Documents and Settings'/<username>/Documents`
or
`ls /mnt/c/Users/<username>/Documents`

在 Windows 系统中,WSL 发行版的文件位于(在 Windows 资源管理器地址栏中输入):

\\wsl$\<distribution name> 例如 \\wsl$\Ubuntu-18.04

如何在 Windows 上运行 Airsim 以及在 WSL 上运行 ROS 封装程序#

对于 WSL 1,请执行以下操作: export WSL_HOST_IP=127.0.0.1 对于 WSL 2: export WSL_HOST_IP=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}') 现在,就像 在 Linux 运行部分一样 ,执行以下命令:

source devel/setup.bash
roslaunch airsim_ros_pkgs airsim_node.launch output:=screen host:=$WSL_HOST_IP
roslaunch airsim_ros_pkgs rviz.launch

使用 Docker 运行 ROS#

tools 目录中包含一个 Dockerfile 文件。要构建 airsim-ros 镜像,请执行以下操作:

cd tools
docker build -t airsim-ros -f Dockerfile-ROS .

要运行程序,请替换以下 AirSim 文件夹的路径:

docker run --rm -it --net=host -v <your-AirSim-folder-path>:/home/testuser/AirSim airsim-ros:latest bash

上述命令会将 AirSim 目录挂载到容器内的主目录中。您在主机上对源文件所做的任何更改都会在容器内生效,这对于开发和测试非常有用。现在,请按照 构建 步骤编译并运行 ROS 封装程序。