PX4-mavros之Roslaunch使用 及流程介绍

  1. 首先在Ros工程目录src下,创建新的功能包。使用命令
 catkin_create_pkg px4_launch

注意此处不需要添加任何依赖了。然后建立一个launch文件夹,如下图所示PX4-mavros之Roslaunch使用 及流程介绍_第1张图片
2. 改写launch文件即可,如下面所示。

<launch>
    <arg name="world_path" default="$(find simulation)/worlds/empty.world" />
    <arg name="gui" default="true"/>
    <arg name="ns" default="/"/>
    <arg name="model" default="iris_irlock_camera"/>
    <arg name="fcu_url" default="udp://:14540@localhost:14557"/>
    <arg name="gcs_url" default="" />   <!-- GCS link is provided by SITL -->
    <arg name="tgt_system" default="1" />
    <arg name="tgt_component" default="1" />
    <arg name="vehicle" default="iris"/>

    <param name="use_sim_time" value="true" />


    <!-- Launch PX4 SITL -->
    <include file="$(find px4)/launch/px4.launch">
        <arg name="vehicle" value="$(arg vehicle)"/>
    </include>

    <!-- Launch MavROS -->
    <include file="$(find mavros)/launch/px4.launch">   
         <!-- Need to change the config file to get the tf topic and get local position in terms of local origin -->
         <arg name="fcu_url" value="$(arg fcu_url)" />
    </include>

    <!-- Launch Gazebo -->
    <include file="$(find gazebo_ros)/launch/empty_world.launch">
        <arg name="gui" value="$(arg gui)"/>
        <arg name="world_name" value="$(arg world_path)" />
    </include>

    <!-- Spawn vehicle model -->
    <node name="spawn_model" pkg="gazebo_ros" type="spawn_model" output="screen"
          args="-sdf -database $(arg model) -model $(arg vehicle)">
    </node>

    <node name="ros_study_offnode" pkg="px4_simu" type="px4_simu_node" output="screen">
    </node>

</launch>

其中以 include开头的表示添加头文件, node name开头的表示添加节点(注:pkg为功能包名称,type为节点可执行文件名字)
可以看出在最后添加了,ros_study_offnode节点。
同时可以看出在mavros里面添加了对应的mavros启动参数。
注意:1. launch文件的写法标准参看古月居。
2. launch启动文件的模板也可以在Firmware/launch中找到,如下图所示。
PX4-mavros之Roslaunch使用 及流程介绍_第2张图片
3. 遇到的问题: 一定要检查环境变量是否正确。官网给出为

 cd <Firmware_clone>
DONT_RUN=1 make px4_sitl_default gazebo
source ~/catkin_ws/devel/setup.bash    # (optional)
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 posix_sitl.launch

其中 export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:$(pwd)

export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:$(pwd)/Tools/sitl_gazebo

即为添加的环境变量,否则无法找到 Launch PX4 SITL 中的 find px4 这里给出修改后的bash文件
在这里插入图片描述

source /opt/ros/melodic/setup.bash

source /home/chasing/project/some/devel/setup.bash
export GAZEBO_MODEL_PATH=:/home/chasing/project/some/src/simulation/models:~/gazebo_models
source /home/chasing/project/some/Firmware/Tools/setup_gazebo.bash $/home/chasing/project/some/Firmware /home/chasing/project/some/Firmware/build/px4_sitl_default
source ~/catkin_ws/devel/setup.bash
source /home/chasing/project/Ros_study/devel/setup.bash

export ROS_PACKAGE_PATH=/home/chasing/project/Ros_study/src:/home/chasing/catkin_ws/src/mavlink:/home/chasing/catkin_ws/src/mavros/libmavconn:/home/chasing/catkin_ws/src/mavros/mavros_msgs:/home/chasing/catkin_ws/src/mavros/mavros:/home/chasing/catkin_ws/src/mavros/mavros_extras:/home/chasing/catkin_ws/src/mavros/test_mavros:/home/chasing/project/some/src:/opt/ros/melodic/share:/home/chasing/project/some/Firmware:/home/chasing/project/some/Firmware/Tools/sitl_gazebo

最后就可以在任意一个终端位置下打开launch文件了,本实验中为

roslaunch px4_launch px_mavros_study.launch 

PX4-mavros之Roslaunch使用 及流程介绍_第3张图片
最后附上仿真图
注:以上图片均采用linux下shift+printscreen截图,保存在picture文件夹下。

你可能感兴趣的:(PX4学习,个人总结)