You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/Tutorials/Demos/Intra-Process-Communication.rst
+12-17Lines changed: 12 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,12 +31,12 @@ If you downloaded the archive or built ROS 2 from source, it will already be par
31
31
Running and understanding the demos
32
32
-----------------------------------
33
33
34
-
There are a few different demos: some are toy problems designed to highlight features of the intraprocess communications functionality and some are end to end examples which use OpenCV and demonstrate the ability to recombine nodes into different configurations.
34
+
There are a few different demos: some are toy problems designed to highlight features of the intra-process communications functionality and some are end to end examples which use OpenCV and demonstrate the ability to recombine nodes into different configurations.
35
35
36
36
The two node pipeline demo
37
37
^^^^^^^^^^^^^^^^^^^^^^^^^^
38
38
39
-
This demo is designed to show that the intraprocess publish/subscribe connection can result in zero-copy transport of messages when publishing and subscribing with ``std::unique_ptr``\ s.
39
+
This demo is designed to show that the intra-process publish/subscribe connection can result in zero-copy transport of messages when publishing and subscribing with ``std::unique_ptr``\ s.
40
40
41
41
First let's take a look at the source:
42
42
@@ -131,7 +131,7 @@ If you look at the "producer" node's implementation in the ``Producer`` struct,
131
131
The "consumer" node is a bit simpler, you can see its implementation in the ``Consumer`` struct, as it only subscribes to the "number" topic and prints the address and value of the message it receives.
132
132
133
133
The expectation is that the producer will print out an address and value and the consumer will print out a matching address and value.
134
-
This demonstrates that intraprocess communication is indeed working and unnecessary copies are avoided, at least for simple graphs.
134
+
This demonstrates that intra-process communication is indeed working and unnecessary copies are avoided, at least for simple graphs.
135
135
136
136
Let's run the demo by executing ``ros2 run intra_process_demo two_node_pipeline`` executable (don't forget to source the setup file first):
137
137
@@ -318,7 +318,7 @@ The ``camera_node`` reads from camera device ``0`` on your computer, writes some
318
318
The ``watermark_node`` subscribes to the output of the ``camera_node`` and adds more text before publishing it too.
319
319
Finally, the ``image_view_node`` subscribes to the output of the ``watermark_node``, writes more text to the image and then visualizes it with ``cv::imshow``.
320
320
321
-
In each node the address of the message which is being sent, or which has been received, or both, is written to the image.
321
+
In each node the process id and the pointer address of the ROS message is written onto the image with ``cv::putText``.
322
322
The watermark and image view nodes are designed to modify the image without copying it and so the addresses imprinted on the image should all be the same as long as the nodes are in the same process and the graph remains organized in a pipeline as sketched above.
323
323
324
324
.. note::
@@ -348,7 +348,7 @@ Pipeline with two image viewers
348
348
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
349
349
350
350
Now let's look at an example just like the one above, except it has two image view nodes.
351
-
All the nodes are still in the same process, but now two image view windows should show up.
351
+
All the nodes are still in the same process, but now there will be two instances of the ``image_view_node`` and so two image view windows should show up.
352
352
(Note for macOS users: your image view windows might be on top of each other).
353
353
Let's run it with the command:
354
354
@@ -371,21 +371,16 @@ To understand why this is happening consider the graph's topology:
371
371
camera_node -> watermark_node -> image_view_node
372
372
-> image_view_node2
373
373
374
-
The link between the ``camera_node`` and the ``watermark_node`` can use the same pointer without copying because there is only one intraprocess subscription to which the message should be delivered.
374
+
The link between the ``camera_node`` and the ``watermark_node`` can use the same pointer without copying because there is only one intra-process subscription to which the message should be delivered.
375
375
But for the link between the ``watermark_node`` and the two image view nodes the relationship is one to many, so if the image view nodes were using ``unique_ptr`` callbacks then it would be impossible to deliver the ownership of the same pointer to both.
376
376
It can be, however, delivered to one of them.
377
377
Which one would get the original pointer is not defined, but instead is simply the last to be delivered.
378
+
And so one of the images being viewed is the original, with all the pointers the same, and the other is a copy of the original image, made between the ``watermark_node`` and one of the ``image_view_node`` instances, which will have a different pointer for the third line of text.
378
379
379
-
Note that the image view nodes are not subscribed with ``unique_ptr`` callbacks.
380
-
Instead they are subscribed with ``const shared_ptr``\ s.
381
-
This means the system deliveres the same ``shared_ptr`` to both callbacks.
382
-
When the first intraprocess subscription is handled, the internally stored ``unique_ptr`` is promoted to a ``shared_ptr``.
383
-
Each of the callbacks will receive shared ownership of the same message.
380
+
Pipeline with inter-process viewer
381
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
384
382
385
-
Pipeline with interprocess viewer
386
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
387
-
388
-
One other important thing to get right is to avoid interruption of the intra process zero-copy behavior when interprocess subscriptions are made.
383
+
One other important thing to get right is to avoid interruption of the intra-process zero-copy behavior when inter-process subscriptions are made.
389
384
To test this we can run the first image pipeline demo, ``image_pipeline_all_in_one``, and then run an instance of the stand alone ``image_view_node`` (don't forget to prefix them with ``ros2 run intra_process_demo`` in the terminal).
390
385
This will look something like this:
391
386
@@ -394,5 +389,5 @@ This will look something like this:
394
389
395
390
396
391
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.
397
-
This means that the intraprocess zero-copy is preserved even when an external view is subscribed as well.
398
-
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.
392
+
This means that the intra-process zero-copy is preserved even when an external view is subscribed as well.
393
+
You can also see that the inter-process 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.
0 commit comments