Skip to content

Commit 1686048

Browse files
authored
Add in additional info about using intra-process comms. (ros2#2225)
* Add in additional info about using intra-process comms. Signed-off-by: Chris Lalancette <[email protected]>
1 parent 93cbb7c commit 1686048

File tree

4 files changed

+192
-57
lines changed

4 files changed

+192
-57
lines changed

source/How-To-Guides.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ If you are new and looking to learn the ropes, start with the :doc:`Tutorials <T
2626
How-To-Guides/Ament-CMake-Python-Documentation
2727
How-To-Guides/Launch-files-migration-guide
2828
How-To-Guides/Launch-file-different-formats
29+
How-To-Guides/Launching-composable-nodes
2930
How-To-Guides/Parameters-YAML-files-migration-guide
3031
How-To-Guides/Node-arguments
3132
How-To-Guides/Sync-Vs-Async
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
Using ROS 2 launch to launch composable nodes
2+
=============================================
3+
4+
.. contents:: Table of Contents
5+
:depth: 1
6+
:local:
7+
8+
In the :doc:`Composition tutorial <../Tutorials/Composition>`, you learned about composable nodes and how to use them from the command-line.
9+
In the :doc:`Launch tutorials <../Tutorials/Launch/Launch-Main>`, you learned about launch files and how to use them to manage multiple nodes.
10+
11+
This guide will combine the above two topics and teach you how to write launch files for composable nodes.
12+
13+
Setup
14+
-----
15+
16+
See the :doc:`installation instructions <../Installation>` for details on installing ROS 2.
17+
18+
If you've installed ROS 2 from packages, ensure that you have ``ros-{DISTRO}-image-tools`` installed.
19+
If you downloaded the archive or built ROS 2 from source, it will already be part of the installation.
20+
21+
Launch file examples
22+
--------------------
23+
24+
Below is a launch file that launches composable nodes in Python, XML, and YAML.
25+
The launch files all do the following:
26+
27+
* Instantiate a cam2image composable node with remappings, custom parameters, and extra arguments
28+
* Instantiate a showimage composable node with remappings, custom parameters, and extra arguments
29+
30+
.. tabs::
31+
32+
.. group-tab:: Python
33+
34+
.. code-block:: python
35+
36+
import launch
37+
from launch_ros.actions import ComposableNodeContainer
38+
from launch_ros.descriptions import ComposableNode
39+
40+
41+
def generate_launch_description():
42+
"""Generate launch description with multiple components."""
43+
container = ComposableNodeContainer(
44+
name='image_container',
45+
namespace='',
46+
package='rclcpp_components',
47+
executable='component_container',
48+
composable_node_descriptions=[
49+
ComposableNode(
50+
package='image_tools',
51+
plugin='image_tools::Cam2Image',
52+
name='cam2image',
53+
remappings=[('/image', '/burgerimage')],
54+
parameters=[{'width': 320, 'height': 240, 'burger_mode': True, 'history': 'keep_last'}],
55+
extra_arguments=[{'use_intra_process_comms': True}]),
56+
ComposableNode(
57+
package='image_tools',
58+
plugin='image_tools::ShowImage',
59+
name='showimage',
60+
remappings=[('/image', '/burgerimage')],
61+
parameters=[{'history': 'keep_last'}],
62+
extra_arguments=[{'use_intra_process_comms': True}])
63+
],
64+
output='both',
65+
)
66+
67+
return launch.LaunchDescription([container])
68+
69+
.. group-tab:: XML
70+
71+
.. code-block:: xml
72+
73+
<launch>
74+
<node_container pkg="rclcpp_components" exec="component_container" name="image_container" namespace="">
75+
<composable_node pkg="image_tools" plugin="image_tools::Cam2Image" name="cam2image" namespace="">
76+
<remap from="/image" to="/burgerimage" />
77+
<param name="width" value="320" />
78+
<param name="height" value="240" />
79+
<param name="burger_mode" value="true" />
80+
<param name="history" value="keep_last" />
81+
<extra_arg name="use_intra_process_comms" value="true" />
82+
</composable_node>
83+
<composable_node pkg="image_tools" plugin="image_tools::ShowImage" name="showimage" namespace="">
84+
<remap from="/image" to="/burgerimage" />
85+
<param name="history" value="keep_last" />
86+
<extra_arg name="use_intra_process_comms" value="true" />
87+
</composable_node>
88+
</node_container>
89+
</launch>
90+
91+
.. group-tab:: YAML
92+
93+
.. code-block:: yaml
94+
95+
launch:
96+
97+
- node_container:
98+
pkg: rclcpp_components
99+
exec: component_container
100+
name: image_container
101+
namespace: ''
102+
composable_node:
103+
- pkg: image_tools
104+
plugin: image_tools::Cam2Image
105+
name: cam2image
106+
namespace: ''
107+
remap:
108+
- from: /image
109+
to: /burgerimage
110+
param:
111+
- name: width
112+
value: 320
113+
- name: height
114+
value: 240
115+
- name: burger_mode
116+
value: true
117+
- name: history
118+
value: keep_last
119+
extra_arg:
120+
- name: use_intra_process_comms
121+
value: 'true'
122+
123+
- pkg: image_tools
124+
plugin: image_tools::ShowImage
125+
name: showimage
126+
namespace: ''
127+
remap:
128+
- from: /image
129+
to: /burgerimage
130+
param:
131+
- name: history
132+
value: keep_last
133+
extra_arg:
134+
- name: use_intra_process_comms
135+
value: 'true'
136+
137+
Using the Launch files from the command-line
138+
--------------------------------------------
139+
140+
Any of the launch files above can be run with ``ros2 launch``.
141+
Copy the data into a local file, and then run:
142+
143+
.. code-block:: console
144+
145+
ros2 launch <path_to_launch_file>
146+
147+
Intra-process communications
148+
----------------------------
149+
150+
All of the above examples use an extra argument to setup intra-process communication between the nodes.
151+
For more information on what intra-process communications are, see the :doc:`intra-process comms tutorial <../Tutorials/Intra-Process-Communication>`.
152+
153+
Python, XML, or YAML: Which should I use?
154+
-----------------------------------------
155+
156+
See the discussion in :doc:`Launch-file-different-formats` for more information.

source/Tutorials/Composition.rst

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Composing multiple nodes in a single process
1212
Background
1313
----------
1414

15-
See the `conceptual article <../Concepts/About-Composition>`.
15+
See the :doc:`conceptual article <../Concepts/About-Composition>`.
1616

1717
Run the demos
1818
-------------
@@ -269,6 +269,27 @@ The corresponding entries appear in ``ros2 component list``:
269269

270270
Namespace remappings of the container do not affect loaded components.
271271

272+
Passing parameter values into components
273+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
274+
275+
The ``ros2 component load`` command-line supports passing arbitrary parameters to the node as it is constructed.
276+
This functionality can be used as follows:
277+
278+
.. code-block:: bash
279+
280+
$ ros2 component load /ComponentManager image_tools image_tools::Cam2Image -p burger_mode:=true
281+
282+
Passing additional arguments into components
283+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
284+
285+
The ``ros2 component load`` command-line supports passing particular options to the component manager for use when constructing the node.
286+
As of now, the only command-line option that is supported is to instantiate a node using intra-process communication.
287+
This functionality can be used as follows:
288+
289+
.. code-block:: bash
290+
291+
$ ros2 component load /ComponentManager composition composition::Talker -e use_intra_process_comms:=true
292+
272293
Composable nodes as shared libraries
273294
------------------------------------
274295

source/Tutorials/Intra-Process-Communication.rst

Lines changed: 13 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,13 @@ In ROS 2 we aim to improve on the design of Nodelets by addressing some fundamen
1919

2020
In this demo we'll be highlighting how nodes can be composed manually, by defining the nodes separately but combining them in different process layouts without changing the node's code or limiting its abilities.
2121

22-
Build the demos
23-
---------------
22+
Installing the demos
23+
--------------------
2424

25-
These demos should work on any of the three major OSs (Windows, Mac, or Linux).
26-
Some of them do require OpenCV to have been installed.
25+
See the :doc:`installation instructions <../Installation>` for details on installing ROS 2.
2726

28-
Using the pre-built binaries
29-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30-
31-
If you've installed the binaries, simply source the ROS 2 setup file and then skip down to any of the individual demos to see how to run them.
32-
33-
Building from source
34-
^^^^^^^^^^^^^^^^^^^^
35-
36-
Make sure you have OpenCV installed and then follow the source instructions.
37-
You can find the from source instructions linked from the main `ros2 installation page <../Installation>`.
38-
Once built source the setup file and continue down to one of the specific demos to read about them and for instructions on how to run them.
27+
If you've installed ROS 2 from packages, ensure that you have ``ros-{DISTRO}-intra-process-demo`` installed.
28+
If you downloaded the archive or built ROS 2 from source, it will already be part of the installation.
3929

4030
Running and understanding the demos
4131
-----------------------------------
@@ -274,7 +264,7 @@ To test those expectations, let's run it:
274264

275265
.. code-block:: bash
276266
277-
% ros2 run intra_process_demo cyclic_pipeline
267+
$ ros2 run intra_process_demo cyclic_pipeline
278268
Published first message with value: 42, and address: 0x7fd2ce0a2bc0
279269
Received message with value: 42, and address: 0x7fd2ce0a2bc0
280270
sleeping for 1 second...
@@ -307,14 +297,16 @@ The image pipeline demo
307297

308298
In this demo we'll use OpenCV to capture, annotate, and then view images.
309299

310-
Note for macOS users: If these examples do not work or you receive an error like ``ddsi_conn_write failed -1`` then you'll need to increase your system wide UDP packet size:
300+
.. note::
311301

312-
.. code-block:: bash
302+
If you are on macOS and these examples do not work or you receive an error like ``ddsi_conn_write failed -1``, then you'll need to increase your system wide UDP packet size:
313303

314-
$ sudo sysctl -w net.inet.udp.recvspace=209715
315-
$ sudo sysctl -w net.inet.udp.maxdgram=65500
304+
.. code-block:: bash
316305
317-
These changes will not persist after a reboot.
306+
$ sudo sysctl -w net.inet.udp.recvspace=209715
307+
$ sudo sysctl -w net.inet.udp.maxdgram=65500
308+
309+
These changes will not persist after a reboot.
318310

319311
Simple pipeline
320312
~~~~~~~~~~~~~~~
@@ -394,38 +386,3 @@ One other important thing to get right is to avoid interruption of the intra pro
394386

395387

396388
It's hard to pause both images at the same time so the images may not line up, but the important thing to notice is that the ``image_pipeline_all_in_one`` image view shows the same address for each step. This means that the intra process zero-copy is preserved even when an external view is subscribed as well. You can also see that the interprocess image view has different process IDs for the first two lines of text and the process ID of the standalone image viewer in the third line of text.
397-
398-
Looking forward
399-
---------------
400-
401-
These demos are the foundation for some cool new features on which we're actively working, but right now some things are missing.
402-
403-
Room for Improvement
404-
^^^^^^^^^^^^^^^^^^^^
405-
406-
Let's start by looking at what we at OSRF know we can do better or differently and move on from there.
407-
408-
Performance, Performance, Performance
409-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
410-
411-
This is a very rough first draft. There is a lot of room for improvement, even beyond what has been enumerated above. We'll start to improve performance as we dig into the details of the system, build up a better understanding of exactly what our middleware vendors are doing, and try alternative strategies for implementing intra process.
412-
413-
Latching
414-
~~~~~~~~
415-
416-
We haven't fully implemented the concept of latching yet, but it's very likely we'll need to adjust the implementation of the intra process manager to account for the fact that late intra process subscriptions should be delivered to as well. There are several options on how to do that, and we'll do some testing and figure out what to do in the near future.
417-
418-
Beyond Pub/Sub
419-
~~~~~~~~~~~~~~
420-
421-
We've not done any of this with Services, Parameters, or Actions, but we will.
422-
423-
Type Masquerading
424-
~~~~~~~~~~~~~~~~~
425-
426-
This is one of the coolest upcoming features that we didn't get to in this demo.
427-
Imagine the image pipeline demo above, but rather than passing ``sensor_msgs/Image``\ s around, you're publishing and subscribing to ``cv::Mat`` objects. This exists in ROS 1, see: https://wiki.ros.org/roscpp/Overview/MessagesSerializationAndAdaptingTypes
428-
429-
In ROS 1, this is accomplished by serializing/deserializing the third party type when handling it. This means that with intra process you'll be serializing when passing it between nodelets. But in ROS 2 we want to do it in the most performant way possible. Similar to how these demos have been demonstrating that an instance of a message can be used through the whole pipeline in certain cases, we'd like to do the same with third party types. So conceivably you could have the image pipeline with a single ``cv::Mat`` which never gets copied by the middleware. To do this requires some additional intelligence in the intra process manager, but we've already got a design and some proof of concepts in the works.
430-
431-
Given these features, hopefully there will come a point where you can trust the middleware to handle your data as efficiently as is possible. This will allow you to write performant algorithms without sacrificing modularity or introspection!

0 commit comments

Comments
 (0)