Template for a Simple ROS Subscriber and Publisher in Python

A few days ago I started writing a series of tutorials that ease the work of beginners in ROS. The first tutorial was about a template for a publisher node, and the second tutorial was about a template for a subscriber node in ROS.

Today, I continue the series of tutorials with a template for a publisher and a subscriber node in Python. In addition, I’ll test it by writing and running a publisher and subscriber node.

Template for a Simple ROS Subscriber and Publisher in Python (image source)

Copy the template into a ‘. py’ file, delete the information that you don’t need and replace the text in capital letters.

I used the above template to write a ROS node that will display the random numbers received from another node, then I add some conditional statements, and finally I publish the results.

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 publisher and 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!