Template for a ROS Subscriber in Python

A few days ago I wrote a tutorial about a template for a Publisher node in Python. In the same tutorial, I used the template to write a ROS node to generate a random number.

Today, I continue the series of tutorials that ease the work of beginners in ROS, with a template for Subscriber in Python. In addition, in the article, you will find a template implementation with a ROS node that displays the data generated by the Publisher node from the previous tutorial.

Below you will find the template for a ROS Publisher node in Python. All you have to do is copy the text into a ‘. py’ file, delete the extra text and replace the text with capital letters.

I used the above template to write a ROS node that will display the random numbers sent by the node created to test the Publisher template.

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 Publisher node with the following command:

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

 

Share:

Related Posts

Don't Miss Out!

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