gripper_tool.py
Go to the documentation of this file.
00001 import tool_utils as tu
00002 from PyQt4.QtGui import *
00003 from PyQt4.QtCore import *
00004 import time
00005 import pr2_common_action_msgs.msg as ca 
00006 import functools as ft
00007 import pr2_controllers_msgs.msg as pm
00008 
00009 
00010 class GripperTool(tu.ToolBase):
00011 
00012     def __init__(self, rcommander):
00013         tu.ToolBase.__init__(self, rcommander, 'gripper', 'Gripper')
00014 
00015     def get_smach_class(self):
00016         return GripperState
00017 
00018     def fill_property_box(self, pbox):
00019         formlayout = pbox.layout()
00020         #Left or right
00021         self.radio_boxes, self.radio_buttons = tu.make_radio_box(pbox, ['Left', 'Right'], 'gripper_arm')
00022         #Opening distance
00023         self.gripper_box = tu.SliderBox(pbox, 0.01, 8.4, 0.02, .01, 'gripper', units='cm')
00024         #Effort
00025         self.effort_box = tu.SliderBox(pbox, 50., 200., 0., 40., 'effort', units='')
00026 
00027         formlayout.addRow('&Side', self.radio_boxes)
00028         formlayout.addRow('&Gripper Opening', self.gripper_box.container)
00029         formlayout.addRow('&Effort', self.effort_box.container)
00030         pbox.update()
00031 
00032     def _create_node(self, name=None):
00033         selected_arm = None
00034         for r in self.radio_buttons:
00035             if r.isChecked():
00036                 selected_arm = str(r.text()).lower()
00037         if selected_arm == None:
00038             raise RuntimeError('No arm selected!')
00039 
00040         gsize = self.gripper_box.value()
00041         effort = self.effort_box.value()
00042 
00043         if name == None:
00044             nname = self.name + str(self.counter)
00045         else:
00046             nname = name
00047         return GripperState(nname, selected_arm, gsize, effort)
00048     
00049     def _node_selected(self, gripper_state):
00050         if gripper_state.arm == 'left':
00051             self.radio_buttons[0].setChecked(True)
00052         if gripper_state.arm == 'right':
00053             self.radio_buttons[1].setChecked(True)
00054 
00055         self.gripper_box.set_value(gripper_state.gripper_size)
00056         self.effort_box.set_value(gripper_state.effort)
00057 
00058     def reset(self):
00059         self.gripper_box.set_value(0.0)
00060         self.effort_box.set_value(50.)
00061         self.radio_buttons[0].setChecked(True)
00062 
00063 
00064 class GripperState(tu.SimpleStateBase): # smach_ros.SimpleActionState):
00065 
00066     def __init__(self, name, arm, gripper_size, effort):
00067         if arm == 'left':
00068             action = 'l_gripper_controller/gripper_action'
00069         elif arm == 'right':
00070             action = 'r_gripper_controller/gripper_action'
00071 
00072         tu.SimpleStateBase.__init__(self, name, \
00073                 action, pm.Pr2GripperCommandAction,
00074                 goal_cb_str = 'ros_goal')
00075 
00076         self.gripper_size = gripper_size
00077         self.effort = effort
00078         self.arm = arm
00079 
00080     def ros_goal(self, userdata, default_goal):
00081         #import time
00082         #while True:
00083         #    time.sleep(.01)
00084         return pm.Pr2GripperCommandGoal(pm.Pr2GripperCommand(position=self.gripper_size/100., max_effort=self.effort))
00085 
00086     def __getstate__(self):
00087         state = tu.SimpleStateBase.__getstate__(self)
00088         my_state = [self.gripper_size, self.effort, self.arm]
00089         return {'simple_state': state, 'self': my_state}
00090 
00091     def __setstate__(self, state):
00092         tu.SimpleStateBase.__setstate__(self, state['simple_state'])
00093         self.gripper_size, self.effort, self.arm = state['self']
00094 


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