roslaunch XML 格式 官方文檔 翻譯

roslaunch XML

 

目錄

  1. Evaluation order
  2. substitution args
  3. if and unless attributes
    1. Example
  4. Tag Reference
  5. Example .launch XML Config Files
    1. Minimal Example
    2. A More Complicated Example
    3. Setting parameters

 

This page describes the XML format used for roslaunch .launch files. For background on roslaunch, its functionality, and related tools, please consult the roslaunch page first.

本頁介紹roslaunch .launch文件的XML格式。 有關roslaunch的背景知識、功能和相關的工具,請首先查閱roslaunch頁面。

Evaluation order

計算順序

roslaunch evaluates the XML file in a single pass. Includes are processed in depth-first traversal order. Tags are evaluated serially and the last setting wins. Thus, if there are multiple settings of a parameter, the last value specified for the parameter will be used.

roslaunch 會一次性的解析XML文件。 include按深度優先遍歷順序進行處理。 標籤將按順序解析,以最後的設置的值爲準。 因此,如果同一參數被多次設置,則被指定爲最後被設定的值。

Relying on the override behavior can be brittle. There is no guarantee that an override is specified correctly (e.g. if a parameter name is changed in an included file). Instead, it is recommended that override behavior be done using $(arg)/<arg> settings.

依賴覆蓋行爲可能很弱。不能保證覆蓋會被正確執行(例如,如果在包含的文件中更改了參數名)。相反,建議使用$(arg)/<arg>設置完成覆蓋行爲。

譯者注:lannch機制不保證節點的啓動順序,雖然launch文件是順序分析,但節點初始化的時間長度不一,啓動時間不一

 

substitution args  參數替換

Roslaunch tag attributes can make use of substitution args, which roslaunch will resolve prior to launching nodes. The currently supported substitution args are:

