A publisher is a node that broadcasts messages on a topic. It has to do the following:
A subscriber is a node that receives the broadcasted messages on a topic. It's basically like a listener. It has to do the following:
Let's create a publisher that publishes a number (of message type std_msgs/Float64) and a subscriber that listens to those. We'll let the topic name be /floating_numbers. We'll publish two messages a second here, but you could pick any rate (or choose not to publish in a rate).
The file name is "NumberPublisher.cpp". The following is the manner in which it is programmed:
The file name is "NumberSubscriber.cpp". The following is the manner in which it is programmed:
catkin_make
on the workspace home directoryroscore
rosrun intro_pkg1 NumberPublisher
rostopic echo /floating_numbers
rosrun intro_pkg1 NumberSubscriber
Publisher made using C++
Subscriber made using C++
The file name is "NumberPublisher.py". It has been programmed in the following manner:
The file name is "NumberSubscriber.py". It has been programmed in the following manner:
roscd intro_pkg1/scripts
chmod +x *.py
rosrun intro_pkg1 NumberPublisher.py
rosrun intro_pkg1 NumberSubscriber.py
Publisher made using Python
Subscriber made using Python