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

Capture stdin using ros2 launch

asked 2022-04-01 11:50:30 -0600

bjoernolav gravatar image

In ROS1, I've successfully used pdb to debug ROS nodes launched using roslaunch. Moving to ROS2 (Galactic/Ubuntu 20.04LTS), I'm struggling with this, and invoking pdb in a node prints output to the terminal using output=screen, but stdin of the ros2 launch ... process is not connected to the node.

Experimenting and looking through the code and event tutorials, I've managed to connect the stdout of a node to a OnProcessIO event, but I've not found any way of capturing and forwarding the stdin of the launch process to the node.

I would be very happy for any suggestions!

A MWE of the launch file with an OnProcessIO event handler for reading the nodes stdout:

from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import RegisterEventHandler, LogInfo
from launch.event_handlers import OnProcessIO, OnProcessStart
from ament_index_python.packages import get_package_share_directory


def generate_launch_description():
    node = Node(
            package='ros_mpcs',
            namespace='',
            executable='reference_generator',
            #output='screen',
            name='reference_generator',
            emulate_tty=True
        )
    return LaunchDescription([
        node,
        RegisterEventHandler(
            OnProcessStart(
                target_action=node,
                on_start=[
                    LogInfo(msg='Node started!!!!!')
                ]
            )
        ),
        RegisterEventHandler(
            OnProcessIO(
                target_action=node,
                on_stdout= lambda event: LogInfo(msg='STDOUT: {}'.format(event))
            )
        )
    ])
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-05-23 03:42:24 -0600

AlexKaravaev gravatar image

The only way I found is to capture stdin in ROS2 is by appending prefix="xterm -e" to the Node() and launching node in xterm

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-04-01 11:50:30 -0600

Seen: 932 times

Last updated: May 23 '22