ros源码分析(8)—roslaunch .launch文件中的tag

在roslaunch的.launch xml文件中,包含很多的tag,下面是每个tag使用的介绍。

<launch>tag

the <launch> tag is the root element of any roslaunch file. Its sole purpose is to act as a container for the other elements.

①Attributes

deprecated="deprecation message"
ROS 1.1: warn users that roslaunch file is deprecated.

②Elements

<node>
    #Launch a node.
<param>
    #Set a parameter on the Parameter Server
<remap>
    #Declare a name remapping.
<machine>
    #Declare a machine to use for launching.
<rosparam>
    #Set ROS parameters for the launch using a rosparam file.
<include>
    #Include other roslaunch files.
<env>
    #Specify an environment variable for launched nodes.
<test>
    #Launch a test node (see rostest).
<arg>
    #Declare an argument.
<group>
    #Group enclosed elements sharing a namespace or remap.

<node> tag

The <node> tag specifies a ROS node that you wish to have launched. This is the most common roslaunch tag as it supports the most important features: bringing up and taking down nodes.

roslaunch does not provide any guarantees about what order nodes start in. This is intentional: there is no way to externally know when a node is fully initialized, so all code that is launched must be robust to launching in any order.

例子,

<node name="listener1" pkg="rospy_tutorials" type="listener.py" args="--test" respawn="true" />

Launches the “listener1” node using the listener.py executable from the rospy_tutorials package with the command-line argument –test. If the node dies, it will automatically be respawned.

<node name="bar1" pkg="foo_pkg" type="bar" args="$(find baz_pkg)/resources/map.pgm" />

Launches the bar node from the foo_pkg package. This example uses substitution arguments to pass in a portable reference to baz_pkg/resources/map.pgm.

①Attributes

pkg="mypackage"
    #Package of node.
type="nodetype"
    #Node type. There must be a corresponding executable with the same name.
name="nodename"
    #Node name. NOTE: name cannot contain a namespace. Use the ns attribute instead.
args="arg1 arg2 arg3"(optional)
    #Pass arguments to node.
machine="machine-name"(optional, see <machine>)
    #Launch node on designated machine.
respawn="true"(optional)
    #Restart the node automatically if it quits.
respawn_delay="30" (optional, default 0) New in ROS indigo
    #If respawn is true, wait respawn_delay seconds after the node failure is detected
     before attempting restart.
required="true"(optional)
    #ROS 0.10: If node dies, kill entire roslaunch.
ns="foo"(optional)
    #Start the node in the 'foo' namespace.
clear_params="true|false"(optional)
    #Delete all parameters in the node's private namespace before launch.
output="log|screen"(optional)
    #If 'screen', stdout/stderr from the node will be sent to the screen. If 'log', the
     stdout/stderr output will be sent to a log file in $ROS_HOME/log, and stderr will
      continue to be sent to screen. The default is 'log'.
cwd="ROS_HOME|node"(optional)
    #If 'node', the working directory of the node will be set to the same directory as 
    the node's executable. In C Turtle, the default is 'ROS_HOME'. In Box Turtle (ROS 
     1.0.x), the default is 'ros-root'. The use of 'ros-root' is deprecated in C Turtle.
launch-prefix="prefix arguments"(optional)
    #Command/arguments to prepend to node's launch arguments. This is a powerful feature
     that enables you to enable gdb, valgrind, xterm, nice, or other handy tools. See 
      Roslaunch Nodes in Valgrind or GDB for examples.

②Elements

You can use the following XML tags inside of a <node> tag:

<env>
    #Set an environment variable for the node.
<remap>
    #Set a remapping argument for this node.
<rosparam>
    #Load a rosparam file into this node's ~/local namespace.
<param>
    #Set a parameter in the node's ~/local namespace.

<machine> tag

The <machine> tag declares a machine that you can run ROS nodes on. You do not need this tag if you are launching all the nodes locally. It is mainly used to declare SSH and ROS environment variable settings for remote machines, though you can also use it to declare information about the local machine.

①Attributes

name="machine-name"
    #Name to assign to machine. This corresponds to the name used for the machine 
     attribute for <node> tags.
address="blah.willowgarage.com"
    #Network address/hostname of machine.
env-loader="/opt/ros/fuerte/env.sh" New in Fuerte
    #Specify environment file on remote machine. Environment file must be a shell script 
     that sets all required environment variables, then runs exec on the provided 
      arguments. For an example file, see the env.sh that is provided with debian 
       installs of ROS Fuerte. See below for an example env-loader.
