0
$\begingroup$

Rosanswers logo

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?


Originally posted by Raposa on ROS Answers with karma: 23 on 2021-09-10

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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'])
    ])

Originally posted by lukicdarkoo with karma: 486 on 2021-09-10

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.