test_hand_joint_movement.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 # Copyright 2020 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 sr_robot_commander.sr_hand_commander import SrHandCommander
21 from actionlib_msgs.msg import GoalStatusArray
22 from unittest import TestCase
23 
24 PKG = "sr_robot_launch"
25 
26 
27 class TestHandJointMovement(TestCase):
28  """
29  Tests the Hand Commander
30  """
31 
32  @classmethod
33  def setUpClass(cls):
34  cls.hand_type = rospy.get_param('~test_sim/hand_type', 'hand_e_plus')
35  if cls.hand_type == 'hand_e':
36  cls.hand_type = 'hand_e_plus'
37  elif cls.hand_type not in ('hand_e_plus', 'hand_lite', 'hand_extra_lite'):
38  raise TypeError("The specified hand_type is incorrect.")
39  cls.hand_id = rospy.get_param('~test_sim/hand_id', 'rh')
40 
41  rospy.wait_for_message('/move_group/status', GoalStatusArray)
42  if cls.hand_id == 'rh':
43  cls.hand_commander = SrHandCommander(name='right_hand')
44  elif cls.hand_id == 'lh':
45  cls.hand_commander = SrHandCommander(name='left_hand')
46  else:
47  raise TypeError("The specified hand_id is incorrect.")
48 
49  @classmethod
50  def tearDownClass(cls):
51  pass
52 
53  def joints_error_check(self, expected_joint_values, recieved_joint_values):
54  expected_and_final_joint_value_diff = 0
55  for expected_value, recieved_value in zip(sorted(expected_joint_values), sorted(recieved_joint_values)):
56  expected_and_final_joint_value_diff += abs(expected_joint_values[expected_value] -
57  recieved_joint_values[recieved_value])
58  return expected_and_final_joint_value_diff
59 
60  def test_hand_open(self):
61  open_joints_target = self.hand_commander.get_joints_position()
62  for key in open_joints_target:
63  open_joints_target[key] = 0.0
64 
65  self.hand_commander.move_to_joint_value_target(open_joints_target, wait=True)
66  rospy.sleep(5)
67  final_joint_values = self.hand_commander.get_current_state()
68 
69  expected_and_final_joint_value_diff = self.joints_error_check(open_joints_target, final_joint_values)
70 
71  self.assertAlmostEqual(expected_and_final_joint_value_diff, 0, delta=0.1)
72 
73  def test_hand_pack(self):
74  hand_pack_joint_targets = {
75  'hand_e_plus': {'THJ1': 0.52, 'THJ2': 0.61, 'THJ3': 0.0, 'THJ4': 1.20, 'THJ5': 0.17,
76  'FFJ1': 1.5707, 'FFJ2': 1.5707, 'FFJ3': 1.5707, 'FFJ4': 0.0,
77  'MFJ1': 1.5707, 'MFJ2': 1.5707, 'MFJ3': 1.5707, 'MFJ4': 0.0,
78  'RFJ1': 1.5707, 'RFJ2': 1.5707, 'RFJ3': 1.5707, 'RFJ4': 0.0,
79  'LFJ1': 1.5707, 'LFJ2': 1.5707, 'LFJ3': 1.5707, 'LFJ4': 0.0,
80  'LFJ5': 0.0, 'WRJ1': 0.0, 'WRJ2': 0.0},
81  'hand_lite': {'THJ1': 0.52, 'THJ2': 0.61, 'THJ4': 1.20, 'THJ5': 0.17,
82  'FFJ1': 1.5707, 'FFJ2': 1.5707, 'FFJ3': 1.5707, 'FFJ4': 0.0,
83  'MFJ1': 1.5707, 'MFJ2': 1.5707, 'MFJ3': 1.5707, 'MFJ4': 0.0,
84  'RFJ1': 1.5707, 'RFJ2': 1.5707, 'RFJ3': 1.5707, 'RFJ4': 0.0},
85  'hand_extra_lite': {'THJ1': 0.52, 'THJ2': 0.61, 'THJ4': 1.20, 'THJ5': 0.17,
86  'FFJ1': 1.5707, 'FFJ2': 1.5707, 'FFJ3': 1.5707, 'FFJ4': 0.0,
87  'RFJ1': 1.5707, 'RFJ2': 1.5707, 'RFJ3': 1.5707, 'RFJ4': 0.0}
88  }
89 
90  pack_joints_target_no_id = hand_pack_joint_targets[self.hand_type]
91  pack_joints_target = {}
92  for key, value in pack_joints_target_no_id.items():
93  pack_joints_target[self.hand_id + '_' + key] = value
94 
95  self.hand_commander.move_to_joint_value_target(pack_joints_target, wait=True)
96  rospy.sleep(5)
97  final_joint_values = self.hand_commander.get_current_state()
98 
99  expected_and_final_joint_value_diff = self.joints_error_check(pack_joints_target, final_joint_values)
100 
101  self.assertAlmostEqual(expected_and_final_joint_value_diff, 0, delta=0.1)
102 
103 
104 if __name__ == "__main__":
105  rospy.init_node('test_sim', anonymous=True)
106  rostest.rosrun(PKG, "test_sim", TestHandJointMovement)
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