> For the complete documentation index, see [llms.txt](https://ptandur14.gitbook.io/everything-about-drone/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ptandur14.gitbook.io/everything-about-drone/ros-robotic-operating-system/examples/publisher-in-ros.md).

# Publisher in ROS

#### The publisher node will publish the type of data and the data on the topic

#### Following commands should be ran in the terminal

* $ roscd beginner\_tutorials
* $ mkdir scripts
* $ cd scripts

Make a new file and name it talker.py

```
   #!/usr/bin/env python
    # license removed for brevity
    import rospy
    from std_msgs.msg import String
    
    def talker():
        pub = rospy.Publisher('chatter', String, queue_size=10)
        rospy.init_node('talker', anonymous=True)
        rate = rospy.Rate(10) # 10hz
       while not rospy.is_shutdown():
           hello_str = "hello world %s" % rospy.get_time()
           rospy.loginfo(hello_str)
           pub.publish(hello_str)
           rate.sleep()
   
   if __name__ == '__main__':
       try:
           talker()
       except rospy.ROSInterruptException:
           pass

```

$ chmod +x talker.py (Write this command to make the file executable)

![](https://2337796245-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LiHGnU31k3UMwGKWEZa%2F-Lkc5jobdbh-XgErDntH%2F-Lkc62SaBLP8_uzNFIiG%2FMVIMG_20190718_181349.jpg?alt=media\&token=ef8155a5-e76b-40d3-8973-efa3c28c6e3d)
