test_grasp_contact.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 os
18 import unittest
19 import rospy
20 import rostest
21 from actionlib import SimpleActionClient, GoalStatus
22 from sr_robot_msgs.msg import GraspAction, GraspGoal
23 from moveit_msgs.msg import Grasp
24 from trajectory_msgs.msg import JointTrajectoryPoint
25 from sr_hand.shadowhand_ros import ShadowHand_ROS
26 
27 PKG = 'sr_grasp'
28 NAME = 'test_grasp_contact'
29 
30 
31 class TestGraspContact(unittest.TestCase):
32  longMessage = True
33 
34  joint_names = [
35  'LFJ0', 'LFJ3', 'LFJ4', 'LFJ5',
36  'RFJ0', 'RFJ3', 'RFJ4',
37  'MFJ0', 'MFJ3', 'MFJ4',
38  'FFJ0', 'FFJ3', 'FFJ4',
39  'THJ1', 'THJ2', 'THJ3', 'THJ4', 'THJ5',
40  'WRJ1', 'WRJ2']
41 
42  def mk_grasp(self, joints):
43  grasp = Grasp()
44  # pre-grasp (just zero all for now)
45  grasp.pre_grasp_posture.joint_names = self.joint_names
46  jtp = JointTrajectoryPoint()
47  for jname in self.joint_names:
48  jtp.positions.append(0.0)
49  grasp.pre_grasp_posture.points.append(jtp)
50  # grasp
51  grasp.grasp_posture.joint_names = self.joint_names
52  jtp = JointTrajectoryPoint()
53  for jname in self.joint_names:
54  if jname in joints:
55  jtp.positions.append(joints[jname])
56  else:
57  jtp.positions.append(0.0)
58  grasp.grasp_posture.points.append(jtp)
59  return grasp
60 
61  # Tests
62  ########
63 
64  def test_grasp_contact(self):
65  """Test sending a grasp with object in the way"""
66  rospy.sleep(2)
67  hand = ShadowHand_ROS()
68 
69  # Reset hand.
70  for j in hand.allJoints:
71  hand.sendupdate(j.name, 0.0)
72  rospy.sleep(2)
73 
74  goal = GraspGoal()
75  goal.grasp = self.mk_grasp({
76  'LFJ3': 1.4, 'RFJ3': 1.4, 'MFJ3': 1.4, 'FFJ3': 1.4,
77  'LFJ0': 2.0, 'RFJ0': 2.0, 'MFJ0': 2.0, 'FFJ0': 2.0,
78  })
79  goal.pre_grasp = False
80 
81  client = SimpleActionClient('grasp', GraspAction)
82  client.wait_for_server()
83  client.send_goal(goal)
84  client.wait_for_result(rospy.Duration.from_sec(20.0))
85  self.assertEqual(client.get_state(), GoalStatus.SUCCEEDED,
86  "Action did not return in SUCCEEDED state.")
87 
88  rospy.sleep(2)
89 
90  # Reset hand.
91  for j in hand.allJoints:
92  hand.sendupdate(j.name, 0.0)
93  rospy.sleep(2)
94 
95 
96 if __name__ == '__main__':
97  rospy.init_node(NAME)
98  rostest.rosrun(PKG, NAME, TestGraspContact)


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