string_pub_node.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 """ A dummy ROS node """
00004 from __future__ import absolute_import
00005 
00006 import common
00007 import sys
00008 
00009 import rospy
00010 import std_msgs
00011 
00012 # TODO : implement service to check if pub
00013 
00014 if __name__ == '__main__':
00015     try:
00016         args = rospy.myargv(argv=sys.argv)
00017         node_name = args[1] if len(args) > 1 else 'string_pub_node'
00018 
00019         rospy.init_node(node_name)
00020         rospy.loginfo('String Pub node started. [' + rospy.get_name() + ']')
00021 
00022         topic_name = rospy.get_param("~topic_name", "")
00023         print 'Parameter {0!s} has value {1!s}'.format(rospy.resolve_name('~topic_name'), topic_name)
00024         if topic_name == "":
00025             print "{0} parameter not found".format(rospy.resolve_name('~topic_name'))
00026             raise common.TestArgumentNotFound
00027         test_message = rospy.get_param("~test_message", "")
00028         print 'Parameter {0!s} has value {1!s}'.format(rospy.resolve_name('~test_message'), test_message)
00029         if test_message == "":
00030             print "{0} parameter not found".format(rospy.resolve_name('~test_message'))
00031             raise common.TestArgumentNotFound
00032 
00033         pub = rospy.Publisher(topic_name, std_msgs.msg.String, queue_size=1)
00034 
00035         rate = rospy.Rate(10)  # 10hz
00036         while not rospy.is_shutdown():
00037             pub.publish(test_message)
00038             rate.sleep()
00039 
00040     except rospy.ROSInterruptException:
00041         pass


pyros_test
Author(s): AlexV
autogenerated on Sat Jun 8 2019 20:51:06