Skip to content

Launch preferences update: XML-first, .launch extensions, Python launchfile declarative style #5143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 14 commits into
base: rolling
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions source/Concepts/Basic/About-Launch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ Launch
:local:

A ROS 2 system typically consists of many nodes running across many different processes (and even different machines).
While it is possible to run each of these nodes separately, it gets cumbersome quite quickly.
While it is possible to manually start each of these nodes, it gets cumbersome quite quickly.

The launch system in ROS 2 is meant to automate the running of many nodes with a single command.
It helps the user describe the configuration of their system and then executes it as described.
The configuration of the system includes what programs to run, where to run them, what arguments to pass them, and ROS-specific conventions which make it easy to reuse components throughout the system by giving them each a different configuration.
It is also responsible for monitoring the state of the processes launched, and reporting and/or reacting to changes in the state of those processes.

All of the above is specified in a launch file, which can be written in XML, YAML, or Python.
All of the above is specified in a "launch file", which can be written in XML, YAML, or Python.
This launch file can then be run using the ``ros2 launch`` command, and all of the nodes specified will be run.

The `design document <https://design.ros2.org/articles/roslaunch.html>`__ details the goal of the design of ROS 2's launch system (not all functionality is currently available).
To get started writing and using launch files, see `the launch tutorials <../../Tutorials/Intermediate/Launch/Launch-Main>`.

For more detailed information, see `the launch documentation <https://docs.ros.org/en/{DISTRO}/p/launch>`__.
2 changes: 1 addition & 1 deletion source/How-To-Guides/Developing-a-ROS-2-Package.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ and a ``setup.py`` file that looks like:
# Include our package.xml file
(os.path.join('share', package_name), ['package.xml']),
# Include all launch files.
(os.path.join('share', package_name, 'launch'), glob(os.path.join('launch', '*launch.[pxy][yma]*'))),
(os.path.join('share', package_name, 'launch'), glob(os.path.join('launch', '*'))),
],
# This is important as well
install_requires=['setuptools'],
Expand Down
291 changes: 132 additions & 159 deletions source/How-To-Guides/Launch-file-different-formats.rst

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -331,35 +331,24 @@ If you look at the other terminal, you should see the output change to ``[INFO]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can also set the parameter in a launch file, but first you will need to add the launch directory.
Inside the ``ros2_ws/src/cpp_parameters/`` directory, create a new directory called ``launch``.
In there, create a new file called ``cpp_parameters_launch.py``
In there, create a new file called ``param_node.launch``


.. code-block:: Python

from launch import LaunchDescription
from launch_ros.actions import Node
.. code-block:: xml

def generate_launch_description():
return LaunchDescription([
Node(
package="cpp_parameters",
executable="minimal_param_node",
name="custom_minimal_param_node",
output="screen",
emulate_tty=True,
parameters=[
{"my_parameter": "earth"}
]
)
])
<?xml version="1.0" encoding="UTF-8"?>
<launch>
<node pkg="cpp_parameters" exec="minimal_param_node" name="custom_minimal_param_node" output="screen" emulate_tty="true">
<param name="my_parameter" value="earth" />
</node>
</launch>

Here you can see that we set ``my_parameter`` to ``earth`` when we launch our node ``minimal_param_node``.
By adding the two lines below, we ensure our output is printed in our console.
By adding the values below, we ensure our output is printed in our console.

.. code-block:: console

output="screen",
emulate_tty=True,
output="screen" emulate_tty="true"

Now open the ``CMakeLists.txt`` file.
Below the lines you added earlier, add the following lines of code.
Expand Down Expand Up @@ -419,7 +408,7 @@ Now run the node using the launch file we have just created:

.. code-block:: console

ros2 launch cpp_parameters cpp_parameters_launch.py
ros2 launch cpp_parameters param_node.launch

The terminal should return the following message the first time:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,34 +330,23 @@ Since the node afterwards set the parameter back to ``world``, further outputs s

You can also set parameters in a launch file, but first you will need to add a launch directory.
Inside the ``ros2_ws/src/python_parameters/`` directory, create a new directory called ``launch``.
In there, create a new file called ``python_parameters_launch.py``
In there, create a new file called ``param_node.launch``

.. code-block:: Python
.. code-block:: xml

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
return LaunchDescription([
Node(
package='python_parameters',
executable='minimal_param_node',
name='custom_minimal_param_node',
output='screen',
emulate_tty=True,
parameters=[
{'my_parameter': 'earth'}
]
)
])
<?xml version="1.0" encoding="UTF-8"?>
<launch>
<node pkg="python_parameters" exec="minimal_param_node" name="custom_minimal_param_node" output="screen" emulate_tty="true">
<param name="my_parameter" value="earth" />
</node>
</launch>

Here you can see that we set ``my_parameter`` to ``earth`` when we launch our node ``parameter_node``.
By adding the two lines below, we ensure our output is printed in our console.
Here you can see that we set ``my_parameter`` to ``earth`` when we launch our node ``minimal_param_node``.
By adding the values below, we ensure our output is printed in our console.

.. code-block:: console

output="screen",
emulate_tty=True,
output="screen" emulate_tty="true"

Now open the ``setup.py`` file.
Add the ``import`` statements to the top of the file, and the other new statement to the ``data_files`` parameter to include all launch files:
Expand All @@ -372,7 +361,7 @@ Add the ``import`` statements to the top of the file, and the other new statemen
# ...
data_files=[
# ...
(os.path.join('share', package_name), glob('launch/*launch.[pxy][yma]*')),
(os.path.join('share', package_name), glob('launch/*')),
]
)

Expand Down Expand Up @@ -424,7 +413,7 @@ Now run the node using the launch file we have just created:

.. code-block:: console

ros2 launch python_parameters python_parameters_launch.py
ros2 launch python_parameters param_node.launch

The terminal should return the following message the first time:

Expand Down
Loading