test_bm.py
Go to the documentation of this file.
00001 #! /usr/bin/python
00002 
00003 import roslib
00004 roslib.load_manifest("kelsey_sandbox")
00005 import rospy
00006 
00007 from behavior_manager import BehaviorManagerClient, clear_behavior_manager, BMPriorities
00008 
00009 class BMCWrapper(object):
00010     def __init__(self, name, priority):
00011         self.name = name
00012         self.priority = priority
00013         self.bmc = BehaviorManagerClient('l_arm', self.preempt_cb, self.resume_cb, priority=priority, name=name)
00014 
00015     def request(self):
00016         print "Request", self.name
00017         result = self.bmc.request()
00018         print "Request result:", self.name, result
00019         return result
00020 
00021     def relinquish(self):
00022         print "Relinquish", self.name
00023         self.bmc.relinquish()
00024 
00025     def preempt_cb(self):
00026         print "preempt", self.name, self.priority
00027 
00028     def resume_cb(self):
00029         print "resume", self.name, self.priority
00030 
00031     def create_timer(self, start_time, sleep_time):
00032         self.sleep_time = sleep_time
00033         def thread(te):
00034             if self.request():
00035                 rospy.sleep(self.sleep_time)
00036                 self.relinquish()
00037         rospy.Timer(rospy.Duration(start_time), thread, oneshot=True)
00038 
00039 def main():
00040     rospy.init_node("test_bm")
00041     p_low = BMPriorities.LOW
00042     p_med = BMPriorities.MEDIUM
00043     p_high = BMPriorities.HIGH
00044 
00045     clear_behavior_manager()
00046     bmcw_low = BMCWrapper("test_low", p_low)
00047     bmcw_med = BMCWrapper("test_med", p_med)
00048     bmcw_high = BMCWrapper("test_high", p_high)
00049 
00050     if True:
00051         bmcw_low.create_timer(0.01, 15)
00052         bmcw_med.create_timer(5, 5)
00053 
00054         bmcw_low.create_timer(25, 25)
00055         bmcw_med.create_timer(30, 10)
00056         bmcw_high.create_timer(35, 10)
00057         rospy.spin()
00058 
00059     if True:
00060         bmcw_med.create_timer(0.01, 20)
00061         bmcw_low.create_timer(5, 10)
00062         bmcw_high.create_timer(10, 5)
00063         rospy.spin()
00064 
00065 if __name__ == "__main__":
00066     main()


kelsey_sandbox
Author(s): kelsey
autogenerated on Wed Nov 27 2013 11:52:04