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 from sr_hand.Grasp import Grasp
00019
00020 class GraspInterpoler:
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({joint: [self.grasp_from.joints_and_positions.get(joint),self.grasp_to.joints_and_positions.get(joint)]})
00041
00042 def set_percentage_grasp1_to_grasp2(self, percentage):
00043 """
00044 move to a given percentage between grasp1 and grasp2
00045
00046 Keyword arguments
00047 percentage -- must be between 0 and 100
00048 """
00049 self.percentage = percentage
00050 positions_to_send = {}
00051
00052 for joint in self.from_grasp1_to_grasp2.iteritems():
00053 new_target = percentage/100.0 * (joint[1][1] - joint[1][0])
00054 positions_to_send.update({joint[0]:new_target})
00055
00056 return positions_to_send
00057
00058 def interpolate(self, percentage):
00059 position_to_send = {}
00060 for name, position in self.grasp_to.joints_and_positions.items():
00061 if name in self.grasp_from.joints_and_positions.keys():
00062 pos_from = self.grasp_from.joints_and_positions[name]
00063 pos_to = position
00064 position_to_send[name] = pos_from + (pos_to-pos_from)*(percentage/100.0)
00065 return position_to_send