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
评论列表
文章目录