sleep_tool.py
Go to the documentation of this file.
00001 #import roslib; roslib.load_manifest('rcommander_core')
00002 import rospy
00003 from PyQt4.QtGui import *
00004 from PyQt4.QtCore import *
00005 import tool_utils as tu
00006 import smach
00007 
00008 class SleepTool(tu.ToolBase):
00009 
00010     def __init__(self, rcommander):
00011         tu.ToolBase.__init__(self, rcommander, 'sleep', 'Sleep', SleepState)
00012 
00013     def fill_property_box(self, pbox):
00014         formlayout = pbox.layout()
00015         self.time_box = QDoubleSpinBox(pbox)
00016         self.time_box.setMinimum(0)
00017         self.time_box.setMaximum(1000.)
00018         self.time_box.setSingleStep(.2)
00019         self.time_box.setValue(3.)
00020         formlayout.addRow("&Seconds", self.time_box)
00021 
00022     def new_node(self, name=None):
00023         if name == None:
00024             nname = self.name + str(self.counter)
00025         else:
00026             nname = name
00027         return SleepState(nname, self.time_box.value())
00028 
00029     def set_node_properties(self, my_node):
00030         self.time_box.setValue(my_node.sleep_time)
00031 
00032     def reset(self):
00033         self.time_box.setValue(3.)
00034 
00035 class SleepState(tu.StateBase):
00036 
00037     def __init__(self, name, sleep_time):
00038         tu.StateBase.__init__(self, name)
00039         self.sleep_time = sleep_time
00040 
00041     def get_smach_state(self):
00042         return SleepSmachState(self.sleep_time)
00043 
00044 class SleepSmachState(smach.State):
00045 
00046     def __init__(self, sleep_time):
00047         smach.State.__init__(self, outcomes=['preempted', 'done'], input_keys=[], output_keys=[])
00048         self.sleep_time = sleep_time
00049 
00050     def execute(self, userdata):
00051         r = rospy.Rate(30)
00052         start_time = rospy.get_time()
00053         while (rospy.get_time() - start_time) < self.sleep_time:
00054             r.sleep()
00055             if self.preempt_requested():
00056                 self.services_preempt()
00057                 return 'preempted'
00058         return 'done'
00059 #class SleepState(smach.State, tu.StateBase): 
00060 #
00061 #    def __init__(self, name, sleep_time):
00062 #        self.__init_unpicklables__()
00063 #
00064 #    def execute(self, userdata):
00065 #        rospy.sleep(self.sleep_time)
00066 #        return 'done'
00067 #
00068 #    def __init_unpicklables__(self):
00069 #        tu.StateBase.__init__(self, self.name)
00070 #        smach.State.__init__(self, outcomes = ['done'], input_keys = [], output_keys = [])
00071 #
00072 #    def __getstate__(self):
00073 #        state = tu.StateBase.__getstate__(self)
00074 #        my_state = [self.name, self.sleep_time]
00075 #        return {'state_base': state, 'self': my_state}
00076 #
00077 #    def __setstate__(self, state):
00078 #        tu.StateBase.__setstate__(self, state['state_base'])
00079 #        self.name, self.sleep_time = state['self']
00080 #        self.__init_unpicklables__()
00081 
00082 
00083 


rcommander
Author(s): Hai Nguyen (haidai@gmail.com)
autogenerated on Thu Nov 28 2013 11:46:34