环境搭建
前置环境
- 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 (QGC) 是用于监控和操控飞机的桌面软件。安装前需进行系统配置:
# 添加用户到 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 版本并移至主目录。


