Capture stdin using ros2 launch
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))
)
)
])