Pr2GripperAction.py
Go to the documentation of this file.
00001 import copy
00002 
00003 import roslib
00004 roslib.load_manifest('pr2_controllers_msgs')
00005 
00006 from Action import Action
00007 from pr2_controllers_msgs.msg import Pr2GripperCommand
00008 import rospy
00009 
00010 class Pr2GripperAction(Action):
00011 
00012     def __init__(self, topic, label):
00013         super(Pr2GripperAction, self).__init__()
00014         self._pub = rospy.Publisher(topic, Pr2GripperCommand)
00015         self._min_value = 0.0
00016         self._max_value = 0.08
00017         self._joints = [{'label': label, 'min': self._min_value, 'max': self._max_value, 'single_step': 0.005}]
00018         self._values = [(self._max_value- self._min_value) / 2.0]
00019         self._timer = None
00020 
00021     def set_values(self, values):
00022         # clamp value to valid range
00023         assert(len(values) == 1)
00024         self._values = [max(self._min_value, min(values[0], self._max_value))]
00025 
00026     def get_value(self, label):
00027         indexes = [i for i, data in enumerate(self._joints) if data['label'] == label]
00028         if len(indexes) == 1:
00029             return self._values[indexes[0]]
00030         raise KeyError('joint with label "%s" not found' % label)
00031 
00032     def update_value(self, label, value):
00033         indexes = [i for i, data in enumerate(self._joints) if data['label'] == label]
00034         if len(indexes) == 1:
00035             self._values[indexes[0]] = value
00036         raise KeyError('joint with label "%s" not found' % label)
00037 
00038     def to_string(self):
00039         return '%.1f' % (100 * self._values[0]) 
00040 
00041     def deepcopy(self):
00042         action = super(Pr2GripperAction, self).deepcopy()
00043         action._values = copy.deepcopy(self._values)
00044         return action
00045 
00046     def serialize(self, stream):
00047         super(Pr2GripperAction, self).serialize(stream)
00048         stream.serialize_data(self._values)
00049 
00050     def deserialize(self, stream):
00051         super(Pr2GripperAction, self).deserialize(stream)
00052         self._values = stream.deserialize_data()
00053 
00054     def execute(self):
00055         super(Pr2GripperAction, self).execute()
00056         command = Pr2GripperCommand(0.04, 0)
00057         command.max_effort = 20.0
00058         command.position = self._values[0]
00059         #print('Pr2GripperAction.execute() %s: %s' % (self.__class__.__name__, str(self._values[0])))
00060         self._pub.publish(command)
00061         self._timer = rospy.Timer(rospy.Duration.from_sec(self.get_duration()), self._timer_finished, oneshot=True)
00062 
00063     def _timer_finished(self, event):
00064         #print('Pr2GripperAction.execute() finished %s\n' % (self.__class__.__name__))
00065         self._timer = None
00066         self._execute_finished()


slider_gui
Author(s): Dirk Thomas
autogenerated on Wed Aug 26 2015 15:37:50