- launch文件的重點是:節點(node)元素的集合。
- roslaunch 則是讓所有的節點共享同一個終端。
1.標簽(元素)說明
-
1. group標簽
-
2. node標簽
<group ns="turtlesim1"> //兩個節點分組並以’命名空間(namespace)’標簽來區分 <node pkg="turtlesim" name="sim" type="turtlesim_node"/> //pkg 和 type 它們分別是:程序包名字和可執行文件的名字;ros::init()函數提供的 name 信息將會全面的覆蓋命名信息(launch文件中node標簽里面的name 屬性) </group> <group ns="turtlesim2"> <node pkg="turtlesim" name="sim" type="turtlesim_node"/> </group>
補充:
ros::init(argc,argv,"my_node_name"); 或者 ros::init(argc,argv,"my_node_name",ros::init_options::AnonymousName);
node標簽的拓展屬性:
output = “screen” :將標准輸出信息顯示在終端(console)上 respawn=”true” :監測每一個啟動完成的節點,當它終止時,我們可以要求 roslaunch 重新啟動它. required=”true” :當一個必需的節點終止時,roslaunch會做出響應,終止其他所有的節點並退出它自己。 (不要同時設置required 屬性和 respawn 屬性) launch-prefix = “command-prefix” :依賴終端輸入的節點,比如 turtle_teleop_key 節點,它可能要優先的保留在獨立的終端上:launch-prefix=”xterm -e”(xterm 命令會開一個新的終端窗口。 -e 參數告訴 xterm :執行其命令行剩余部分(rosrun turtlesim turtle_teleop_key))
ns = “namespace” :turtlesim 話題名字(turtle1/cmd_vel、turtle1/color_sensor 和 turtle1/pose )被從全局命名空間移動 到 /sim1 和 /sim2 的單獨命名空間里。
args:傳遞參數到節點. 個人理解,arg參數只在launch文件中合法(相當於局部變量),不直接傳給節點,所以需 要通過node中的args屬性進行傳遞.
-
3. remap標簽
<remap from="original-name" to="new-name" /> //在launch文件中重新命名
如果這個 remap 是 launch 元素的一個child(子類),與 node 元素同一層級, 並在 launch 元素內的最頂層。那么這個 remapping 將會作用於后續所有的節點。
-
include標簽
1. file屬性:添加想要包含的文件的完整路徑 <include file="$(find package-name)/launch-file-name" /> //常用,如下: <include file = "find learning_tutrols"/launch/start_demo.launch" / > //也可以自己制定路徑 <include file = "find learning_tutrols"/start_demo.launch" /> //這樣是不對的,必須把路徑給到文件所在最終目錄 2. ns屬性:讓這個文件里的內容推送到一個命名空間里面: <include file=". . . " ns="namespace" /> 一般我們都會給 include 元素設置一個 ns 屬性。
-
arg標簽:聲明一個參數的存在(每一個argument必須給它分配一個 value(賦值))
1. 給arg賦值:
<arg name="arg-name" default="arg-value" /> <arg name="arg-name" value="arg-value" /> 命令行可以覆蓋default的值,但是不能覆蓋 value 。
在例子launch文件 中,use_sim3 節點的 default 值為 0,所以它可以通過命令行改變值,就像下面這樣:
$ roslaunch agitr triplesim.launch use_sim3:=1
2.獲取argument的數值
$(arg arg-name) //$() 這個符號出現的任何地方,roslaunch命令都將會把它替換成給定argument 的值(value)。
3.argument的繼承 :
argument不能傳遞給 include 元素里包含的子launch文件 使用。 argument 就像是一個局部變量,它不能被包含的launch文件 所 “繼承” 。解決這個問題的方法:在 include 元素中插入 arg 元素作為 include 元素的子類(children)。
在 inchude 標簽內的arguments是給包含 (included) 的launch文件提供的arguments,不是為本launch文件提供的。
<include file="$(find freenect_launch)/launch/freenect.launch"> <!-- Don't publish the camera frames when using with the Turtlebot --> <arg name="publish_tf" value="false" /> <!-- use device registration --> <arg name="depth_registration" value="true" /> <arg name="rgb_processing" value="true" /> <arg name="ir_processing" value="false" /> <arg name="depth_processing" value="false" /> <arg name="depth_registered_processing" value="true" /> <arg name="disparity_processing" value="false" /> <arg name="disparity_registered_processing" value="false" /> <arg name="sw_registered_processing" value="false" /> <arg name="hw_registered_processing" value="true" />
Parameters(參數)在一個運行的ROS系統中是變量(values),它被存儲在parameter服務器中。活動(或者叫:運行)的節點通過ros::param::get()函數訪問它,並且用戶可以通過 rosparam 命令行工具使用它。
相比之下,arguments只有在launch文件里合法,它們的值不是直接提供給節點。
2.parameter說明
1.group標簽中的param標簽的作用等同於rosparam set命令.
2.node標簽中的param標簽設置為該節點的子元素.
3.在launch文件中也支持等同與rosparam load 功能的rosparam標簽,用於一次性加載大量的參數
4.在launch文件中設置parameter,使用param標簽:
<param name="param-name" value="param-value" />
5.在C++文件中,set或者get處理parameter參數
ros::param::set(” background_r ” , 255 ) ; boolok = ros::param::get (PARAM_NAME, maxVel ) ;
參考:https://blog.csdn.net/qq_33444963/article/details/77893881