launch XML 官方文檔 翻譯

<arg> tag

目錄

  1. <arg> tag
  2. Introduction
  3. Usecase pattern
  4. Attributes
  5. Examples
    1. Passing an argument to an included file
    2. Passing an argument via the command-line

Introduction

The <arg> tag allows you to create more re-usable and configurable launch files by specifying values that are passed via the command-line, passing in via an <include>, or declared for higher-level files. Args are not global. An arg declaration is specific to a single launch file, much like a local parameter in a method. You must explicitly pass arg values to an included file, much like you would in a method call.

<arg>標記允許您創建更多可重用和可配置的啓動文件(通過命令行傳遞的值,通過<include>傳遞的值)。或爲更高級別的文件聲明的值。 Args不是全局的。 arg聲明特定於單個啓動文件,非常類似於方法中的局部參數。 您必須像在方法調用中一樣,將arg值顯式傳遞給包含的文件。

 

Usecase pattern

<arg> can be used in one of three ways:

<arg>可以按三按方式使用

  • <arg name="foo" />

    • Declares the existence of foo. foo must be passed in either as a command-line argument (if top-level) or via <include> passing (if included).

    • 聲明foo,foo必須作爲命令行參數(如果是頂級)或通過<include>傳遞(如果包括)來傳遞。

    <arg name="foo" default="1" />

    • Declares foo with a default value. foo can be overriden by command-line argument (if top-level) or via <include> passing (if included).

    • 使用默認值聲明foo。 foo可以通過命令行參數(如果是頂級)或通過<include>傳遞(如果包括)來覆蓋。

    <arg name="foo" value="bar" />

    • Declares foo with constant value. The value for foo cannot be overridden. This usage enables internal parameterization of a launch file without exposing that parameterization at higher levels.

    • 用常量值聲明foo。 foo的值不能被覆蓋。 這種用法使啓動文件可以進行內部參數化,而無需在更高級別上暴露該參數化。

Attributes

  • name="arg_name"

    • Name of argument.
    • 參數名

    default="default value" (optional)

    • Default value of argument. Cannot be combined with value attribute.

    • 參數的默認值。 不能與value屬性結合使用。

    value="value" (optional)

    • Argument value. Cannot be combined with default attribute.

    • 參數值。 不能與默認屬性結合使用。

    doc="description for this arg" (optional) New in Indigo

    • Description of the argument.
    • 參數聲明

 

Examples

Passing an argument to an included file

向包含的文件傳遞參數

  • my_file.launch:

    <include file="included.launch">
      <!-- all vars that included.launch requires must be set -->
      <arg name="hoge" value="fuga" />
    </include>

    included.launch:

    <launch>
      <!-- declare arg to be passed in -->
      <arg name="hoge" /> 
    
      <!-- read value of arg -->
      <param name="param" value="$(arg hoge)"/>
    </launch>

 

Passing an argument via the command-line

通過命令行傳遞參數

roslaunch uses the same syntax as ROS remapping arguments to specify arg values.

roslaunch使用與ROS重映射參數相同的語法來指定arg值。

  • $ roslaunch my_file.launch hoge:=my_value      (.launch file is available at the current dir)
    $ roslaunch %YOUR_ROS_PKG% my_file.launch hoge:=my_value
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章