Roslaunch標記屬性可以使用substitution args(替換參數),Roslaunch將在啓動節點之前解析這些參數。當前支持的替換參數包括:

  • $(env ENVIRONMENT_VARIABLE)

    $(optenv ENVIRONMENT_VARIABLE) $(optenv ENVIRONMENT_VARIABLE default_value)

    • Substitute the value of a variable from the current environment. The launch will fail if environment variable is not set. This value cannot be overridden by <env> tags.

    • 用當前環境替換變量的值。 如果未設置環境變量,啓動將失敗。 此值不能被<env>標記覆蓋。

    • Substitute the value of an environment variable if it is set. If default_value is provided, it will be used if the environment variable is not set. If default_value is not provided, an empty string will be used. default_value can be multiple words separated by spaces.

    • 替換環境變量的值(如果已設置)。 如果提供default_value,則在未設置環境變量的情況下將使用它。 如果未提供default_value,則將使用空字符串。 default_value可以是多個單詞,用空格分隔。

  • Examples:

    $(find pkg)

    $(anon name)

    $(arg foo)

    $(eval <expression>) New in Kinetic

    $(dirname) New in Lunar

    •   <param name="foo" value="$(optenv NUM_CPUS 1)" />
        <param name="foo" value="$(optenv CONFIG_PATH /home/marvin/ros_workspace)" />
        <param name="foo" value="$(optenv VARIABLE ros rocks)" />
    • e.g. $(find rospy)/manifest.xml. Specifies a package-relative path. The filesystem path to the package directory will be substituted inline. Use of package-relative paths is highly encouraged as hard-coded paths inhibit the portability of the launch configuration. Forward and backwards slashes will be resolved to the local filesystem convention.

    • 如. $(find rospy)/manifest.xml. 指定包的相對路徑。包目錄的文件系統路徑(絕對路徑)會被替換,強烈建議使用包相對路徑,因爲如果硬性的指定其路徑會影響啓動配置的可移植性。正斜槓和反斜槓將解析爲本地文件系統約定的路徑分隔符。

    • e.g. $(anon rviz-1). Generates an anonymous id based on name. name itself is a unique identifier: multiple uses of $(anon foo) will create the same "anonymized" name. This is used for <node> name attributes in order to create nodes with anonymous names, as ROS requires nodes to have unique names. For example:

    • 例如$(anon rviz-1). 根據名稱生成匿名ID。 名稱本身是一個唯一的標識符:$(anon foo)的多次使用將創建相同的“匿名”名稱。 這用於<node>名稱屬性,以便創建帶有匿名名稱的節點,因爲ROS要求節點具有唯一的名稱。 例如:

        <node name="$(anon foo)" pkg="rospy_tutorials" type="talker.py" />
        <node name="$(anon foo)" pkg="rospy_tutorials" type="talker.py" />

      Will generate an error that there are two <node>s with the same name.

         將會產生一個錯誤,指出有兩個同名的<node>。

  • $(arg foo) evaluates to the value specified by an <arg> tag. There must be a corresponding <arg> tag in the same launch file that declares the arg.

  • $(arg foo) 的值等於<arg>標記指定的值。 在聲明<arg>的同一啓動文件中必須有相應的<arg>標記。

      <param name="foo" value="$(arg my_foo)" />
  • Will assign the my_foo argument to the foo parameter.

  • 將my_foo參數分配給foo參數。

  • Another example:
    <node name="add_two_ints_server" pkg="beginner_tutorials" type="add_two_ints_server" />
    <node name="add_two_ints_client" pkg="beginner_tutorials" type="add_two_ints_client" args="$(arg a) $(arg b)" />

    Will launch both the server and client from the <add_two_ints> example, passing as parameters the value a and b. The resulting launch project can be called as follows:

  • 將通過<add_two_ints>示例啓動服務器和客戶端,並傳遞參數a和b作爲參數。 生成的啓動項目可以如下調用:

    roslaunch beginner_tutorials launch_file.launch a:=1 b:=5
  • $(eval <expression>) allows to evaluate arbitrary complex python expressions.

  • $(eval <expression>) 允許任意複雜的python表達式。

  • For example:
    <param name="circumference" value="$(eval 2.* 3.1415 * arg('radius'))"/>
  • Will compute the circumference from the radius argument and assign the result to an appropriate parameter.

  • 將根據radius參數計算周長,並將結果分配給相應的參數。

  • Note: As a limitation, $(eval) expressions need to span the whole attribute string. A mixture of other substitution args with eval within a single string is not possible:

  • 注意:作爲限制,$(eval)表達式需要跨越整個屬性字符串。 在單個字符串中不可能將其他替換args與eval混合使用:

    <param name="foo" value="$(arg foo)$(eval 6*7)bar"/>

    To remedy this limitation, all substitution commands are available as functions within eval as well:

  • 爲了解決此限制,所有替換命令也可以作爲eval中的函數使用:

    "$(eval arg('foo') + env('PATH') + 'bar' + find('pkg')"
  • For your convenience, arguments are also implicitly resolved, i.e. the following two expressions are identical:
  • 爲了方便起見,參數也隱式解析,即以下兩個表達式相同:
  • $(dirname) returns the absolute path to the directory of the launch file in which it appears. This can be used in conjunction with eval and if/unless to modify behaviour based on the installation path,

  • $(dirname)返回launch文件所在目錄的絕對路徑。可以與eval和if /unless結合一起使用,根據此文件的安裝路徑,以執行不同的行爲如:

  • <group if="$(dirname)">
    	<node pkg="pkg_name1" .../>
    </group>
    
    <group unless="$(arg foo)">
    	<node pkg="pkg_name" .../>
    </group>
  • or simply as a convenience for referencing launch or yaml files relative to the current file rather than relative to a package root (as with $(find PKG)).

  • 或者只是爲了方便引用launch或yaml文件(相對於此文件所安裝的路徑,而不是相對於功能包的根目錄的路徑(如$(find PKG)))。

  • For example:
    <include file="$(dirname)/other.launch" />
  • Will expect to find other.launch in the same directory as the launch file which it appears in.

  • 在該launch所在目錄查找其他的luan文件,other.launch

Substitution args are currently resolved on the local machine. In other words, environment variables and ROS package paths will be set to their values in your current environment, even for remotely launched processes.

替代參數當前在本地計算機上解析。 換言之,環境變量和ROS包路徑將設置爲其在當前環境中的值,即使對於遠程啓動的進程也是如此。

 

if and unless attributes

if 和unless 屬性

All tags support if and unless attributes, which include or exclude a tag based on the evaluation of a value. "1" and "true" are considered true values. "0" and "false" are considered false values. Other values will error.

