Go to the documentation of this file.00001
00002 import rospy
00003 from PyQt4.QtGui import *
00004 from PyQt4.QtCore import *
00005 import rcommander.tool_utils as tu
00006 import smach
00007
00008 class MyOutputTool(tu.ToolBase):
00009
00010 def __init__(self, rcommander):
00011 tu.ToolBase.__init__(self, rcommander, 'my_output', 'My Output', MyOutputState)
00012
00013 def fill_property_box(self, pbox):
00014 formlayout = pbox.layout()
00015 self.output_number_box = QDoubleSpinBox(pbox)
00016 self.output_number_box.setMinimum(0)
00017 self.output_number_box.setMaximum(1000.)
00018 self.output_number_box.setSingleStep(.2)
00019 self.output_number_box.setValue(3.)
00020 formlayout.addRow("&Output", self.output_number_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 MyOutputState(nname, self.output_number_box.value())
00028
00029 def set_node_properties(self, my_node):
00030 self.output_number_box.setValue(my_node.output_number)
00031
00032 def reset(self):
00033 self.output_number_box.setValue(3.)
00034
00035 class MyOutputState(tu.StateBase):
00036
00037 def __init__(self, name, output_number):
00038 tu.StateBase.__init__(self, name, outputs={name: float})
00039 self.output_number = output_number
00040
00041 def get_smach_state(self):
00042 return MyOutputSmachState(self.get_name(), self.output_number)
00043
00044 class MyOutputSmachState(smach.State):
00045
00046 def __init__(self, output_variable_name, output_number):
00047 smach.State.__init__(self, outcomes=['done'], input_keys=[], output_keys=[output_variable_name])
00048 self.output_number = output_number
00049 self.output_variable_name = output_variable_name
00050
00051 def execute(self, userdata):
00052 exec("userdata.%s = self.output_number" % self.output_variable_name)
00053 return 'done'
00054
00055