report_stopper_node.py 文件源码

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

项目:UArmForROS 作者: uArm-Developer 项目源码 文件源码
def execute():

    # define publisher and its topic 
    pub = rospy.Publisher('stopper_status',Int32,queue_size = 10)
    rospy.init_node('report_stopper_node',anonymous = True)
    rate = rospy.Rate(10)

    # report once
    if len(sys.argv) == 1:

        pub.publish(1)
        time.sleep(0.1)
        status = rospy.get_param('stopper_status')

        if status == 'HIGH':
            print 'Stopper is actived'
        elif status == 'LOW':
            print 'Stopper is not actived'

    # report multiple time
    elif len(sys.argv) == 2:
        for i in range(0,int(sys.argv[1])):
            pub.publish(1)
            time.sleep(0.1)

            status = rospy.get_param('stopper_status')
            if status == 'HIGH':
                print 'Stopper is actived'
            elif status == 'LOW':
                print 'Stopper is not actived'

    elif len(sys.argv) == 3:
        for i in range(0,int(sys.argv[1])):

            pub.publish(1)
            time.sleep(0.1)

            status = rospy.get_param('stopper_status')
            if status == 'HIGH':
                print 'Stopper is actived'
            elif status == 'LOW':
                print 'Stopper is not actived'
            time.sleep(float(sys.argv[2])-0.1)
    else: 
        raiseError()

    rate.sleep()

# main function
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号