PX4(px4 v1.14.0)无人机仿真环境搭建(以Ubuntu 22.04,ROS2 Humble 为例)

  1. ros2安装
    (推荐)使用小鱼ROS一键安装,若要自行安装,可参考官网教程Ubuntu (Debian packages) — ROS 2 Documentation: Humble documentation

    wget 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
    
  2. px4安装配置
    2.1安装git

    sudo 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
    如果是其他更高的版本,可能会出现冲突在这里插入图片描述

  3. 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
  1. 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
    
  2. 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,启动MicroXRCEAgent

    MicroXRCEAgent 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
    
  3. 遇到的问题
    无人机无法起飞,地面站报错:

    [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

问题解决

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值