utils.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright 2014 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 import rospy
18 from moveit_msgs.msg import Grasp
19 from trajectory_msgs.msg import JointTrajectoryPoint
20 
21 _sr_joint_names = [
22  'FFJ1', 'FFJ2', 'FFJ3', 'FFJ4',
23  'LFJ1', 'LFJ2', 'LFJ3', 'LFJ4', 'LFJ5',
24  'MFJ1', 'MFJ2', 'MFJ3', 'MFJ4',
25  'RFJ1', 'RFJ2', 'RFJ3', 'RFJ4',
26  'THJ1', 'THJ2', 'THJ3', 'THJ4', 'THJ5',
27  'WRJ1', 'WRJ2']
28 
29 _sr_joint_names_j0 = [
30  'LFJ0', 'LFJ3', 'LFJ4', 'LFJ5',
31  'RFJ0', 'RFJ3', 'RFJ4',
32  'MFJ0', 'MFJ3', 'MFJ4',
33  'FFJ0', 'FFJ3', 'FFJ4',
34  'THJ1', 'THJ2', 'THJ3', 'THJ4', 'THJ5',
35  'WRJ1', 'WRJ2']
36 
37 
38 def _fix_j0(joints):
39  """
40  Convert joints targets using J1 and J2 to J0, which the controllers use.
41  Useful if using joint_states to get grasp joint positions.
42  """
43  for finger in ['FFJ', 'LFJ', 'MFJ', 'RFJ']:
44  if finger+'1' in joints and finger+'2' in joints:
45  joints[finger+'0'] = joints[finger+'1'] + joints[finger+'2']
46  del joints[finger+'1']
47  del joints[finger+'2']
48 
49 
50 def mk_grasp(joints, pre_joints=None, fix_j0=False):
51  """
52  Generate a moveit_msgs/Grasp from a set of joint angles given as a dict
53  of joint_name -> position.
54  """
55  if pre_joints is None:
56  pre_joints = {}
57 
58  sr_joint_names = _sr_joint_names
59  if fix_j0:
60  _fix_j0(joints)
61  _fix_j0(pre_joints)
62  sr_joint_names = _sr_joint_names_j0
63  now = rospy.Time.now()
64  grasp = Grasp()
65  grasp.grasp_quality = 0.001
66  grasp.grasp_pose.header.frame_id = "forearm"
67  grasp.grasp_pose.header.stamp = now
68  grasp.grasp_pose.pose.position.x = 0.01
69  grasp.grasp_pose.pose.position.y = -0.045
70  grasp.grasp_pose.pose.position.z = 0.321
71  grasp.grasp_pose.pose.orientation.x = 0
72  grasp.grasp_pose.pose.orientation.y = 0
73  grasp.grasp_pose.pose.orientation.z = 0
74  grasp.grasp_pose.pose.orientation.w = 0
75  # pre-grasp (just zero all for now)
76  grasp.pre_grasp_posture.header.stamp = now
77  grasp.pre_grasp_posture.joint_names = sr_joint_names
78  jtp = JointTrajectoryPoint()
79  for jname in sr_joint_names:
80  if jname in pre_joints:
81  jtp.positions.append(pre_joints[jname])
82  else:
83  jtp.positions.append(0.0)
84  grasp.pre_grasp_posture.points.append(jtp)
85  # grasp
86  grasp.grasp_posture.header.stamp = now
87  grasp.grasp_posture.joint_names = sr_joint_names
88  jtp = JointTrajectoryPoint()
89  for jname in sr_joint_names:
90  if jname in joints:
91  jtp.positions.append(joints[jname])
92  else:
93  jtp.positions.append(0.0)
94  grasp.grasp_posture.points.append(jtp)
95  return grasp
def _fix_j0(joints)
Definition: utils.py:38
def mk_grasp(joints, pre_joints=None, fix_j0=False)
Definition: utils.py:50


sr_grasp
Author(s): Mark Pitchless
autogenerated on Wed Oct 14 2020 04:05:13