Template for a ROS Publisher in Python

I do not like to memorize definitions, methods, procedures, etc., but I like to find solutions to help me reach my final goal.

In ROS, the structure of a simple node is repeated almost every time. To write the Publisher nodes as easily as possible, I’ve made a template that you can modify as you needed.

The template below represents a ROS Publisher node written in Python. All you have to do is to copy the template into a ‘. py’ file, delete the extra text and replace the text in capital letters.

I used the above template to make a ROS node that generates a random number between 0 and 5000.

To run the above node, navigate to the .py file and make it executable. The command is:

After the file is executable, you can run the node.

Step 1: open a new Terminal and run the command:

Step 2: open a new Terminal and run the node with the following command:

Leave a Comment

Your email address will not be published. Required fields are marked *

Don't Miss Out!

Get the latest news, tutorials, reviews and more direct to your inbox when you subscribe!