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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM