Skip to content

Instantly share code, notes, and snippets.

@detik19
Last active August 29, 2015 14:12
Show Gist options
  • Save detik19/70f46602666cf8174956 to your computer and use it in GitHub Desktop.
Save detik19/70f46602666cf8174956 to your computer and use it in GitHub Desktop.
Simple Publisher Using Rospy
#!/usr/bin/env python
import roslib; roslib.load_manifest('beginner_tutorials')
import rospy
from std_msgs.msg import String
def talker():
pub = rospy.Publisher('chatter', String)
rospy.init_node('talker')
while not rospy.is_shutdown():
#subtitute the time to message
str="Hello ROS World %s" % rospy.get_time()
#loginfo()
#gets the message printed to screen
#gets it written to the Node's log file
#gets it written to rosout
rospy.loginfo(str)
pub.publish(String(str))
rospy.sleep(1.0)
if __name__== '__main__':
try:
talker()
except rospy.ROSInterruptException:pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment