In this post, we will see what a ROS publisher is all about in just about five minutes! We’ll also see how it relates to ROS nodes and topics.
Step 1: Grab a copy of the Project (ROSject) on ROSDS
Once you have copied the project, open it up.
Step 2: Run the
Pick a Shell from the Tools menu and run the following commands.
First, start the ROS master – we need this to run any ROS commands. We’re starting this program in the background:
user:~$ nohup roscore &  1501 user:~$ nohup: ignoring input and appending output to 'nohup.out' user:~$
Before we proceed, let’s check the ROS topics currently available:
user:~$ rostopic list /rosout /rosout_agg
Now start the
user:~$ cd catkin_ws/src user:~/catkin_ws/src$ ./obiwan_pub.py
Again, check the list of available ROS topics. Pick another Shell from the Tools menu and run:
user:~$ rostopic list /help_msg /rosout /rosout_agg
Now we have a new topic
/help_msg, obviously created by the
obiwan_pub.py program. Running it is the only thing we have done since the last time we checked the list of messages, right?
Okay, do not take my word for it; let’s spy on the
/help_msg topic to confirm:
user:~$ rostopic info /help_msg Type: std_msgs/String Publishers: * /sos_2 (http://rosdscomputer:38619/) Subscribers: None
Now we know that that topic uses a message of type
std_msgs/String and has a Publisher named
But what has this got to with the
obiwan_pub node? Everything – let’s see that in the next step.
Step 3: Unravel the mysterious “Publisher”
In the previous step, we saw that
/sos_2 was listed as a Publisher on the topic
/help_msg, and we suspected that this has to do with the
obiwan_pub.py program. Now, let’s examine the
obiwan_pub.py code to see if we have some clues.
#! /usr/bin/env python import rospy from std_msgs.msg import String rospy.init_node("sos_2") rate = rospy.Rate(2) help_msg = String() help_msg.data = "help me Obi-Wan Kenobi, you're my only hope" pub = rospy.Publisher('/help_msg', String, queue_size = 1) while not rospy.is_shutdown(): pub.publish(help_msg) rate.sleep()
On line 6, we have the statement
rospy.init_node("sos_2"), so we now know that:
/sos_2was created by this program!
/sos_2is a ROS node, because it says
Also on line 10, we have this statement:
pub = rospy.Publisher('/help_msg', String, queue_size = 1), confirming that:
- The code actually creates a
Step 4: Master the Concept – What is a ROS Publisher?
Combining all the points in the previous steps, we can see that a ROS Publisher…
- is a ROS node (program).
- creates a particular type of ROS message. In this case, it’s
std_msgs/String, as can be seen on lines 4,7-8 of the code.
- sends (publishes) a message over a channel called “topic”, as can be seen on lines 10 then 12 of the code.
In short, a ROS publisher is a ROS node that publishes a specific type of ROS message over a given ROS topic. “Interested” nodes (Subscribers) can access messages so published.
And that was it!
Prefer to watch a video demonstrating the steps above? We have one for you below!
- A previous video about ROS nodes: [irp posts=”10305″ name=”ROS in 5 mins – 005 – What is a ROS Node?”]
If you are a ROS beginner and want to learn ROS basics fast, we recommend you take any of the following courses on Robot Ignite Academy:
Did you like this post? Whatever the case, please leave a comment in the comments section below, so we can interact and learn from each other.
If you want to learn about other ROS topics, please let us know in the comments area and we will do a post or video about it.