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