launch文件

launch
在ROS应用中,每个节点通常有许多参数需要设置,为了方便高效操作多个节点,可以编写launch文件,然后用roslaunch命令运行
roslaunch: roslaunch [options] [package] <filename> [arg_name:=value...]
                    roslaunch [options] <filename> [<filename>...] [arg_name:=value...]
launch文件的一般格式,参数:
<launch>
    <node .../>
    <rosparam ..../>
    <param .../>
    <include .../>
    <env .../>
    <remap .../>
    <arg.../>
</launch>

 

参数说明
<node >要启动的node参数
    pkg=''mypackage''
    type=''nodetype''
    name=''nodename''
    arg=''arg1 ....''(可选)
    respawn=''ture''(可选)如果节点停止,自动重启节点
    ns=''foo''(可选)在foo命名空间启动节点
    output=''log|screen''(可选)
<rosparam>操作yaml文件参数
    command=''load|dump|delete''(默认load)
    file=''$(find pkg-name)/path/foo.yaml''(load或dump命令)yaml文件的名字
    param=''param-name''参数名
<param>定义一个设置在参数服务器的参数,它可以添加到<node>中
    name=''namespace/name''
    value=''value''(可选)如果省略这个参数,则应指定一个文件(binfile/textfile)或命令
    type=''str|int|double|boot''(可选)指定参数的类型
    textfile=''$(find pkg-name)/path/file''(可选)   

    binfile=''$(find pkg-name)/path/file''()
    command=''(find pkg-name)/exe '$(find pkg-name)/arg.txt' ''(可选)exe是可执行文件(cpp、py),arg.txt是参        数文件
<include>在当前launch文件中调用另一个launch文件
    file=''$(find pkg-name)/path/launch-file.launch''    
<env>设置节点的环境变量
    name=''environment-variable-name''
    value=''environment-variable-value''    
<remap>将一个参数名映射为另一个名字
    from=''original-name''
    to=''new-name''    
<arg>定义一个局部参数,该参数只能在一个launch文件中使用
    <arg name=''foo''/>声明一个参数foo,后面需要给它赋值
    <arg name=''foo'' default=''1''/>声明一个参数foo,如不赋值取默认值
    <arg name=''foo'' value=''bar''/>声明一常量foo,它的值不能修改

首先新建一个测试功能包

catkin_create_pkg turtlesim_launch roscpp rospy

新建一个launch文件

vi turtlesim_launch.launch
<launch>
<node pkg="turtlesim" type="turtlesim_node" name="turtlesim_node" respawn="true" output="screen"/>

<node pkg="turtlesim" type = "turtle_teleop_key" name="turtle_teleop_key"
respawn="false" output="screen"/>


</launch>
roslaunch turtlesim_launch.launch 

j简单的键盘控制小乌龟

 

利用<include>在当前launch文件中调用另一个launch文件
    file=''$(find pkg-name)/path/launch-file.launch''   

运行子launch文件

  turtlesim_launch.launch

<launch>

<include  file="$(find turtlesim_launch)/teleop.launch"/>
<node pkg="turtlesim" type="turtlesim_node" name="turtlesim_node" respawn="true" output="screen"/>

<param name="turte" value = "1"/>
<rosparam command="dump" file="$(find turtlesim_launch)/color.yaml"/>
<arg name="foo" value="2"/>
</launch>

  vi teleop.launch

<launch>

<node pkg="turtlesim" type = "turtle_teleop_key" name="turtle_teleop_key"
respawn="false" output="screen"/>


</launch>

 

posted @ 2016-10-09 21:14  CAM&  阅读(4908)  评论(0编辑  收藏  举报