このページは、roslaunchで使われる.launchファイルのXMLのフォーマットについて書かれています。roslaunch、その機能と、関連するツールに関する背景知識を得るには、まずroslaunch をはじめにご覧ください。

評価順序

roslaunchは、XMLファイルを一本道に評価していきます。 インクルードなどを処理するときは深さ優先の順序で横断して処理していきます。タグは、順番に評価されていき、最後の設定が優先されます。したがって、もし複数のパラメータの設定があるときは、もっとも最後のパラメータの値が使用されます。この上書き機能に頼ることはとても危険です。どこにも正しく上書きが正しくできている保障がありません。(例えば、パラメータの名前がインクルードファイルで変更されているときなど。)そのかわり、上書き機能は、$(arg)/<arg>の設定を使うことが推奨されています。

args置換

Roslaunchのタグの属性は、args置換をすることができ、これは、roslaunchがnodeを立ち上げる前に解決されます。現在サポートされているargs置換は以下です。:

  • $(env ENVIRONMENT_VARIABLE)

    • 現在の環境変数の値を置換します。環境変数がセットされなかったときは立ち上げは失敗します。この値は、'<env>'タグによって上書きすることはできません。

    $(optenv ENVIRONMENT_VARIABLE) $(optenv ENVIRONMENT_VARIABLE default_value)

    • もし環境変数がセットされていれば環境変数の値を置換します。もしdefault_valueが与えられれていて、環境変数がセットされていなかったときは、その値が使用されます。default_valueが与えられないなら、空の文字列が使われます。default_valueはスペースで分けられていれば、複数の単語を与えることもできます。

  • 例:
    •   <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)" />

    $(find pkg)

    • 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.

    $(anon name)

    • 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:

        <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.

    $(arg foo)

    • $(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.

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

    • 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:

      roslaunch beginner_tutorials launch_file.launch a:=1 b:=5

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.

if and unless attributes

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=value (optional)

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

    unless=value (optional)

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

Example

  • <group if="$(arg foo)">
      <!-- stuff that will only be evaluated if foo is true -->
    </group>
    <param name="foo" value="bar" unless="$(arg foo)" />

Tag Reference

Deprecated Tags

Deprecated in c-turtle, ignored since diamondback:

Example .launch XML Config Files

NOTE: by convention, the roslaunch XML files are named with the extension .launch, e.g. 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...).

<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.

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>

Wiki: ja/roslaunch/XML (last edited 2013-04-20 07:33:23 by Yuto Inagaki)