赞
踩
官方参考链接: 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模块
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的画面,有问题可留言探讨
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。