<arg> tag
目录
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