Ask Your Question
6

Remotely Launch Nodes in ROS2

asked 2020-10-26 06:30:10 -0500

smorad gravatar image

Is there a way to remotely launch nodes in ROS2? This could be done in ROS1 using the <machine> attribute. It's listed in the ROS2 design document but I can't figure out how to use it. I'm using the python launch and launch_ros libraries.

edit retag flag offensive close merge delete

Comments

Hi. Same need. I didn't find into the documentation...

resnault gravatar image resnault  ( 2021-04-01 03:34:10 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2022-04-26 06:23:11 -0500

afrixs gravatar image

updated 2022-04-26 11:59:52 -0500

I've just found a way to perform a remote launch from a python launch file using the ExecuteProcess launch action. There are several problems you're going to face if you go this way, so here are the workarounds I used to solve them (on Ubuntu 20.04).

First, let's state what we are trying to achieve:

  1. We have a main machine A and a machine B reachable via ssh pi@192.168.0.20 from machine A (without a password, i.e. use ssh-keygen -t rsa -b 2048 && ssh-copy-id pi@192.168.0.20 first)
  2. We have a launch file drinks_hmi_launch.py in drinks_hmi_bringup package on machine B (we can launch it from machine B via ros2 launch drinks_hmi_bringup drinks_hmi_launch.py)
  3. We have a launch file drinks_bringup_launch.py in drinks_bringup package on machine A which is supposed (among other actions) to launch drinks_hmi_launch.py on machine B

Now the following command should work from machine A, i.e. it launches the nodes, prints out output and can be terminated via SIGINT (Ctrl+C):

ssh -t pi@192.168.0.20 'bash -i -c "ros2 launch drinks_hmi_bringup drinks_hmi_launch.py"'

However, after putting it directly into ExecuteProcess action in drinks_bringup_launch.py, the process complains about not having a proper tty console and the nodes on machine B are not terminated after terminating the ros2 launch drinks_bringup drinks_bringup_launch.py process.

A workaround is to call the above command inside a detached screen (use sudo apt install screen if not present). This, however, raises two further problems:

  • The screen does not pass SIGINT from calling process to inner processes, so it does not terminate the nodes when Ctrl+C is pressed. However it can be terminated explicitly using a remote_launch_terminator node which calls screen -S hmi -X quit (see the complete solution below)
  • The screen does not pass output from inner processes to calling process, so this needs to be done explicitly by redirecting inner output to outer

The complete solution is as follows:

/home/machine_A/drink_ws/src/launch_utils/launch_utils/remote_launch_terminator.py:

import rclpy
from rclpy.node import Node
import os

def main(args=None):
    rclpy.init(args=args)

    node = Node('remote_launch_terminator')
    node.declare_parameter('screen_pid', 'remote')
    screen_pid = node.get_parameter('screen_pid').get_parameter_value().string_value

    try:
        rclpy.spin(node)
    except:
        pass

    print('Terminating ' + screen_pid)
    os.system('screen -S ' + screen_pid + ' -X quit')

if __name__ == '__main__':
    main()

/home/machine_A/drink_ws/src/drinks_bringup/launch/drinks_bringup_launch.py:

import os

from ament_index_python.packages import get_package_share_directory

from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions.execute_process import ExecuteProcess

def generate_launch_description():
    return LaunchDescription([

        # other actions

        # remote launch
        ExecuteProcess(
            name='hmi',
            cmd=['{ outer_stdout=$(readlink -f /proc/self/fd/3); } 3>&1 && screen -DmS hmi bash -i -c "ssh -t pi@192.168.0.20 \'bash -i -c \\"ros2 launch drinks_hmi_bringup drinks_hmi_launch.py\\"\' > $outer_stdout"'],
            output="screen",
            shell=True,
            emulate_tty=True
        ),
        Node(
            package='launch_utils',
            executable='remote_launch_terminator',
            name='remote_launch_terminator',
            output='screen',
            parameters=[{'screen_pid': 'hmi'}]
        ),
    ])

Hope this helps, cheers! ;)

Note: ExecuteProcess action does not work inside OnShutdown event, that's why ... (more)

edit flag offensive delete link more
0

answered 2021-06-07 23:16:00 -0500

shonigmann gravatar image

updated 2021-06-07 23:17:44 -0500

As far as I can tell, this is still a work in progress, but has been on the backlog to get merged into the documentation. Lots of discussion here, and it seems the change to the documentation is awaiting approval to get merged in.

The tentative document can be found here, but it doesn't look like the proposed changes have made their way into code yet.

I'd imagine it is pretty low priority because ssh is possible on all the tier 1 platforms (ever since Windows joined the club).

edit flag offensive delete link more

Comments

It has been quite some time since this was posted. Could anyone comment on when support for remote-launching nodes via roslaunch can be expected to make it into ROS2?

alikureishy gravatar image alikureishy  ( 2022-02-17 14:04:33 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

5 followers

Stats

Asked: 2020-10-26 06:27:28 -0500

Seen: 334 times

Last updated: Apr 26