本机环境配置¶
推荐组合¶
本手册按以下组合编写:
- Ubuntu 20.04 LTS
- ROS Noetic
- PX4 Autopilot v1.15.0
- Gazebo Classic
- MAVROS
- Python 3
建议优先使用原生 Ubuntu 或独立 Ubuntu 设备。虚拟机和 WSL 的图形、USB、网络广播与硬件加速配置会因宿主机而异,不在本手册的默认流程内。
1. 安装 ROS Noetic 与 MAVROS¶
先按 ROS Noetic 官方流程安装桌面版环境,再安装平台运行所需的软件包:
sudo apt update
sudo apt install ros-noetic-desktop-full \
ros-noetic-mavros ros-noetic-mavros-extras \
python3-rosdep python3-catkin-tools python3-pip
初始化 rosdep,并安装 GeographicLib 数据集:
sudo rosdep init
rosdep update
sudo /opt/ros/noetic/lib/mavros/install_geographiclib_datasets.sh
将 ROS 环境加入当前用户的 shell:
echo 'source /opt/ros/noetic/setup.bash' >> ~/.bashrc
source ~/.bashrc
如果 rosdep init 提示已经初始化,可直接继续执行 rosdep update。
2. 安装 PX4 v1.15.0¶
以下示例把 PX4 安装到用户主目录:
cd ~
git clone --branch v1.15.0 --recursive https://github.com/PX4/PX4-Autopilot.git
cd PX4-Autopilot
git submodule update --init --recursive
bash Tools/setup/ubuntu.sh --fix-missing
安装脚本结束后重启系统,然后完成一次 SITL 编译:
cd ~/PX4-Autopilot
make px4_sitl gazebo-classic
将 PX4 和 Gazebo Classic 路径加入 ~/.bashrc:
source ~/PX4-Autopilot/Tools/simulation/gazebo-classic/setup_gazebo.bash \
~/PX4-Autopilot ~/PX4-Autopilot/build/px4_sitl_default
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4-Autopilot
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic
保存后重新打开终端,或执行 source ~/.bashrc。
3. 获取 SwiftWing 仿真源码¶
源码仓库的根目录按 Catkin 工作空间的 src 目录组织,因此建议按下面的目录方式克隆:
mkdir -p ~/swiftwing_ws
cd ~/swiftwing_ws
git clone https://github.com/SwiftWing001/swiftwing-simulation.git src
catkin_make
echo 'source ~/swiftwing_ws/devel/setup.bash' >> ~/.bashrc
source ~/swiftwing_ws/devel/setup.bash
安装示例额外使用的 Python 包:
python3 -m pip install --user numpy scipy matplotlib plotly geographiclib pygeodesy
把仓库提供的 PX4 启动文件复制到 PX4 的 ROS launch 目录:
cp ~/swiftwing_ws/src/px4_launch/*.launch ~/PX4-Autopilot/launch/
4. 验证安装¶
新开一个终端并执行:
rospack find uav_controller
rospack find single_demo
rospack find multi_demo
三条命令都应返回 ~/swiftwing_ws/src/ 下的对应目录。随后测试单机 PX4 环境:
roslaunch px4 single_plane.launch
Gazebo 中出现固定翼模型、终端没有持续报错,即可进入快速开始。
常见问题¶
- 找不到 ROS 包:确认当前终端已执行
source ~/swiftwing_ws/devel/setup.bash。 - 找不到
single_plane.launch:重新复制px4_launch/*.launch,并确认rospack find px4指向预期的 PX4 目录。 - Gazebo 无法启动或模型缺失:确认使用 PX4 v1.15.0,并检查 Gazebo Classic 环境变量中的路径。
- Python 模块缺失:使用报错终端中的同一个
python3执行安装命令,避免把依赖装到其他解释器。