report_coords_node.py 文件源码

python
阅读 41 收藏 0 点赞 0 评论 0

项目:UArmForROS 作者: uArm-Developer 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号