所有標籤都支持if和non屬性,這些屬性根據計算的值,包含或排除標籤。 “ 1”和“ true”被視爲真實值。 “ 0”和“ false”被視爲錯誤值。 其他值將出錯。

  • if=value (optional)

    • If value evaluates to true, include tag and its contents.

    • 如果值計算爲true,則include 這些標籤和這些內容

    unless=value (optional)

    • Unless value evaluates to true (which means if value evaluates to false), include tag and its contents.

    • 除非value的值爲true(這意味着value的值爲false),否則包含標記及其內容。

 

Example

  • <group if="$(arg foo)">
      <!-- stuff that will only be evaluated if foo is true -->
    </group>
    
    <param name="foo" value="bar" unless="$(arg foo)" />  <!-- This param won't be set when "unless" condition is met -->

 

Tag Reference

 

Example .launch XML Config Files

NOTE: by convention, the roslaunch XML files are named with the extension .launch, e.g. example.launch.

注意:按照慣例,roslaunch XML文件的擴展名爲.launch,例如 example.launch。

 

Minimal Example

最簡示例

The following example shows a minimal launch configuration script. It launches a single 'talker' node, which is part of the 'rospy_tutorials' package. This node will launch on the local machine using the currently configured ROS environment (i.e. ROS_ROOT, etc...).

以下示例顯示了最簡啓動配置腳本。 它啓動一個“ talker”節點,該節點是“ rospy_tutorials”軟件包的一部分。 該節點會在本地計算機上啓動(使用當前配置的ROS環境(即ROS_ROOT等))。

 

<launch>
  <node name="talker" pkg="rospy_tutorials" type="talker" />
</launch>

 

A More Complicated Example

一個更復雜的示例

 

<launch>
  <!-- local machine already has a definition by default.
       This tag overrides the default definition with
       specific ROS_ROOT and ROS_PACKAGE_PATH values -->
  <machine name="local_alt" address="localhost" default="true" ros-root="/u/user/ros/ros/" ros-package-path="/u/user/ros/ros-pkg" />
  <!-- a basic listener node -->
  <node name="listener-1" pkg="rospy_tutorials" type="listener" />
  <!-- pass args to the listener node -->
  <node name="listener-2" pkg="rospy_tutorials" type="listener" args="-foo arg2" />
  <!-- a respawn-able listener node -->
  <node name="listener-3" pkg="rospy_tutorials" type="listener" respawn="true" />
  <!-- start listener node in the 'wg1' namespace -->
  <node ns="wg1" name="listener-wg1" pkg="rospy_tutorials" type="listener" respawn="true" />
  <!-- start a group of nodes in the 'wg2' namespace -->
  <group ns="wg2">
    <!-- remap applies to all future statements in this scope. -->
    <remap from="chatter" to="hello"/>
    <node pkg="rospy_tutorials" type="listener" name="listener" args="--test" respawn="true" />
    <node pkg="rospy_tutorials" type="talker" name="talker">
      <!-- set a private parameter for the node -->
      <param name="talker_1_param" value="a value" />
      <!-- nodes can have their own remap args -->
      <remap from="chatter" to="hello-1"/>
      <!-- you can set environment variables for a node -->
      <env name="ENV_EXAMPLE" value="some value" />
    </node>
  </group>
</launch>

 

Setting parameters

設置參數

You can also set parameters on the Parameter Server. These parameters will be stored on the Parameter Server before any nodes are launched.

您也可以在參數服務器上設置參數。 這些參數將在啓動任何節點之前存儲在參數服務器上。

You can omit the type attribute if value is unambiguous. Supported types are str, int, double, bool. You can also specify the contents of a file instead using the textfile or binfile attributes.

如果值是明確的,則可以省略type屬性。 支持的類型爲str,int,double,bool。 您也可以使用textfile或binfile屬性來指定文件的內容。

Example:

 

<launch>
  <param name="somestring1" value="bar" />
  <!-- force to string instead of integer -->
  <param name="somestring2" value="10" type="str" />

  <param name="someinteger1" value="1" type="int" />
  <param name="someinteger2" value="2" />

  <param name="somefloat1" value="3.14159" type="double" />
  <param name="somefloat2" value="3.0" />

  <!-- you can set parameters in child namespaces -->
  <param name="wg/childparam" value="a child namespace parameter" />

  <!-- upload the contents of a file to the server -->
  <param name="configfile" textfile="$(find roslaunch)/example.xml" />
  <!-- upload the contents of a file as base64 binary to the server -->
  <param name="binaryfile" binfile="$(find roslaunch)/example.xml" />

</launch>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章