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, either version 2 of the License, or (at your option)
8 # any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 # more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program. If not, see <http://www.gnu.org/licenses/>.
17 #
18 
19 
20 class GraspInterpoler(object):
21 
22  def __init__(self, grasp_from, grasp_to="current"):
23  """
24  interpolate from one grasp to another
25 
26  Keyword arguments
27  grasp_from -- goes from this grasp
28  grasp_to -- to this grasp (if not defined, then consider
29  the current position of the hand as a grasp)
30  """
31  self.percentage = 0
32  self.grasp_from = grasp_from
33  self.grasp_to = grasp_to
34 
35  # store the joints in common between the 2 grasps, with a table
36  # [ starting_value, end_value ]
38 
39  for joint in self.grasp_from.joints_and_positions.keys():
40  # if joint in self.grasp_to.joints_and_positions.keys():
41  self.from_grasp1_to_grasp2.update({
42  joint: [self.grasp_from.joints_and_positions.get(joint),
43  self.grasp_to.joints_and_positions.get(joint)]})
44 
45  def set_percentage_grasp1_to_grasp2(self, percentage):
46  """
47  move to a given percentage between grasp1 and grasp2
48 
49  Keyword arguments
50  percentage -- must be between 0 and 100
51  """
52  self.percentage = percentage
53  positions_to_send = {}
54 
55  for joint in self.from_grasp1_to_grasp2.iteritems():
56  new_target = percentage / 100.0 * (joint[1][1] - joint[1][0])
57  positions_to_send.update({joint[0]: new_target})
58 
59  return positions_to_send
60 
61  def interpolate(self, percentage):
62  position_to_send = {}
63  for name, position in self.grasp_to.joints_and_positions.items():
64  if name in self.grasp_from.joints_and_positions.keys():
65  pos_from = self.grasp_from.joints_and_positions[name]
66  pos_to = position
67  position_to_send[name] = pos_from + (
68  pos_to - pos_from) * (percentage / 100.0)
69  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 Tue Oct 13 2020 03:55:53