default="true|false|never" (optional)
    #Sets this machine as the default to assign nodes to. The default setting only 
     applies to nodes defined later in the same scope. NOTE: if there are no default 
     machines, the local machine is used. You can prevent a machine from being chosen by 
     setting default="never", in which case the machine can only be explicitly assigned.
user="username" (optional)
    #SSH user name for logging into machine. May be omitted if not required.
password="passwhat"(strongly discouraged)
    #SSH password. It is highly recommended that you configure SSH keys and SSH agent 
    instead so you can login with certificates instead.
timeout="10.0" (optional)
    #Number of seconds before a roslaunch on this machine is considered as having failed 
    to launch. By default, this is 10 seconds. While you can use this setting to allow 
    for slower connections, needing to change this parameter is generally a symptom that 
    your overall ROS graph will have communication issues.

The following attributes are available in ROS Electric and earlier:

ros-root="/path/to/ros/root/" (optional)
    #ROS_ROOT for machine. Defaults to the ROS_ROOT set in the local environment.
ros-package-path="/path1:/path2" (optional)
    #ROS_PACKAGE_PATH for machine. Defaults to the ROS_PACKAGE_PATH set in the local environment.

②Elements

Electric and earlier only: You can use the following XML tags inside of a <machine>tag:

<env>
    #Set an environment variable on all processes launched on this machine.

例子,

The syntax of the <machine> tag is very different in ROS Electric, so please pay attention to the version indicator in the examples below.

Basic (ROS Electric and Previous Only)
The following example below shows configuring a node “footalker” to run another machine. In addition to overriding the ROS_ROOT and ROS_PACKAGE_PATH that the machine will use, the example also sets a LUCKY_NUMBER environment variable on the remote machine.

<launch>
  <machine name="foo" address="foo-address" ros-root="/u/user/ros/ros/" ros-package-path="/u/user/ros/ros-pkg" user="someone">
    <env name="LUCKY_NUMBER" value="13" />
  </machine>

  <node machine="foo" name="footalker" pkg="test_ros" type="talker.py" />

</launch>

Basic (ROS Fuerte and later) using env-loader

he following example below shows configuring a node “footalker” to run another machine. It uses the default env-loader file that comes with Fuerte.

<launch>
  <machine name="foo" address="foo-address" env-loader="/opt/ros/fuerte/env.sh" user="someone"/>

  <node machine="foo" name="footalker" pkg="test_ros" type="talker.py" />

</launch>

Here is an example env-loader script. Replace /opt/ros/fuerte/setup.sh with a different setup file if you wish to use a different environment configuration:

#!/bin/sh

. /opt/ros/fuerte/setup.sh
exec "$@"

Alternatively, if you prefer to source from a rosws workspace:

#!/usr/bin/env bash

source /home/username/path/to/workspace/setup.bash
exec "$@"

<include> tag

The <include> tag enables you to import another roslaunch XML file into the current file. It will be imported within the current scope of your document, including <group> and <remap> tags. All content in the include file will be imported except for the <master> tag: the <master> tag is only obeyed in the top-level file.

①Attributes

file="$(find pkg-name)/path/filename.xml"
    #Name of file to include.
ns="foo" (optional)
    #Import the file relative to the 'foo' namespace.
clear_params="true|false" (optional Default: false)
    #Delete all parameters in the <include>'s namespace before launch. This feature is 
    very dangerous and should be used with caution. ns must be specified. Default: 
    false.
pass_all_args="true|false" (optional Default: false) 
    #If true, then all args set in the current context are added to the child context 
    that is created for processing the included file. You can do this instead of 
    explicitly listing each argument that you want to pass down.

②Elements

<env>
    #Set an environment variable on across the entire included file.
<arg>
    #Pass an argument to the included file.

<remap> tag

The <remap> tag allows you to pass in name remapping arguments to the ROS node that you are launching in a more structured manner than setting the args attribute of a <node> directly. The <remap> tag applies to all subsequent declarations in its scope (<launch>, <node> or <group>).

①Attributes

from="original-name"
    #Name that you are remapping.
to="new-name"
    #Target name.

例子,
For example, you are given a node that says it subscribes to the “chatter” topic, but you only have a node that publishes the “hello” topic. They are the same type, and you want to pipe your “hello” topic into the new node which wants “chatter” by simply:

<remap from="chatter" to="hello"/>

<env> tag (deprecated)

The <env> tag is deprecated since Fuerte. Use env-loader instead.

