美文网首页ROS
ROS进阶学习(三) - 对大型项目的roslaunch的建议

ROS进阶学习(三) - 对大型项目的roslaunch的建议

作者: Savior2016 | 来源:发表于2017-03-13 17:30 被阅读1233次

    这个教程就是为大型项目设计roslaunch文件的一些建议,使设计出来的文件能够适用于更多的场景

    1 介绍

    一个大的应用一半有很多互相连接的node,每一个都有很多参数。
    一个roslaunch 文件,将会把所有能够让机器人正常运行的东西启动,我们将会浏览一个launch文件。

    2 顶级结构(Top-level organization)

    这里是顶级启动文件(在 "rospack find 2dnav_pr2/move_base/2dnav_pr2.launch")

    <launch>
      <group name="wg">
        <include file="$(find pr2_alpha)/$(env ROBOT).machine" />
        <include file="$(find 2dnav_pr2)/config/new_amcl_node.xml" />
        <include file="$(find 2dnav_pr2)/config/base_odom_teleop.xml" />
        <include file="$(find 2dnav_pr2)/config/lasers_and_filters.xml" />
        <include file="$(find 2dnav_pr2)/config/map_server.xml" />
        <include file="$(find 2dnav_pr2)/config/ground_plane.xml" />
    
        <!-- The navigation stack and associated parameters -->
        <include file="$(find 2dnav_pr2)/move_base/move_base.xml" />
      </group>
    </launch>
    

    这个文件包含一组其他文件设置。每个 included files 包含了和系统某个部分有关的node和参数。比如位置,传感器进程和路径规划。
    设计建议:Top-level启动文件应该尽量短小一些,并且包含其他程序的子组件,通常会改变ROS参数
    这使它很容易交换系统的一部分,我们只会将会看到。

    3 机器标签和环境变量

    我们希望能控制哪些node在哪些机器上运行,这是为了负载平衡和带宽管理。为了重用性,我们不希望硬编码机器名字出现在roslaunch文件里。
    第一个include是:
    <include file="$(find pr2_alpha)/$(env ROBOT).machine" />
    这个文件所做的第一件事中用env代替了环境变量ROBOT。例如,如果:
    export ROBOT=pre
    那么,launch文件会使pre.machine文件被包含。
    设计建议,使用env代替可以允许启动文件的一部分根据环境变量的不同而不同
    接下来,我们来看一个machine文件(pre.machine in the pr2_alpha package):

    <launch>
      <machine name="c1" address="pre1" ros-root="$(env ROS_ROOT)" ros-package-path="$(env ROS_PACKAGE_PATH)" default="true" />
      <machine name="c2" address="pre2" ros-root="$(env ROS_ROOT)" ros-package-path="$(env ROS_PACKAGE_PATH)" />
    </launch>
    

    这个文件设置了一个逻辑机名称,如C1,C2和真实机主,如pre2,的映射关系。它甚至可以允许控制你登陆的用户。
    一旦映射关系建立,他就可以在node启动时被使用。例如,在包含的文件config/new_amcl_node.xml 中包含了这样一句:
    <node pkg="amcl" type="amcl" name="amcl" machine="c1">

    4 参数、命名空间和YAML文件

    我们看一下move_base.xml文件的一部分:

    <node pkg="move_base" type="move_base" name="move_base" machine="c2">
      <remap from="odom" to="pr2_base_odometry/odom" />
      <param name="controller_frequency" value="10.0" />
      <param name="footprint_padding" value="0.015" />
      <param name="controller_patience" value="15.0" />
      <param name="clearing_radius" value="0.59" />
      <rosparam file="$(find 2dnav_pr2)/config/costmap_common_params.yaml" command="load" ns="global_costmap" />
      <rosparam file="$(find 2dnav_pr2)/config/costmap_common_params.yaml" command="load" ns="local_costmap" />
      <rosparam file="$(find 2dnav_pr2)/move_base/local_costmap_params.yaml" command="load" />
      <rosparam file="$(find 2dnav_pr2)/move_base/global_costmap_params.yaml" command="load" />
      <rosparam file="$(find 2dnav_pr2)/move_base/navfn_params.yaml" command="load" />
      <rosparam file="$(find 2dnav_pr2)/move_base/base_local_planner_params.yaml" command="load" />
    </node>
    

    这部分启动文件负责启动move_base node。首先被包含的是一个映射(remap)。Move_base被设计接收topic“odom”发送回来的路程数据。我们做了一个 pr2_base_odometry 到odom的映射。
    后面的<param>在<node>标签内部,表示是私有参数。
    再后面的<rosparam>是从yaml文件里读取参数,yaml文件是一种可以让人阅读的文件,并且允许包含复杂的数据类型。
    下面是costmap_common_params.yaml 文件的一部分:

    raytrace_range: 3.0
    footprint: [[-0.325, -0.325], [-0.325, 0.325], [0.325, 0.325], [0.46, 0.0], [0.325, -0.325]]
    inflation_radius: 0.55
    
    # BEGIN VOXEL STUFF
    observation_sources: base_scan_marking base_scan tilt_scan ground_object_cloud
    
    base_scan_marking: {sensor_frame: base_laser, topic: /base_scan_marking, data_type: PointCloud, expected_update_rate: 0.2,
      observation_persistence: 0.0, marking: true, clearing: false, min_obstacle_height: 0.08, max_obstacle_height: 2.0}
    

    上面的ns即为namespace。
    没有标注ns的即包含在当前命名空间。

    5 再利用已有的启动文件

    首先来看一个启动文件,它换在Gazebo上运行,只需要改变map_server node。

    <launch>
      <include file="$(find pr2_alpha)/sim.machine" />
      <include file="$(find 2dnav_pr2)/config/new_amcl_node.xml" />
      <include file="$(find 2dnav_pr2)/config/base_odom_teleop.xml" />
      <include file="$(find 2dnav_pr2)/config/lasers_and_filters.xml" />
      <node name="map_server" pkg="map_server" type="map_server" args="$(find gazebo_worlds)/Media/materials/textures/map3.png 0.1" respawn="true" machine="c1" />
      <include file="$(find 2dnav_pr2)/config/ground_plane.xml" />
      <!-- The naviagtion stack and associated parameters -->
      <include file="$(find 2dnav_pr2)/move_base/move_base.xml" />
    </launch>
    

    第一个不同就是,因为我们知道我们在仿真,所以只需要用sim.machine文件而不是一个替代参数,第二,这一行:
    <include file="$(find 2dnav_pr2)/config/map_server.xml" />
    被替换为

    <node name="map_server" pkg="map_server" type="map_server" args="$(find gazebo_worlds)/Media/materials/textures/map3.png 0.1" respawn="true" machine="c1" />
    

    包含的文件在第一种情况下只包含了一个node,而第二种情况则包含了一个映射文件。

    6 参数覆盖

    上面的技巧有时候会很不方便使用。假设我们想要使用2dnav_pr2,只改变本地分辨率参数到0.5.我们可以直接改变local_costmap_params.yaml。这是最简单的临时修改,但是这意味着我们没办法检查修改后的文件,把它返回去。我们可以复制一个文件然后修改它。然后改变move_base.xml去包含它,然后把2dnav_pr2.launch 改变为修改后的move_base.xml,这样做的好处是,如果我们使用了版本控制器,我们就不会发生源文件改变的错误了。
    还有一个方法没看懂,自己去官网看吧,说另一个:
    我们可以使用roslaunch的重写行为,参数是按照顺序设置的。这样,我们可以用后面的的top-level文件重写源文件:

    <launch>
    <include file="$(find 2dnav_pr2)/move_base/2dnav_pr2.launch" />
    <param name="move_base/local_costmap/resolution" value="0.5"/>
    </launch>
    

    这个方法的硬伤是,他会让程序难以理解,想要知道一个东西确切的值,还需要遍历整个启动文件,十分蛋疼。

    7ROSlaunch 参数

    roslaunch XML documentation
    这是一个比起来重写更加常用和清晰的改变东西的方法。一般首选这个。
    看到这里看的累死了,教程的语言越来越超出了我的英语能力范围,我要学点别的换换脑子。

    相关文章

      网友评论

        本文标题:ROS进阶学习(三) - 对大型项目的roslaunch的建议

        本文链接:https://www.haomeiwen.com/subject/xmzfnttx.html