suppressor.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # coding=utf-8
00003 
00004 __author__ = 'Minglong Li'
00005 
00006 import rospy
00007 import time
00008 import multiprocessing
00009 
00010 time_unit = 0.1
00011 time_unit_amount = 20
00012 time_start = 0.0
00013 
00014 class Suppressor(multiprocessing.Process):
00015     def __init__(self):
00016         multiprocessing.Process.__init__(self)
00017         self.node_name = 'suppressor'
00018         self.sub1 = rospy.Subscriber("/avoid/suppressor/heading", Heading, avoid_headingCB)
00019         self.sub2 = rospy.Subscriber("/runaway/suppressor/heading", Heading, runaway_headingCB)
00020     
00021     def run(self):
00022         rospy.init_node(self.node_name)
00023 
00024     def avoid_headingCB(msg):
00025         global time_start
00026         time_start = time.time()
00027         pub_heading = rospy.Publisher('/suppressor/turn/heading', Heading, queue_size=10)       
00028         pub_heading.publish(msg)        
00029         print "The upper layer published successfully!" 
00030 
00031     def runaway_headingCB(msg):
00032         global time_unit
00033         global time_unit_amount
00034         global time_start
00035         time_end = time.time()
00036         pub_heading = rospy.Publisher('/suppressor/turn/heading', Heading, queue_size=10)       
00037         if (time_end - time_start) > (time_unit * time_unit_amount):
00038             pub_heading.publish(msg)
00039         print "The upper layer didn't work, the lower layer instead!"
00040 
00041     def avoid_runaway_suppressor():
00042         rospy.spin()
00043 
00044 if __name__ == '__main__':
00045         try:
00046                 pass
00047         except rospy.ROSInterruptException:
00048                 print "Program interrupted before completion"


micros_mars_task_alloc
Author(s): Minglong Li , Xiaodong Yi , Yanzhen Wang , Zhongxuan Cai
autogenerated on Mon Jul 1 2019 19:55:03