基于Gazebo+ROS+PX4+QGC+深度相机实现无人机HITL半实物仿真

场景:Gazebo+ROS+PX4硬件(hitl模式)+QGC+Depth_camera,实现半实物仿真系统搭建

基于以上场景,实现无人机指控、导航、避障算法的仿真平台的搭建
官方硬件在环仿真关系图
PX4、Gazebo、QGC关系

一、连接PX4硬件,设置(hitl,硬件在环仿真模式),测试硬件在环仿真模式

官方参考链接: PX4 HITL SETUP

STEP1:将PX4硬件连接到QGC,设置HIL enabled

STEP2:编译Gazebo-classic上的仿真模块

(1)Build PX4 with Gazebo Classic (in order to build the Gazebo Classic plugins).

cd <Firmware_clone>
DONT_RUN=1 make px4_sitl_default gazebo-classic

(2)设置参数,打开Tools/simulation/gazebo-classic/sitl_gazebo-classic/models/iris_hitl/iris_hitl.sdf).找到文件的 mavlink_interface plugin 分区,将 serialEnabled 和 hil_mode 参数更改为 true。
注意:串口为ttyACM0,可以使用dmesg| grep "tty"进行验证
(3)配置环境变量

source Tools/simulation/gazebo-classic/setup_gazebo.bash $(pwd) $(pwd)/build/px4_sitl_default

(4)启动Gazebo

gazebo Tools/simulation/gazebo-classic/sitl_gazebo-classic/worlds/hitl_iris.world

(5)转发mavlink到其他电脑

mavlink-routerd -e 192.168.100.6:14550 127.0.0.1:14550

最后一个为server,前面为client
以上为PX4+Gazebo半实物仿真系统,还没有添加ROS模块

二、通过ROS启动半实物仿真模型,启动depth_camera话题,启动mavros功能包

STEP1 启动gazebo_ros节点,加载世界模型

cd <PX4-Autopilot_clone>
source Tools/simulation/gazebo-classic/setup_gazebo.bash $(pwd) $(pwd)/build/px4_sitl_default
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:$(pwd)/Tools/simulation/gazebo-classic/sitl_gazebo-classic

roslaunch gazebo_ros empty_world.launch world_name:=$(pwd)/Tools/simulation/gazebo-classic/sitl_gazebo-classic/worlds/empty.world

STEP2 启动无人机模型,iris_hitl_depth_camera,为iris_hitl加装了深度相机的模型,会输出深度和rgb话题

<?xml version="1.0" ?>
<sdf version="1.5">
  <model name='iris_hitl_depth_camera'>
    <include>
      <uri>model://iris_hitl</uri>
    </include>

    <include>
      <uri>model://depth_camera</uri>
      <pose>0.1 0 0 0 0 0</pose>
    </include>
    <joint name="depth_camera_joint" type="revolute">
      <child>depth_camera::link</child>
      <parent>iris::base_link</parent>
      <axis>
        <xyz>0 0 1</xyz>
        <limit>
          <upper>0</upper>
          <lower>0</lower>
        </limit>
      </axis>
    </joint>

  </model>
</sdf>
rosrun gazebo_ros spawn_model -sdf -file $(pwd)/Tools/simulation/gazebo-classic/sitl_gazebo-classic/models/iris/iris_hitl_depth_camera.sdf -model iris -x 0 -y 0 -z 0 -R 0 -P 0 -Y 0

STEP3 开启MAVROS节点,将mavlink消息转发为ROS节点

roslaunch mavros px4.launch fcu_url:="udp://:14540@127.0.0.1:14557"

以上便启动了基于ROS+gazebo+PX4的半实物仿真过程,也可以通过以下launch文件一起启动,不过原始脚本是启动的SITL软件在环仿真,可以修改其iris模型,添加hitl描述,同时不需运行sitl节点

cd <Firmware_clone>
source Tools/setup_gazebo.bash $(pwd) $(pwd)/build/px4_sitl_default
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:$(pwd)
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:$(pwd)/Tools/sitl_gazebo
roslaunch px4 mavros_posix_sitl.launch

以下就是同时启动PX4 HITL+GAZEBO+ROS+RVIZ深度图+QGC的画面,有问题可留言探讨

仿真模型

  • 7
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PX4 Gazebo无人机仿真是一种利用Gazebo仿真软件来模拟现实世界中无人机的行为和环境的方法。通过PX4的源代码,我们可以获得PX4无人机Gazebo模型,通过运行launch文件,我们可以在Gazebo环境中模拟出一个无人机。这种仿真环境可以帮助开发者测试和调试无人机的控制算法和系统。它还可以用于学习ROS系统的基本操作和与无人机进行通讯,如使用MAVROS进行通讯。 在使用PX4 Gazebo无人机仿真的过程中,首先需要打开Gazebo环境,此时会显示一个地面上有一个无人机的场景。然后,我们可以通过使用rostopic echo /mavros/state命令来测试无人机的通讯状态。这个仿真环境可以帮助我们进行无人机的控制和跟踪移动物体等实验。 总结来说,PX4 Gazebo无人机仿真是一种通过Gazebo仿真软件来模拟无人机行为和环境的方法,可以用于测试和调试无人机的控制算法和系统,以及学习ROS系统的基本操作和与无人机进行通讯。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [PX4无人机-Gazebo仿真实现移动物体的跟踪](https://blog.csdn.net/qq_44939973/article/details/120965458)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值