前言
本教程基于 ROS2,在搭建之前,需要把 ROS2、QGC 等基础环境安装配置完成。本次安装是以 px4 v1.14.0 为例,不适用之前的 px4 版本。
1. 准备
1.1 下载 PX4 源码
方式一:从 Github 上下载
sudo apt install git
git clone https://github.com/PX4/PX4-Autopilot.git # 下载源码
mv PX4-Autopilot PX4_Firmware # 更改目录名
cd PX4_Firmware
git checkout v1.14.0 # 切换版本
git submodule update --init --recursive # 更新下载子模块
方式二:从网盘或资源包下载
下载后解压,然后执行下面命令:
cd PX4_Firmware
wget https://gitee.com/tyx6/mytools/raw/main/px4/set_executable.sh
chmod +x set_executable.sh
./set_executable.sh
1.2 安装仿真依赖
sudo apt install ros-dev-tools
cd ~/PX4_Firmware/Tools/setup
chmod +x ubuntu.sh
./ubuntu.sh --no-nuttx --no-sim-tools
注:脚本执行时间跟个人网络有关,可能需要一段时间。安装完成后,重启 Ubuntu。
1.3 安装 Gazebo
Gazebo 是一款强大的 3D 仿真软件,主要用于机器人学的研究和开发。Ubuntu 22.04 及以后的版本支持 Gazebo (原 Gazebo Ignition)。
cd ~/PX4_Firmware/Tools/setup
./ubuntu.sh --no-nuttx # 这一步会安装仿真环境依赖,包括 gazebo
运行一下 gazebo:
gz sim
成功后再重启 Ubuntu。
2. 安装 Micro XRCE-DDS Agent
在 ROS2 中 PX4 使用 uXRCE-DDS 中间件来允许在配套计算机上发布和订阅 uORB 消息。这提供了 PX4 和 ROS2 之间快速可靠的集成。
- 下载源码:
git clone -b v2.4.2 https://github.com/eProsima/Micro-XRCE-DDS-Agent.git
- 编译:
Micro-XRCE-DDS-Agent
build
build
cmake ..
make


