环境搭建
前置环境
- ROS2 Humble
- Gazebo Classic (11)
1. 下载 PX4 源码
在 Home 目录下,使用 Git 克隆 PX4 代码仓库并更新所有子模块。
git clone https://github.com/PX4/PX4-Autopilot.git --recursive
注意: 源码包含许多子模块,不建议直接下载 GitHub 主页的 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 (QGC) 是用于监控和操控飞机的桌面软件。安装前需对 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 版本安装包并将文件移至主目录: https://docs.qgroundcontrol.com/master/zh/qgc-user-guide/getting_started/download_and_install.html


