Robotics StackExchange | Archived questions

ros2 launchfiles: how to launch nodes that are in the same executable?

Hello all,

I am trying to launch three nodes that are in the same executable to enable intra process communication. In the launchfile I need to create start actions for each of them using:

  visualizer_node = launch_ros.actions.LifecycleNode(
        node_name='visualizer',
        package='modulo_core', node_executable="modulo_core_test_cartesian", output='screen')

  robot_interface_node = launch_ros.actions.LifecycleNode(
        node_name='robot_interface',
        package='modulo_core', node_executable="modulo_core_test_cartesian", output='screen')

  motion_generator_node = launch_ros.actions.LifecycleNode(
        node_name='motion_generator',
        package='modulo_core', node_executable="modulo_core_test_cartesian", output='screen')

As those are lifecycle nodes the rest is just to configure and activate them. The problem with that approach is that it will start the executable modulo_core_test_cartesian 3 times, resulting in 3 versions of the node conflicting. See the output of ros2 node list:

/launch_ros
/motion_generator
/motion_generator
/motion_generator
/robot_interface
/robot_interface
/robot_interface
/transform_listener_impl_561d275bf460
/transform_listener_impl_561d279b2de0
/transform_listener_impl_561d27d1d390
/transform_listener_impl_563539d7e980
/transform_listener_impl_56353a0e9080
/transform_listener_impl_56353a60d5a0
/transform_listener_impl_5648cc1556a0
/transform_listener_impl_5648cc54f770
/transform_listener_impl_5648cc8b9f00
/visualizer
/visualizer
/visualizer

I don't know how to properly handle this. I have read about compositions on the wiki but I am not sure this will allow me intra process communication. Any ideas on the proper method?

Thanks in advance.

Asked by buschbapti on 2019-10-04 04:55:15 UTC

Comments

Please note: ROS Answers does not support markdown, so three backticks do not start (or end) a code block.

Asked by gvdhoorn on 2019-10-04 06:30:52 UTC

Oh sorry for that. Good to know thanks

Asked by buschbapti on 2019-10-04 06:36:09 UTC

Answers

I guess if you launch executable it will run everything you wrote there, without determining which node to start. So you should write three different executables for each node or one executable with parameter - in that case your executable will run single desired node depending on parameter value.

EDIT. I don't remember what actually node_name parameter do, but I can imagine it replaces names of each node you launch with this launch_ros.actions.LifecycleNode. I.e.

visualizer_node = launch_ros.actions.LifecycleNode( node_name='visualizer', package='modulo_core', node_executable="modulo_core_test_cartesian", output='screen')

runs three nodes called /visualizer.

Asked by Dmitriy on 2019-10-04 05:59:41 UTC

Comments

Thanks for your reply but I think that is not an option... Otherwise how can we use intra process communication? If nodes are in different executables or executed in a different processes then this feature is lost. Is this a case that can't be handled at the current stage of development?

Asked by buschbapti on 2019-10-04 06:04:53 UTC

Check this: https://index.ros.org//doc/ros2/Tutorials/Intra-Process-Communication/

I do think you just don't need to provide node_name argument in launch file. But yes, they run two nodes with just one executable.

Asked by Dmitriy on 2019-10-04 06:08:38 UTC

Thanks for the link this is exactly what I am doing in the executable and it correctly runs the 3 nodes. But here they don't use a launchfile. They directly use ros2 run which works fine for me as well. Problem is as the nodes I am using are lifecycle nodes I have to configure and activate them by hand afterwards which is very annoying. That is why I would like to put everything in a single launch file. Your suggestion to not use node_name does not seem to work:

ERROR] [launch]: Caught exception in launch (see debug for traceback): Caught exception when trying to load file of format [py]: __init__() missing 1 required keyword-only argument: 'node_name'

Asked by buschbapti on 2019-10-04 06:21:40 UTC

As I believed, the current implementation does not allow this. I have raised this as an issue on github and it was confirmed (see https://github.com/ros2/rclcpp/issues/880).

So for reference, it seems the only way for now is to use compositions as in https://github.com/ros2/demos/blob/master/composition/launch/composition_demo.launch.py

There should be a possibility to add intra process communication using composition.

Asked by buschbapti on 2019-10-04 10:08:32 UTC

Comments