ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
launch_ros.actions.Node
inherits from launch.actions.ExecuteProcess
, and it passes extra arguments given to __init__
to it. I think you're looking for prefix.
Save this file as gdb_pub_launch.py
from launch import LaunchDescription
from launch import LaunchService
import launch_ros.actions
def generate_launch_description():
"""Run demo nodes via launch."""
ld = LaunchDescription([
launch_ros.actions.Node(
package='demo_nodes_cpp', node_executable='talker', output='screen',
remappings=[('chatter', 'my_chatter')],
prefix=['gdb -ex=r --args'],
)
])
return ld
And run with
ros2 launch gdb_pub_launch.py
2 | No.2 Revision |
EDIT
There is new discussion about this answer not being able to interact with GDB because launch doesn't allow a process to access stdin. That discussion is on an issue in the launch_ros repo.
One workaround is to add xterm -e
to the start of the prefix to open an new xterm window with the process. In this case, use the prefix xterm -e gdb -ex=r --args
.
There's another very similar question and answer in https://answers.ros.org/question/267261/how-can-i-run-ros2-nodes-in-a-debugger-eg-gdb/
Original answer
launch_ros.actions.Node
inherits from launch.actions.ExecuteProcess
, and it passes extra arguments given to __init__
to it. I think you're looking for prefix.
Save this file as gdb_pub_launch.py
from launch import LaunchDescription
from launch import LaunchService
import launch_ros.actions
def generate_launch_description():
"""Run demo nodes via launch."""
ld = LaunchDescription([
launch_ros.actions.Node(
package='demo_nodes_cpp', node_executable='talker', output='screen',
remappings=[('chatter', 'my_chatter')],
prefix=['gdb -ex=r --args'],
)
])
return ld
And run with
ros2 launch gdb_pub_launch.py
3 | No.3 Revision |
EDIT
There is new discussion about this answer not being able to interact with GDB because launch doesn't allow a process to access stdin. That discussion is on an issue in the launch_ros repo.
One workaround is to add xterm -e
to the start of the prefix to open an new xterm window with the process. In this case, use the prefix xterm -e gdb -ex=r --args
.
There's another very similar question and answer in https://answers.ros.org/question/267261/how-can-i-run-ros2-nodes-in-a-debugger-eg-gdb/#q267261
Original answer
launch_ros.actions.Node
inherits from launch.actions.ExecuteProcess
, and it passes extra arguments given to __init__
to it. I think you're looking for prefix.
Save this file as gdb_pub_launch.py
from launch import LaunchDescription
from launch import LaunchService
import launch_ros.actions
def generate_launch_description():
"""Run demo nodes via launch."""
ld = LaunchDescription([
launch_ros.actions.Node(
package='demo_nodes_cpp', node_executable='talker', output='screen',
remappings=[('chatter', 'my_chatter')],
prefix=['gdb -ex=r --args'],
)
])
return ld
And run with
ros2 launch gdb_pub_launch.py