Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 class GraspInterpoler(object):
00021 def __init__(self, grasp_from, grasp_to="current"):
00022 """
00023 interpolate from one grasp to another
00024
00025 Keyword arguments
00026 grasp_from -- goes from this grasp
00027 grasp_to -- to this grasp (if not defined, then consider
00028 the current position of the hand as a grasp)
00029 """
00030 self.percentage = 0
00031 self.grasp_from = grasp_from
00032 self.grasp_to = grasp_to
00033
00034
00035
00036 self.from_grasp1_to_grasp2 = {}
00037
00038 for joint in self.grasp_from.joints_and_positions.keys():
00039
00040 self.from_grasp1_to_grasp2.update({
00041 joint: [self.grasp_from.joints_and_positions.get(joint),
00042 self.grasp_to.joints_and_positions.get(joint)]})
00043
00044 def set_percentage_grasp1_to_grasp2(self, percentage):
00045 """
00046 move to a given percentage between grasp1 and grasp2
00047
00048 Keyword arguments
00049 percentage -- must be between 0 and 100
00050 """
00051 self.percentage = percentage
00052 positions_to_send = {}
00053
00054 for joint in self.from_grasp1_to_grasp2.iteritems():
00055 new_target = percentage / 100.0 * (joint[1][1] - joint[1][0])
00056 positions_to_send.update({joint[0]: new_target})
00057
00058 return positions_to_send
00059
00060 def interpolate(self, percentage):
00061 position_to_send = {}
00062 for name, position in self.grasp_to.joints_and_positions.items():
00063 if name in self.grasp_from.joints_and_positions.keys():
00064 pos_from = self.grasp_from.joints_and_positions[name]
00065 pos_to = position
00066 position_to_send[name] = pos_from + (pos_to - pos_from) * (percentage / 100.0)
00067 return position_to_send