Note: This tutorial assumes that you have completed the previous tutorials: writing a simple publisher and subscriber (python) (c++). |
Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags. |
Examining the Simple Publisher and Subscriber
Description: This tutorial examines running the simple publisher and subscriber.Tutorial Level: BEGINNER
Next Tutorial: Writing a simple service and client (python) (c++)
Running the Publisher
Make sure that a roscore is up and running:
$ roscore
catkin specific If you are using catkin, make sure you have sourced your workspace's setup.sh file after calling catkin_make but before trying to use your applications:
# In your catkin workspace $ cd ~/catkin_ws $ source ./devel/setup.bash
In the last tutorial we made a publisher called "talker". Let's run it:
$ rosrun beginner_tutorials talker (C++) $ rosrun beginner_tutorials talker.py (Python)
You will see something similar to:
[INFO] [WallTime: 1314931831.774057] hello world 1314931831.77 [INFO] [WallTime: 1314931832.775497] hello world 1314931832.77 [INFO] [WallTime: 1314931833.778937] hello world 1314931833.78 [INFO] [WallTime: 1314931834.782059] hello world 1314931834.78 [INFO] [WallTime: 1314931835.784853] hello world 1314931835.78 [INFO] [WallTime: 1314931836.788106] hello world 1314931836.79
The publisher node is up and running. Now we need a subscriber to receive messages from the publisher.
Running the Subscriber
In the last tutorial we made a subscriber called "listener". Let's run it:
$ rosrun beginner_tutorials listener (C++) $ rosrun beginner_tutorials listener.py (Python)
You will see something similar to:
[INFO] [WallTime: 1314931969.258941] /listener_17657_1314931968795I heard hello world 1314931969.26 [INFO] [WallTime: 1314931970.262246] /listener_17657_1314931968795I heard hello world 1314931970.26 [INFO] [WallTime: 1314931971.266348] /listener_17657_1314931968795I heard hello world 1314931971.26 [INFO] [WallTime: 1314931972.270429] /listener_17657_1314931968795I heard hello world 1314931972.27 [INFO] [WallTime: 1314931973.274382] /listener_17657_1314931968795I heard hello world 1314931973.27 [INFO] [WallTime: 1314931974.277694] /listener_17657_1314931968795I heard hello world 1314931974.28 [INFO] [WallTime: 1314931975.283708] /listener_17657_1314931968795I heard hello world 1314931975.28
When you are done, press Ctrl-C to terminate both the listener and the talker.
Now that you have examined the simple publisher and subscriber, let's write a simple service and client (python) (c++).
Video Demonstration
Watch the video below to have more explanation on Nodes Communication and step by step guide .