The <env> tag allows you to set environment variables on nodes that are launched. This tag may only be used within the scope of a <launch>, <include>, <node> or <machine> tag. When it is used inside of a <launch> tag, the <env> tag only applies to nodes declared after.

① Attributes

name="environment-variable-name"
    #Environment variable you are setting.
value="environment-variable-value"
    #Value to set the environment variable to.

<param> tag

The <param> tag defines a parameter to be set on the Parameter Server. Instead of value, you can specify a textfile, binfile or command attribute to set the value of a parameter. The <param> tag can be put inside of a <node> tag, in which case the parameter is treated like a private parameter.

You can also set private parameter across a group of nodes by using the ~param syntax (see ROS names) in a <param> tag. The declared parameter will be set as a local parameter in the <node>tags that follow that are in the same scope (i.e. group or ns tag).

①Attributes

name="namespace/name"
    #Parameter name. Namespaces can be included in the parameter name, but globally 
    specified names should be avoided.
value="value"(optional)
    #Defines the value of the parameter. If this attribute is omitted, binfile, textfile 
    or command must be specified.
type="str|int|double|bool|yaml"(optional)
    #Specifies the type of the parameter. If you don't specify the type, roslaunch will 
    attempt to automatically determine the type. These rules are very basic:     
    numbers with '.'s are floating point, integers otherwise;
    "true" and "false" are boolean (not case-sensitive).
    all other values are strings
textfile="$(find pkg-name)/path/file.txt"(optional)
    #The contents of the file will be read and stored as a string. The file must be 
    locally accessible, though it is strongly recommended that you use the package-
    relative $(find)/file.txt syntax to specify the location.
binfile="$(find pkg-name)/path/file"(optional)
    #The contents of the file will be read and stored as a base64-encoded XML-RPC binary 
    object. The file must be locally accessible, though it is strongly recommended that 
    you use the package-relative $(find)/file.txt syntax to specify the location.
command="$(find pkg-name)/exe '$(find pkg-name)/arg.txt'"(optional)
    #The output of the command will be read and stored as a string. It is strongly 
    recommended that you use the package-relative $(find)/file.txt syntax to specify 
    file arguments. You should also quote file arguments using single quotes due to XML 
    escaping requirements.

例子,

<param name="publish_frequency" type="double" value="10.0" />

In order to load a YAML file, you can use:

<rosparam command="load" file="FILENAME" />

But this doesn’t work when using a command which outputs the parameters on stdout. In that case the new param type yaml can be used:

<param name="params_a" type="yaml" command="cat &quot;$(find roslaunch)/test/params.yaml&quot;" />

<rosparam> tag

The <rosparam> tag enables the use of rosparam YAML files for loading and dumping parameters from the ROS Parameter Server. It can also be used to remove parameters. The <rosparam> tag can be put inside of a <node> tag, in which case the parameter is treated like a private name.

The delete and dump commands run before the load command as well as before any other parameters are uploaded to the Parameter Server. delete and dump commands run in the declared order.

The load command is considered additive: if you declare a dictionary or namespace of parameters, those parameters will be added to any other parameters declared for that namespace. Similarly, load commands can override parameters previously declared.

The <rosparam> tag can either reference a YAML file or contain raw YAML text. If the YAML text defines a dictionary, the param attribute may be omitted.

①Attributes

command="load|dump|delete" (optional, default=load)
    #rosparam command.
file="$(find pkg-name)/path/foo.yaml" (load or dump commands)
    #Name of rosparam file.
param="param-name"
    #Name of parameter.
ns="namespace" (optional)
    #Scope the parameters to the specified namespace.
subst_value=true|false (optional)
    #Allows use of substitution args in the YAML text.

例子,

<rosparam command="load" file="$(find rosparam)/example.yaml" />
<rosparam command="delete" param="my/param" />
<rosparam param="a_list">[1, 2, 3, 4]</rosparam>
<rosparam>
  a: 1
  b: 2
</rosparam>

Substitution allows you to make use of roslaunch args representing all or part of a YAML string. e.g.

<arg name="whitelist" default="[3, 2]"/>
<rosparam param="whitelist" subst_value="True">$(arg whitelist)</rosparam>

They are also useful for embedding $(find …) in yaml strings and to a lesser extent any of the other substitution patterns.

Example of accessing a list in roscpp code:

XmlRpc::XmlRpcValue v;
    nh_.param("subscribed_to_nodes", v, v);
    for(int i =0; i < v.size(); i++)
    {
      node_names_.push_back(v[i]);
      std::cerr << "node_names: " << node_names_[i] << std::endl;
    }

