def execute():
# define publisher and its topic
pub = rospy.Publisher('read_coords',Int32,queue_size = 10)
rospy.init_node('report_coords_node',anonymous = True)
rate = rospy.Rate(10)
# report once
if len(sys.argv) == 1:
pub.publish(1)
time.sleep(0.1)
print 'Current location is x: %2.2fcm, y: %2.2fcm, z: %2.2fcm.' %(rospy.get_param('current_x'),rospy.get_param('current_y'),rospy.get_param('current_z'))
# report multiple time
elif len(sys.argv) == 2:
for i in range(0,int(sys.argv[1])):
pub.publish(1)
time.sleep(0.1)
print 'Current location is x: %2.2fcm, y: %2.2fcm, z: %2.2fcm.' %(rospy.get_param('current_x'),rospy.get_param('current_y'),rospy.get_param('current_z'))
elif len(sys.argv) == 3:
for i in range(0,int(sys.argv[1])):
pub.publish(1)
time.sleep(0.1)
print 'Current location is x: %2.2fcm, y: %2.2fcm, z: %2.2fcm.' %(rospy.get_param('current_x'),rospy.get_param('current_y'),rospy.get_param('current_z'))
time.sleep(float(sys.argv[2])-0.1)
else:
raiseError()
rate.sleep()
# main function
评论列表
文章目录