Migrating Launch Files
While launch files in ROS 1 are always specified using XML files, ROS 2 supports both XML and YAML files. ROS 2 also supports Python launch scripts to enable more flexibility (see launch package). However, for typical use cases, XML and YAML should be preferred over Python.
This guide describes how to write ROS 2 XML launch files for an easy migration from ROS 1.
Background
A description of the ROS 2 launch system can be found in Launch System tutorial.
Replacing an include tag
In order to include a launch file under a namespace as in ROS 1 then the include tags must be nested in a group tag.
<group>
<include file="another_launch_file"/>
</group>
Then, instead of using the ns attribute, add the push_ros_namespace action tag to specify the namespace:
<group>
<push_ros_namespace namespace="my_ns"/>
<include file="another_launch_file"/>
</group>
Nesting include tags under a group tag is only required when specifying a namespace
Substitutions
Documentation about ROS 1’s substitutions can be found in roslaunch XML wiki.
Substitutions syntax hasn’t changed, i.e. it still follows the $(substitution-name arg1 arg2 ...) pattern.
There are, however, some changes w.r.t. ROS 1:
envandoptenvtags have been replaced by theenvtag.$(env <NAME>)will fail if the environment variable doesn’t exist.$(env <NAME> '')does the same as ROS 1’s$(optenv <NAME>).$(env <NAME> <DEFAULT>)does the same as ROS 1’s$(env <NAME> <DEFAULT>)or$(optenv <NAME> <DEFAULT>).findhas been replaced withfind-pkg-share(substituting the share directory of an installed package). Alternativelyfind-pkg-prefixwill return the root of an installed package.There is a new
exec-in-pkgsubstitution. e.g.:$(exec-in-pkg <package_name> <exec_name>).There is a new
find-execsubstitution.arghas been replaced withvar. It looks at configurations defined either withargorlettag.evalanddirnamesubstitutions require escape characters for string values, e.g.if="$(eval '\'$(var variable)\' == \'val1\'')".
Type inference rules
The rules that were shown in Type inference rules subsection of param tag applies to any attribute.
For example:
<!--Setting a string value to an attribute expecting an int will raise an error.-->
<tag1 attr-expecting-an-int="'1'"/>
<!--Correct version.-->
<tag1 attr-expecting-an-int="1"/>
<!--Setting an integer in an attribute expecting a string will raise an error.-->
<tag2 attr-expecting-a-str="1"/>
<!--Correct version.-->
<tag2 attr-expecting-a-str="'1'"/>
<!--Setting a list of strings in an attribute expecting a string will raise an error.-->
<tag3 attr-expecting-a-str="asd, bsd" str-attr-sep=", "/>
<!--Correct version.-->
<tag3 attr-expecting-a-str="don't use a separator"/>
Some attributes accept more than a single type, for example value attribute of param tag.
It’s usual that parameters that are of type int (or float) also accept an str, that will be later substituted and tried to convert to an int (or float) by the action.