grasps_interpoler.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright 2011 Shadow Robot Company Ltd.
00004 #
00005 # This program is free software: you can redistribute it and/or modify it
00006 # under the terms of the GNU General Public License as published by the Free
00007 # Software Foundation, either version 2 of the License, or (at your option)
00008 # any later version.
00009 #
00010 # This program is distributed in the hope that it will be useful, but WITHOUT
00011 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
00013 # more details.
00014 #
00015 # You should have received a copy of the GNU General Public License along
00016 # with this program.  If not, see <http://www.gnu.org/licenses/>.
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                 # store the joints in common between the 2 grasps, with a table
00035                 # [ starting_value, end_value ]
00036                 self.from_grasp1_to_grasp2 = {}
00037 
00038                 for joint in self.grasp_from.joints_and_positions.keys():
00039             #if joint in self.grasp_to.joints_and_positions.keys():
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


sr_hand
Author(s): Ugo Cupcic
autogenerated on Fri Aug 28 2015 13:08:51