环境搭建
前置环境
- 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 版本并将文件移至主目录,赋予执行权限:
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/

