~ugocupcic/sr-ros-interface/manipulation

« back to all changes in this revision

Viewing changes to shadow_robot/sr_hand/python_lib/grasp/grasps_interpoler.py

  • Committer: Ugo Cupcic
  • Date: 2011-05-23 15:44:05 UTC
  • mfrom: (119.1.67 sr-ros-interface)
  • Revision ID: ugo@shadowrobot.com-20110523154405-kwvv543sy9wxehzi
Huge merge from trunk. Lots of changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#
1
18
from Grasp import Grasp
2
19
 
3
20
class GraspInterpoler:
15
32
                self.grasp_to = grasp_to
16
33
 
17
34
                # store the joints in common between the 2 grasps, with a table
18
 
                # [ starting_value, end_value ] 
 
35
                # [ starting_value, end_value ]
19
36
                self.from_grasp1_to_grasp2 = {}
20
37
 
21
38
                for joint in self.grasp_from.joints_and_positions.keys():
22
39
            #if joint in self.grasp_to.joints_and_positions.keys():
23
40
                        self.from_grasp1_to_grasp2.update({joint: [self.grasp_from.joints_and_positions.get(joint),self.grasp_to.joints_and_positions.get(joint)]})
24
 
        
 
41
 
25
42
        def set_percentage_grasp1_to_grasp2(self, percentage):
26
43
                """
27
44
                move to a given percentage between grasp1 and grasp2
33
50
                positions_to_send = {}
34
51
 
35
52
                for joint in self.from_grasp1_to_grasp2.iteritems():
36
 
                        new_target = percentage/100.0 * (joint[1][1] - joint[1][0]) 
 
53
                        new_target = percentage/100.0 * (joint[1][1] - joint[1][0])
37
54
                        positions_to_send.update({joint[0]:new_target})
38
55
 
39
56
                return positions_to_send
40
 
               
 
57
 
41
58
        def interpolate(self, percentage):
42
59
                position_to_send = {}
43
60
                for name, position in self.grasp_to.joints_and_positions.items():