ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Intra-Process Communication between Components in Container

asked 2022-01-18 09:10:50 -0600

morten gravatar image

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-02-22 07:36:04 -0600

morten gravatar image

updated 2022-02-22 07:36:18 -0600

Way down the road found a way to make it work, no one's responded so I'll post my own answer. See here, an example launch file which accomplishes my desired goal.

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


def generate_launch_description():
    container = ComposableNodeContainer(
        name="two_nodes",
        namespace="",
        package="rclcpp_components",
        executable="component_container",
        composable_node_descriptions=[
            ComposableNode(
                package="ipc_demo",
                plugin="composition::Talker",
                name="talker",
                extra_arguments=[{"use_intra_process_comms": True}],
            ),
            ComposableNode(
                package="ipc_demo",
                plugin="composition::Listener",
                name="listener",
                extra_arguments=[{"use_intra_process_comms": True}],
            ),
        ],
        output="screen",
    )

    return launch.LaunchDescription([container])
edit flag offensive delete link more

Comments

Is ipc_demo your personal package? I'm wondering how you handled any modifications to CPP source (possibly from composition demos) to adapt it to intra process?

jeremya gravatar image jeremya  ( 2022-04-05 10:11:32 -0600 )edit

Question Tools

3 followers

Stats

Asked: 2022-01-18 09:10:50 -0600

Seen: 272 times

Last updated: Feb 22 '22