环境搭建
前置环境
- ROS2 humble
- Gazebo Classic (11)
1. 下载 PX4 源码
在 Home 目录下,使用 Git 克隆 PX4 代码仓库并更新子模块。
git clone https://github.com/PX4/PX4-Autopilot.git --recursive
注意:源码包含许多子模块,不建议直接下载 ZIP 包解压,以免缺失模块。建议使用网络加速工具以提高克隆速度。
2. 运行自动安装脚本
PX4 提供自动化脚本安装编译仿真环境依赖。
cd PX4-Autopilot
bash ./Tools/setup/ubuntu.sh
若仅需仿真且无需编译固件,可添加参数跳过编译环境安装以节省时间。
cd PX4-Autopilot
bash ./Tools/setup/ubuntu.sh --no-nuttx
3. 编译并运行示例
在 PX4-Autopilot 目录下执行:
make px4_sitl gazebo-classic_iris
首次编译耗时较长属正常现象。成功后将弹出 Gazebo 窗口并显示黑色无人机模型。
4. 安装并配置 QGC(地面站)
QGroundControl 用于地面监控和操控。需先配置 Ubuntu 系统以确保通信正常。
# 将用户添加到 dialout 组以便访问 USB 设备
sudo usermod -aG dialout "$(id -un)"
# 移除 ModemManager,防止干扰串口通信
sudo apt-get remove modemmanager -y
# 安装 GStreamer 相关库及依赖
sudo apt install gstreamer1.0-plugins-bad gstreamer1.0-libav gstreamer1.0-gl -y
sudo apt install libfuse2 -y
sudo apt install libxcb-xinerama0 libxkbcommon-x11-0 libxcb-cursor-dev -y
从官网下载 Linux 版本并移至主目录。赋予 AppImage 文件执行权限:
chmod +x ./QGroundControl-x86_64.AppImage
5. 安装 Micro-XRCE-DDS-Agent
作为 ROS2 与 PX4 的通信桥梁。
# 安装依赖
sudo apt install -y ros-humble-ros-base ros-humble-geometry-msgs ros-humble-sensor-msgs
# 编译 Micro-XRCE-DDS-Agent
~
git https://github.com/eProsima/Micro-XRCE-DDS-Agent.git
Micro-XRCE-DDS-Agent
build && build
cmake ..
make
make install
ldconfig /usr/local/lib/

