Intra-Process Communication between Components in Container
Is it possible to take advantage of Intra Process Comms (IPC) when starting nodes in a container? I've made an example, trying to made a basic subscriber and publisher and looking at the pointer address, it seems as though it only works when "manually" composing.
This just seems surprising given the text in the composable nodes tutorial, which seems to indicate manually composing should somehow be "equivalent" to the container route. Especially given that manually composing using a multi-threaded executor also works fine.
Find the demo project here. The following example outputs are directly taken from this.
Example Outputs
Expected
With multi-threaded executor
$ ros2 run ipc_demo manual_composition
[INFO] [1642518288.545003595] [ipc_talker]: Count: 0 Addr: 0x7f1dbc001300
[INFO] [1642518288.545393895] [ipc_listener]: Count: 0 Addr: 0x7f1dbc001300
[INFO] [1642518289.544906771] [ipc_talker]: Count: 1 Addr: 0x7f1dbc001400
[INFO] [1642518289.544989777] [ipc_listener]: Count: 1 Addr: 0x7f1dbc001400
[INFO] [1642518290.545010214] [ipc_talker]: Count: 2 Addr: 0x7f1dbc0032c0
[INFO] [1642518290.545243590] [ipc_listener]: Count: 2 Addr: 0x7f1dbc0032c0
[INFO] [1642518291.545039618] [ipc_talker]: Count: 3 Addr: 0x7f1dbc003f80
[INFO] [1642518291.545282153] [ipc_listener]: Count: 3 Addr: 0x7f1dbc003f80
[INFO] [1642518292.544973975] [ipc_talker]: Count: 4 Addr: 0x7f1db0001740
[INFO] [1642518292.545166314] [ipc_listener]: Count: 4 Addr: 0x7f1db0001740
Pointer addresses are the same, so should be working as expected.
Container
$ ros2 launch ipc_demo composition.launch.py
[INFO] [launch]: All log files can be found below /home/morten/.ros/log/2022-01-18-16-04-58-690321-agrirobot-44101
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [component_container-1]: process started with pid [44117]
[component_container-1] [INFO] [1642518299.060037442] [two_nodes]: Load Library: /home/morten/temp_ws/install/ipc_demo/lib/libtalker_component.so
[component_container-1] [INFO] [1642518299.061590715] [two_nodes]: Found class: rclcpp_components::NodeFactoryTemplate<composition::Talker>
[component_container-1] [INFO] [1642518299.061656586] [two_nodes]: Instantiate class: rclcpp_components::NodeFactoryTemplate<composition::Talker>
[INFO] [launch_ros.actions.load_composable_nodes]: Loaded node '/talker' in container '/two_nodes'
[component_container-1] [INFO] [1642518299.068096064] [two_nodes]: Load Library: /home/morten/temp_ws/install/ipc_demo/lib/liblistener_component.so
[component_container-1] [INFO] [1642518299.068447676] [two_nodes]: Found class: rclcpp_components::NodeFactoryTemplate<composition::Listener>
[component_container-1] [INFO] [1642518299.068460910] [two_nodes]: Instantiate class: rclcpp_components::NodeFactoryTemplate<composition::Listener>
[INFO] [launch_ros.actions.load_composable_nodes]: Loaded node '/listener' in container '/two_nodes'
[component_container-1] [INFO] [1642518300.067406025] [talker]: Count: 0 Addr: 0x557f63f68960
[component_container-1] [INFO] [1642518300.067869433] [listener]: Count: 0 Addr: 0x557f63e42fd0
[component_container-1] [INFO] [1642518301.067393044] [talker]: Count: 1 Addr: 0x557f63e04720
[component_container-1] [INFO] [1642518301.067703912] [listener]: Count: 1 Addr: 0x557f64035980
[component_container-1] [INFO] [1642518302.067380956] [talker]: Count: 2 Addr: 0x557f64053c20
[component_container-1] [INFO] [1642518302.067666810] [listener]: Count: 2 Addr: 0x557f63e42fd0
Different pointer addresses between corresponding talker/listener message.