-
ros2安装
(推荐)使用小鱼ROS一键安装,若要自行安装,可参考官网教程Ubuntu (Debian packages) — ROS 2 Documentation: Humble documentationwget http://fishros.com/install -O fishros && . fishros
测试
打开一个终端ros2 run demo_nodes_cpp talker
打开另一个终端
ros2 run demo_nodes_py listener
运行成功会显示hello world的成功发布和订阅
这里需要注意的是,这里安装的gazebo是ros2 humble自带的,可能会与px4版本不兼容,作者就遇到了类似的问题,地面站会出现报错,导致飞机无法起飞,具体解决方案见 offboard程序实例:
[10:14:21.007 ] Critical: Preflight Fail: ekf2 missing data
-
px4安装配置
2.1安装gitsudo apt-get update sudo apt install git
2.2安装PX4并切换版本
git clone https://github.com/PX4/PX4-Autopilot.git mv PX4-Autopilot PX4_Firmware cd PX4_Firmware git checkout v1.14.0 # 切换分支到v1.14.0
2.3更新子模块(为防止安装过程有些包没安装成功):
git submodule update --init --recursive
2.4安装依赖
sudo apt install ros-dev-tools cd ~/PX4_Firmware/Tools/setup chmod +x ubuntu.sh ./ubuntu.sh --no-nuttx --no-sim-tools
2.5编译
cd ~/PX4_Firmware make px4_sitl gz_x500
场景中出现无人机则代表编译成功
2.6运行gazebo
gz sim
作者这里的是garden v7.7.0
如果是其他更高的版本,可能会出现冲突 -
QGC地面站安装配置
3.1安装依赖sudo usermod -a -G dialout $USER sudo apt-get remove modemmanager -y 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-cursor0 -y
3.2 qgc安装
参考官方教程
下载好后打开权限,可以用 ./QGroundControl.AppImage 或者 直接双击 进行使用
cd ~/Downloads/
chmod +x QGroundControl.AppImage
./QGroundControl.AppImage
-
Micro XRCE-DDS Agent安装配置
在 ROS2 中 PX4 使用 uXRCE-DDS 中间件来允许在配套计算机上发布和订阅 uORB 消息,就像它们是 ROS2 话题一样。
4.1下载源代码git clone https://github.com/eProsima/Micro-XRCE-DDS-Agent.git cd Micro-XRCE-DDS-Agent mkdir build cd build cmake .. make
4.2安装
sudo make install sudo ldconfig /usr/local/lib
-
offboard程序实例
6.1创建工作空间mkdir -p ~/ros2_ws/src
6.2下载源码
cd ~/ros2_ws/src git clone https://github.com/PX4/px4_msgs.git -b release/1.14 git clone https://github.com/PX4/px4_ros_com.git -b release/v1.14
6.3编译
cd ~/ros2_ws colcon build
6.4 offboard程序运行流程
1)打开qgc
2)终端1,启动MicroXRCEAgentMicroXRCEAgent udp4 -p 8888
3)终端2,启动gazebo仿真
cd ~/PX4_Firmware make px4_sitl gz_x500
4)终端3,启动官方 offboard 案例
cd ~/ros2_ws/src source install/setup.bash ros2 run px4_ros_com offboard_control
-
遇到的问题
无人机无法起飞,地面站报错:[10:14:21.007 ] Critical: Preflight Fail: ekf2 missing data
参考解决方案:https://github.com/PX4/PX4-Autopilot/issues/24033
解决办法:install the correct version of Gazebo
# install the correct version of Gazebo
sudo apt install gz-garden
# install the correct version of the Gazebo-ROS bridge
sudo apt install ros-humble-ros-gzgarden
# uninstall any incorrect version of Gazebo
sudo apt remove gz-harmonic
sudo apt autoremove
问题解决