Skip to content

Pull all example launchfiles into separate file with literalinclude (backport #5155) #5175

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

Closed
wants to merge 1 commit into from
Closed
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
20 changes: 17 additions & 3 deletions source/How-To-Guides/Launch-file-different-formats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Guides/Launch-file-different-formats

Using Python, XML, and YAML for ROS 2 Launch Files
Using XML, YAML, and Python for ROS 2 Launch Files
==================================================

.. contents:: Table of Contents
Expand All @@ -29,6 +29,7 @@ Each launch file performs the following actions:

.. group-tab:: XML

<<<<<<< HEAD
.. code-block:: xml

<!-- example.launch.xml -->
Expand Down Expand Up @@ -136,11 +137,22 @@ Each launch file performs the following actions:
-
from: "/output/cmd_vel"
to: "/turtlesim2/turtle1/cmd_vel"
=======
.. literalinclude:: launch/different_formats_launch.xml
:language: xml

.. group-tab:: YAML

.. literalinclude:: launch/different_formats_launch.yaml
:language: yaml
>>>>>>> 666df3e (Pull all example launchfiles into separate file with `literalinclude` (#5155))

.. group-tab:: Python

.. code-block:: python
.. literalinclude:: launch/different_formats_launch.py
:language: python

<<<<<<< HEAD
# example.launch.py

import os
Expand Down Expand Up @@ -239,6 +251,8 @@ Each launch file performs the following actions:
turtlesim_node_with_parameters,
forward_turtlesim_commands_to_second_turtlesim_node,
])
=======
>>>>>>> 666df3e (Pull all example launchfiles into separate file with `literalinclude` (#5155))

Using the Launch files from the command line
--------------------------------------------
Expand Down Expand Up @@ -287,7 +301,7 @@ To test that the remapping is working, you can control the turtles by running th

.. _launch-file-different-formats-which:

Python, XML, or YAML: Which should I use?
XML, YAML, or Python: Which should I use?
-----------------------------------------

.. note::
Expand Down
210 changes: 13 additions & 197 deletions source/How-To-Guides/Launching-composable-nodes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,108 +31,18 @@ The launch files all do the following:

.. group-tab:: XML

.. code-block:: xml

<launch>
<node_container pkg="rclcpp_components" exec="component_container" name="image_container" namespace="">
<composable_node pkg="image_tools" plugin="image_tools::Cam2Image" name="cam2image" namespace="">
<remap from="/image" to="/burgerimage" />
<param name="width" value="320" />
<param name="height" value="240" />
<param name="burger_mode" value="true" />
<param name="history" value="keep_last" />
<extra_arg name="use_intra_process_comms" value="true" />
</composable_node>
<composable_node pkg="image_tools" plugin="image_tools::ShowImage" name="showimage" namespace="">
<remap from="/image" to="/burgerimage" />
<param name="history" value="keep_last" />
<extra_arg name="use_intra_process_comms" value="true" />
</composable_node>
</node_container>
</launch>
.. literalinclude:: launch/composition_launch.xml
:language: xml

.. group-tab:: YAML

.. code-block:: yaml

launch:

- node_container:
pkg: rclcpp_components
exec: component_container
name: image_container
namespace: ''
composable_node:
- pkg: image_tools
plugin: image_tools::Cam2Image
name: cam2image
namespace: ''
remap:
- from: /image
to: /burgerimage
param:
- name: width
value: 320
- name: height
value: 240
- name: burger_mode
value: true
- name: history
value: keep_last
extra_arg:
- name: use_intra_process_comms
value: 'true'

- pkg: image_tools
plugin: image_tools::ShowImage
name: showimage
namespace: ''
remap:
- from: /image
to: /burgerimage
param:
- name: history
value: keep_last
extra_arg:
- name: use_intra_process_comms
value: 'true'
.. literalinclude:: launch/composition_launch.yaml
:language: yaml

.. group-tab:: Python

.. code-block:: python

import launch
from launch_ros.actions import ComposableNodeContainer
from launch_ros.descriptions import ComposableNode


def generate_launch_description():
"""Generate launch description with multiple components."""
container = ComposableNodeContainer(
name='image_container',
namespace='',
package='rclcpp_components',
executable='component_container',
composable_node_descriptions=[
ComposableNode(
package='image_tools',
plugin='image_tools::Cam2Image',
name='cam2image',
remappings=[('/image', '/burgerimage')],
parameters=[{'width': 320, 'height': 240, 'burger_mode': True, 'history': 'keep_last'}],
extra_arguments=[{'use_intra_process_comms': True}]),
ComposableNode(
package='image_tools',
plugin='image_tools::ShowImage',
name='showimage',
remappings=[('/image', '/burgerimage')],
parameters=[{'history': 'keep_last'}],
extra_arguments=[{'use_intra_process_comms': True}])
],
output='both',
)

return launch.LaunchDescription([container])
.. literalinclude:: launch/composition_launch.py
:language: python


Loading composable nodes into an existing container
Expand All @@ -147,112 +57,18 @@ The below example launches the same nodes as above.

.. group-tab:: XML

.. code-block:: xml

<launch>
<node pkg="rclcpp_components" exec="component_container" name="image_container">
</node>
<load_composable_node target="image_container">
<composable_node pkg="image_tools" plugin="image_tools::Cam2Image" name="cam2image">
<remap from="/image" to="/burgerimage" />
<param name="width" value="320" />
<param name="height" value="240" />
<param name="burger_mode" value="true" />
<param name="history" value="keep_last" />
<extra_arg name="use_intra_process_comms" value="true" />
</composable_node>
<composable_node pkg="image_tools" plugin="image_tools::ShowImage" name="showimage" namespace="">
<remap from="/image" to="/burgerimage" />
<param name="history" value="keep_last" />
<extra_arg name="use_intra_process_comms" value="true" />
</composable_node>
</load_composable_node>
</launch>
.. literalinclude:: launch/composition_load_launch.xml
:language: xml

.. group-tab:: YAML

.. code-block:: yaml

launch:
- node_container:
pkg: rclcpp_components
exec: component_container
name: image_container
namespace: ''
composable_node:
- pkg: image_tools
plugin: image_tools::Cam2Image
name: cam2image
namespace: ''
remap:
- from: /image
to: /burgerimage
param:
- name: width
value: 320
- name: height
value: 240
- name: burger_mode
value: true
- name: history
value: keep_last
extra_arg:
- name: use_intra_process_comms
value: 'true'

- pkg: image_tools
plugin: image_tools::ShowImage
name: showimage
namespace: ''
remap:
- from: /image
to: /burgerimage
param:
- name: history
value: keep_last
extra_arg:
- name: use_intra_process_comms
value: 'true'
.. literalinclude:: launch/composition_load_launch.yaml
:language: yaml

.. group-tab:: Python

.. code-block:: python

from launch import LaunchDescription
from launch_ros.actions import LoadComposableNodes, Node
from launch_ros.descriptions import ComposableNode

def generate_launch_description():
container = Node(
name='image_container',
package='rclcpp_components',
executable='component_container',
output='both',
)

load_composable_nodes = LoadComposableNodes(
target_container='image_container',
composable_node_descriptions=[
ComposableNode(
package='image_tools',
plugin='image_tools::Cam2Image',
name='cam2image',
remappings=[('/image', '/burgerimage')],
parameters=[{'width': 320, 'height': 240, 'burger_mode': True, 'history': 'keep_last'}],
extra_arguments=[{'use_intra_process_comms': True}],
),
ComposableNode(
package='image_tools',
plugin='image_tools::ShowImage',
name='showimage',
remappings=[('/image', '/burgerimage')],
parameters=[{'history': 'keep_last'}],
extra_arguments=[{'use_intra_process_comms': True}]
),
],
)

return LaunchDescription([container, load_composable_nodes])
.. literalinclude:: launch/composition_load_launch.py
:language: python


Using the Launch files from the command-line
Expand All @@ -271,7 +87,7 @@ Intra-process communications
All of the above examples use an extra argument to setup intra-process communication between the nodes.
For more information on what intra-process communications are, see the :doc:`intra-process comms tutorial <../Tutorials/Demos/Intra-Process-Communication>`.

Python, XML, or YAML: Which should I use?
XML, YAML, or Python: Which should I use?
-----------------------------------------

See the :ref:`discussion <launch-file-different-formats-which>` in :doc:`Launch-file-different-formats` for more information.
36 changes: 36 additions & 0 deletions source/How-To-Guides/launch/composition_launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import launch
from launch_ros.actions import ComposableNodeContainer
from launch_ros.descriptions import ComposableNode


def generate_launch_description():
"""Generate launch description with multiple components."""
return launch.LaunchDescription([
ComposableNodeContainer(
name='image_container',
namespace='',
package='rclcpp_components',
executable='component_container',
composable_node_descriptions=[
ComposableNode(
package='image_tools',
plugin='image_tools::Cam2Image',
name='cam2image',
remappings=[('/image', '/burgerimage')],
parameters=[{
'width': 320,
'height': 240,
'burger_mode': True,
'history': 'keep_last'}],
extra_arguments=[{'use_intra_process_comms': True}]),
ComposableNode(
package='image_tools',
plugin='image_tools::ShowImage',
name='showimage',
remappings=[('/image', '/burgerimage')],
parameters=[{'history': 'keep_last'}],
extra_arguments=[{'use_intra_process_comms': True}])
],
output='both',
),
])
18 changes: 18 additions & 0 deletions source/How-To-Guides/launch/composition_launch.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<launch>
<node_container pkg="rclcpp_components" exec="component_container" name="image_container">
<composable_node pkg="image_tools" plugin="image_tools::Cam2Image" name="cam2image">
<remap from="/image" to="/burgerimage" />
<param name="width" value="320" />
<param name="height" value="240" />
<param name="burger_mode" value="true" />
<param name="history" value="keep_last" />
<extra_arg name="use_intra_process_comms" value="true" />
</composable_node>
<composable_node pkg="image_tools" plugin="image_tools::ShowImage" name="showimage">
<remap from="/image" to="/burgerimage" />
<param name="history" value="keep_last" />
<extra_arg name="use_intra_process_comms" value="true" />
</composable_node>
</node_container>
</launch>
39 changes: 39 additions & 0 deletions source/How-To-Guides/launch/composition_launch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
%YAML 1.2
---
launch:
- node_container:
pkg: rclcpp_components
exec: component_container
name: image_container
composable_node:
- pkg: image_tools
plugin: image_tools::Cam2Image
name: cam2image
remap:
- from: /image
to: /burgerimage
param:
- name: width
value: 320
- name: height
value: 240
- name: burger_mode
value: true
- name: history
value: keep_last
extra_arg:
- name: use_intra_process_comms
value: true

- pkg: image_tools
plugin: image_tools::ShowImage
name: showimage
remap:
- from: /image
to: /burgerimage
param:
- name: history
value: keep_last
extra_arg:
- name: use_intra_process_comms
value: true
Loading
Loading