Ubuntu 24.04 + ROS2 Jazzy + PX4 SITL + MAVROS2 最简安装与启动
2026/7/1 1:33:05 网站建设 项目流程

1. 环境

Ubuntu 24.04 ROS2 Jazzy PX4 SITL Gazebo MAVROS2

PX4 官方 Ubuntu 安装脚本支持 Ubuntu 24.04,并会安装 Gazebo Harmonic 和 PX4 编译工具链。


2. 安装基础依赖

sudo apt update sudo apt install -y git curl wget build-essential cmake ninja-build python3-pip python3-colcon-common-extensions

3. 安装 PX4-Autopilot

cd ~ git clone https://github.com/PX4/PX4-Autopilot.git --recursive

如果子模块没拉完整:

cd ~/PX4-Autopilot git submodule update --init --recursive

安装 PX4 依赖:

cd ~ bash ./PX4-Autopilot/Tools/setup/ubuntu.sh

重启:

sudo reboot

4. 安装 MAVROS2

source /opt/ros/jazzy/setup.bash sudo apt update sudo apt install -y ros-jazzy-mavros ros-jazzy-mavros-extras

安装 GeographicLib 数据:

cd ~ wget https://raw.githubusercontent.com/mavlink/mavros/ros2/mavros/scripts/install_geographiclib_datasets.sh chmod +x install_geographiclib_datasets.sh sudo ./install_geographiclib_datasets.sh

如果下载失败,换这个:

cd ~ wget https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/install_geographiclib_datasets.sh chmod +x install_geographiclib_datasets.sh sudo ./install_geographiclib_datasets.sh

5. 启动 PX4 SITL + Gazebo

终端 1:

cd ~/PX4-Autopilot make px4_sitl gz_x500

6. 启动 MAVROS2

终端 2:

source /opt/ros/jazzy/setup.bash ros2 launch mavros px4.launch fcu_url:=udp://:14540@127.0.0.1:14557

PX4 官方 MAVROS 仿真连接示例使用的也是udp://:14540@127.0.0.1:14557这种连接方式。

如果连不上,可以试:

ros2 launch mavros px4.launch fcu_url:=udp://:14540@

7. 验证 MAVROS 是否连接成功

终端 3:

source /opt/ros/jazzy/setup.bash ros2 topic list | grep mavros

查看连接状态:

ros2 topic echo /mavros/state

如果看到:

connected: true

说明 MAVROS 已经连接 PX4 SITL。

查看无人机本地位姿:

ros2 topic echo /mavros/local_position/pose

查看 IMU:

ros2 topic echo /mavros/imu/data

8. 每次使用的最短启动流程

终端 1:

cd ~/PX4-Autopilot make px4_sitl gz_x500

终端 2:

source /opt/ros/jazzy/setup.bash ros2 launch mavros px4.launch fcu_url:=udp://:14540@127.0.0.1:14557

终端 3:

source /opt/ros/jazzy/setup.bash ros2 topic echo /mavros/state ros2 topic echo /mavros/local_position/pose

9. 常用 MAVROS 话题

/mavros/state /mavros/local_position/pose /mavros/local_position/velocity_local /mavros/local_position/odom /mavros/imu/data /mavros/setpoint_position/local /mavros/setpoint_velocity/cmd_vel /mavros/setpoint_raw/local /mavros/setpoint_raw/attitude

常用服务:

ros2 service list | grep mavros

常见服务:

/mavros/cmd/arming /mavros/set_mode

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询