Everything about Drone
  • Drone (Dynamic Remotely Operated Navigation Equipment)
  • About Me
  • Types of Drones
  • Applications of Drone
  • Categories of Drones in India
  • Motor Configuration and Controls for Quadcopter
  • Assembling Pluto Drone
  • Dynamics of DRONEs
    • Force and Moments
    • Orientation and position
    • Moving in z, x & y direction
  • Sensors which are used on a Drone
  • Rules & Regulations
  • Testing & Executing codes
    • Acro Mode
    • Blow to Take Off
    • App Heading
    • Monitoring the Pressure Difference
    • Throw and Go
    • Flipping
  • Laser Cutting
  • Laser Cutting Procedure
  • 3D Printing Drone case
  • Table Tennis Game
  • ROS (Robotic Operating System)
    • ROS Master
    • ROS Nodes
    • ROS Topics
    • ROS Message
    • Workspace (catkin)
    • Examples
      • Creating ROS Workspace
      • Publisher in ROS
      • Subscriber in ROS
      • Testing Publisher and Subscriber nodes
      • Add two int in ROS
      • Building Nodes
      • Pluto Node
Powered by GitBook
On this page

Was this helpful?

  1. ROS (Robotic Operating System)
  2. Examples

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)

PreviousCreating ROS WorkspaceNextSubscriber in ROS

Last updated 5 years ago

Was this helpful?