<group> tag

The <group> tag makes it easier to apply settings to a group of nodes. It has an ns attribute that lets you push the group of nodes into a separate namespace. You can also use the <remap> tag to apply remap setting across the group.

①Attributes

ns="namespace" (optional)
    #Assign the group of nodes to the specified namespace. The namespace can be global 
    or relative, though global namespaces are discouraged.
clear_params="true|false" (optional)
    #Delete all parameters in the group's namespace before launch. This feature is very 
    dangerous and should be used with caution. ns must be specified.

②Elements

The <group> tag is equivalent to the top-level <launch> tag and simply acts as a container for the tags within. This means that you can use any tag as you would normally use it within a <launch> tag.

<node>
    #Launch a node.
<param>
    #Set a parameter on the Parameter Server
<remap>
    #Declare a name remapping.
<machine>
    #Declare a machine to use for launching.
<rosparam>
    #Set ROS parameters for the launch using a rosparam file.
<include>
    #Include other roslaunch files.
<env>
    #Specify an environment variable for launched nodes.
<test>
    #Launch a test node (see rostest).
<arg>
    #Declare an argument.

<arg> tag

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> can be used in one of three ways:

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

①Attributes

name="arg_name"
    #Name of argument.
default="default value" (optional)
    #Default value of argument. Cannot be combined with value attribute.
value="value" (optional)
    #Argument value. Cannot be combined with default attribute.
doc="description for this arg" (optional) New in Indigo
    #Description of the argument.

例子,

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 my_file.launch hoge:=my_value      (.launch file is available at the current dir)
$ roslaunch %YOUR_ROS_PKG% my_file.launch hoge:=my_value
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
可以回答这个问题。在Ubuntu18.04,在rplidar_ros新建slam.launch文件的步骤如下: 1. 打开终端,输入以下命令安装rplidar_ros包: ``` sudo apt-get install ros-melodic-rplidar-ros ``` 2. 在终端输入以下命令,创建一个新的工作空间: ``` mkdir -p ~/catkin_ws/src cd ~/catkin_ws/src catkin_init_workspace ``` 3. 在终端输入以下命令,将rplidar_ros包复制到工作空间: ``` cd ~/catkin_ws/src git clone https://github.com/robopeak/rplidar_ros.git ``` 4. 在终端输入以下命令,编译工作空间: ``` cd ~/catkin_ws catkin_make ``` 5. 在终端输入以下命令,打开slam.launch文件: ``` roscd rplidar_ros cd launch gedit slam.launch ``` 6. 在slam.launch文件添加以下内容: ``` <launch> <node pkg="gmapping" type="slam_gmapping" name="slam_gmapping"> <param name="base_frame" value="base_link"/> <param name="odom_frame" value="odom"/> <param name="map_frame" value="map"/> <param name="map_update_interval" value="1."/> <param name="maxUrange" value="10."/> <param name="sigma" value=".05"/> <param name="kernelSize" value="1"/> <param name="lstep" value=".05"/> <param name="astep" value=".05"/> <param name="iterations" value="5"/> <param name="lsigma" value=".075"/> <param name="ogain" value="3."/> <param name="lskip" value=""/> <param name="srr" value=".1"/> <param name="srt" value=".2"/> <param name="str" value=".1"/> <param name="stt" value=".2"/> <param name="linearUpdate" value=".2"/> <param name="angularUpdate" value=".1"/> <param name="temporalUpdate" value="3."/> <param name="resampleThreshold" value=".5"/> <param name="particles" value="30"/> <param name="xmin" value="-10."/> <param name="ymin" value="-10."/> <param name="xmax" value="10."/> <param name="ymax" value="10."/> <param name="delta" value=".05"/> <param name="llsamplerange" value=".01"/> <param name="llsamplestep" value=".01"/> <param name="lasamplerange" value=".005"/> <param name="lasamplestep" value=".005"/> <param name="tf_delay" value=".05"/> </node> <node pkg="rplidar_ros" type="rplidarNode" name="rplidarNode" output="screen"> <param name="serial_port" value="/dev/ttyUSB"/> <param name="serial_baudrate" value="115200"/> </node> </launch> ``` 7. 保存并关闭slam.launch文件。 8. 在终端输入以下命令,启动slam.launch文件: ``` roslaunch rplidar_ros slam.launch ``` 这样就可以在Ubuntu18.04在rplidar_ros新建slam.launch文件了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值