Ask Your Question
0

ros2 topic pub from launch file

asked 2021-09-10 09:01:28 -0600

Raposa gravatar image

Hello everyone,

Does anyone know if it is possible in ros2 to directly start from launch file a simple node that publishes a message?

In ROS1 it was easily possible like this:

<node pkg="rostopic" type="rostopic" name="rostopic" args="pub {pub args}"/>

(reference from: https://answers.ros.org/question/230465/publish-to-topic-via-launch-file/)

I made a few tries in ROS2 adding an action for a node with similar parameterization in my launch description, but I don't really understand in this case what is the correct package and what is the executable for ros2 (or if it is not possible at all).

Of course I know it would be possible to define my own node that does that, instead of putting all in the launch file, but if I can avoid the added overhead as it was possible in ros1, it would be preferable.

Would anyone have a simple working example of this?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-09-10 16:24:11 -0600

You can use the ExecuteProcess action:

from launch import LaunchDescription
from launch.actions import ExecuteProcess


def generate_launch_description():
    return LaunchDescription([
        ExecuteProcess(cmd=['ros2', 'topic', 'pub', '/my_topic', 'std_msgs/String', 'data: 1'])
    ])
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

2 followers

Stats

Asked: 2021-09-10 09:01:28 -0600

Seen: 20 times

Last updated: Sep 10