test_bimanual_hand_and_arm.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright 2021 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 from __future__ import absolute_import
18 import rospy
19 import rostest
20 from moveit_msgs.msg import PlanningScene
21 from sr_robot_commander.sr_arm_commander import SrArmCommander
22 from sr_robot_commander.sr_hand_commander import SrHandCommander
23 from sr_robot_commander.sr_robot_commander import SrRobotCommander
24 from geometry_msgs.msg import PoseStamped, Pose
25 from rospy import get_rostime
26 from actionlib_msgs.msg import GoalStatusArray
27 from unittest import TestCase
28 
29 
30 class TestBiHandAndArmSim(TestCase):
31  """
32  Tests the Hand and Arm in Sim
33  """
34 
35  @classmethod
36  def setUpClass(cls):
37  rospy.wait_for_message('/move_group/status', GoalStatusArray)
38  cls.scene = rospy.get_param('~test_hand_and_arm_sim/scene')
39  cls.robot_commander = SrRobotCommander(name="two_arms_and_hands")
40  cls.hand_commander = SrHandCommander(name='two_hands')
41  cls.arm_commander = SrArmCommander(name='two_arms', set_ground=False)
42 
43  rospy.Subscriber('/move_group/monitored_planning_scene', PlanningScene, cls.scene_data_cb)
44 
45  rospy.sleep(10)
46 
47  @classmethod
48  def tearDownClass(cls):
49  pass
50 
51  @classmethod
52  def scene_data_cb(cls, result):
53  scene_data = ()
54  cls.scene_data = result.world.collision_objects
55 
56  def joints_error_check(self, expected_joint_values, recieved_joint_values):
57  expected_and_final_joint_value_diff = 0
58  for expected_value, recieved_value in zip(sorted(expected_joint_values), sorted(recieved_joint_values)):
59  expected_and_final_joint_value_diff += abs(expected_joint_values[expected_value] -
60  recieved_joint_values[recieved_value])
61  return expected_and_final_joint_value_diff
62 
63  def wait_for_topic_with_scene(self, timeout=50):
64  counter = 0
65  while counter < timeout:
66  current_value = self.scene_data
67  if len(current_value) != 0:
68  return current_value
69  rospy.sleep(0.1)
70  counter += 1
71 
73  start_arm_angles = self.arm_commander.get_current_state()
74  self.expected_home_angles = {'la_shoulder_pan_joint': 0.0, 'la_elbow_joint': -2.0,
75  'la_shoulder_lift_joint': -1.89, 'la_wrist_1_joint': -2.1,
76  'la_wrist_2_joint': -1.5708, 'la_wrist_3_joint': 2,
77  'ra_shoulder_pan_joint': 0.00, 'ra_elbow_joint': 2.0,
78  'ra_shoulder_lift_joint': -1.25, 'ra_wrist_1_joint': -1,
79  'ra_wrist_2_joint': 1.5708, 'ra_wrist_3_joint': -2}
80 
81  expected_and_actual_home_angles = self.joints_error_check(self.expected_home_angles, start_arm_angles)
82  self.assertAlmostEqual(expected_and_actual_home_angles, 0, delta=0.2)
83 
84  def test_2_scene(self):
85  scene = ()
86  self.scene = rospy.get_param('~test_hand_and_arm_sim/scene')
88  if self.scene is True:
89  self.assertNotEqual(len(self.scene_value), 0)
90  elif self.scene is False:
91  self.assertTrue(self.scene_value is None)
92 
93  def test_3_arms(self):
94  arm_joints_target = {'la_shoulder_pan_joint': 0.00, 'la_elbow_joint': -1.43,
95  'la_shoulder_lift_joint': -1.82, 'la_wrist_1_joint': 3.24,
96  'la_wrist_2_joint': -1.57, 'la_wrist_3_joint': 3.13,
97  'ra_shoulder_pan_joint': 0.00, 'ra_elbow_joint': 1.43,
98  'ra_shoulder_lift_joint': -1.27, 'ra_wrist_1_joint': -0.1,
99  'ra_wrist_2_joint': 1.57, 'ra_wrist_3_joint': 3.13}
100 
101  self.arm_commander.move_to_joint_value_target(arm_joints_target, wait=True)
102  rospy.sleep(5)
103  final_arm_joint_values = self.arm_commander.get_current_state()
104 
105  expected_and_final_joint_value_diff_arm = self.joints_error_check(arm_joints_target, final_arm_joint_values)
106 
107  self.assertAlmostEqual(expected_and_final_joint_value_diff_arm, 0, delta=0.2)
108 
109  def test_4_hands(self):
110  hand_joints_target = {'THJ1': 0.52, 'THJ2': 0.61, 'THJ3': 0.0, 'THJ4': 1.20, 'THJ5': 0.17,
111  'FFJ1': 1.5707, 'FFJ2': 1.5707, 'FFJ3': 1.5707, 'FFJ4': 0.0,
112  'MFJ1': 1.5707, 'MFJ2': 1.5707, 'MFJ3': 1.5707, 'MFJ4': 0.0,
113  'RFJ1': 1.5707, 'RFJ2': 1.5707, 'RFJ3': 1.5707, 'RFJ4': 0.0,
114  'LFJ1': 0.0, 'LFJ2': 0.0, 'LFJ3': 0.0, 'LFJ4': 0.0,
115  'LFJ5': 0.0, 'WRJ1': 0.0, 'WRJ2': 0.0}
116 
117  hand_joints_target_no_id = hand_joints_target
118 
119  hand_joints_target_left = {}
120  for key, value in hand_joints_target_no_id.items():
121  hand_joints_target_left['lh' + '_' + key] = value
122 
123  hand_joints_target_right = {}
124  for key, value in hand_joints_target_no_id.items():
125  hand_joints_target_right['rh' + '_' + key] = value
126 
127  hands_joints_target = {**hand_joints_target, **arm_joints_target}
128 
129  self.hand_commander.move_to_joint_value_target(hands_joints_target, wait=True)
130  rospy.sleep(15)
131  final_hand_joint_values = self.hand_commander.get_current_state()
132 
133  expected_and_final_joint_value_diff_hand = self.joints_error_check(hands_joints_target, final_hand_joint_values)
134 
135  self.assertAlmostEqual(expected_and_final_joint_value_diff_hand, 0, delta=0.5)
136 
138  hand_joints_target = {'THJ1': 0.52, 'THJ2': 0.61, 'THJ3': 0.0, 'THJ4': 1.20, 'THJ5': 0.17,
139  'FFJ1': 1.5707, 'FFJ2': 1.5707, 'FFJ3': 1.5707, 'FFJ4': 0.0,
140  'MFJ1': 1.5707, 'MFJ2': 1.5707, 'MFJ3': 1.5707, 'MFJ4': 0.0,
141  'RFJ1': 0.0, 'RFJ2': 0.0, 'RFJ3': 0.0, 'RFJ4': 0.0,
142  'LFJ1': 0.0, 'LFJ2': 0.0, 'LFJ3': 0.0, 'LFJ4': 0.0,
143  'LFJ5': 0.0, 'WRJ1': 0.0, 'WRJ2': 0.0}
144 
145  arm_joints_target_right = {'ra_shoulder_pan_joint': 0.00, 'ra_elbow_joint': 2.0,
146  'ra_shoulder_lift_joint': -1.25, 'ra_wrist_1_joint': -0.733,
147  'ra_wrist_2_joint': 1.578, 'ra_wrist_3_joint': -3.1416}
148 
149  arm_joints_target_left = {'la_shoulder_pan_joint': 0.0, 'la_elbow_joint': -2.0,
150  'la_shoulder_lift_joint': -1.89, 'la_wrist_1_joint': 3.8,
151  'la_wrist_2_joint': -1.5708, 'la_wrist_3_joint': 3.1416}
152 
153  hand_joints_target_no_id = hand_joints_target
154 
155  hand_joints_target_left = {}
156  for key, value in hand_joints_target_no_id.items():
157  hand_joints_target_left['lh' + '_' + key] = value
158 
159  hand_joints_target_right = {}
160  for key, value in hand_joints_target_no_id.items():
161  hand_joints_target_right['rh' + '_' + key] = value
162 
163  hands_and_arms_joints_target = {**hand_joints_target_right, **arm_joints_target_right,
164  **hand_joints_target_left, **arm_joints_target_left}
165 
166  self.robot_commander.move_to_joint_value_target_unsafe(hands_and_arms_joints_target, 10.0, True)
167 
168  rospy.sleep(5)
169 
170  final_hand_and_arm_joint_values = self.robot_commander.get_current_state()
171  joint_value_diff_arm_and_hand = self.joints_error_check(hands_and_arms_joints_target,
172  final_hand_and_arm_joint_values)
173 
174  self.assertAlmostEqual(joint_value_diff_arm_and_hand, 0, delta=0.4)
175 
176 
177 if __name__ == "__main__":
178  PKGNAME = 'sr_robot_launch'
179  NODENAME = 'test_bimanual_hand_and_arm'
180 
181  rospy.init_node(NODENAME, anonymous=True)
182  rostest.rosrun(PKGNAME, NODENAME, TestBiHandAndArmSim)
def joints_error_check(self, expected_joint_values, recieved_joint_values)


sr_robot_launch
Author(s): Kirsty Ellis
autogenerated on Mon Feb 28 2022 23:52:27