grasps_interpoler.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright 2011 Shadow Robot Company Ltd.
4 #
5 # This program is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the Free
7 # Software Foundation version 2 of the License.
8 #
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 # more details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 
18 class GraspInterpoler(object):
19 
20  def __init__(self, grasp_from, grasp_to="current"):
21  """
22  interpolate from one grasp to another
23 
24  Keyword arguments
25  grasp_from -- goes from this grasp
26  grasp_to -- to this grasp (if not defined, then consider
27  the current position of the hand as a grasp)
28  """
29  self.percentage = 0
30  self.grasp_from = grasp_from
31  self.grasp_to = grasp_to
32 
33  # store the joints in common between the 2 grasps, with a table
34  # [ starting_value, end_value ]
36 
37  for joint in self.grasp_from.joints_and_positions.keys():
38  # if joint in self.grasp_to.joints_and_positions.keys():
39  self.from_grasp1_to_grasp2.update({
40  joint: [self.grasp_from.joints_and_positions.get(joint),
41  self.grasp_to.joints_and_positions.get(joint)]})
42 
43  def set_percentage_grasp1_to_grasp2(self, percentage):
44  """
45  move to a given percentage between grasp1 and grasp2
46 
47  Keyword arguments
48  percentage -- must be between 0 and 100
49  """
50  self.percentage = percentage
51  positions_to_send = {}
52 
53  for joint in self.from_grasp1_to_grasp2.iteritems():
54  new_target = percentage / 100.0 * (joint[1][1] - joint[1][0])
55  positions_to_send.update({joint[0]: new_target})
56 
57  return positions_to_send
58 
59  def interpolate(self, percentage):
60  position_to_send = {}
61  for name, position in self.grasp_to.joints_and_positions.items():
62  if name in self.grasp_from.joints_and_positions.keys():
63  pos_from = self.grasp_from.joints_and_positions[name]
64  pos_to = position
65  position_to_send[name] = pos_from + (
66  pos_to - pos_from) * (percentage / 100.0)
67  return position_to_send
def set_percentage_grasp1_to_grasp2(self, percentage)
def __init__(self, grasp_from, grasp_to="current")


sr_hand
Author(s): Ugo Cupcic
autogenerated on Mon Feb 28 2022 23:52:24