17 from __future__
import absolute_import
20 from sr_robot_commander.sr_hand_commander
import SrHandCommander
21 from actionlib_msgs.msg
import GoalStatusArray
22 from unittest
import TestCase
24 PKG =
"sr_robot_launch" 29 Tests the Hand Commander 34 cls.
hand_type = rospy.get_param(
'~test_sim/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')
41 rospy.wait_for_message(
'/move_group/status', GoalStatusArray)
47 raise TypeError(
"The specified hand_id is incorrect.")
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
62 for key
in open_joints_target:
63 open_joints_target[key] = 0.0
65 self.
hand_commander.move_to_joint_value_target(open_joints_target, wait=
True)
69 expected_and_final_joint_value_diff = self.
joints_error_check(open_joints_target, final_joint_values)
71 self.assertAlmostEqual(expected_and_final_joint_value_diff, 0, delta=0.1)
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}
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
95 self.
hand_commander.move_to_joint_value_target(pack_joints_target, wait=
True)
99 expected_and_final_joint_value_diff = self.
joints_error_check(pack_joints_target, final_joint_values)
101 self.assertAlmostEqual(expected_and_final_joint_value_diff, 0, delta=0.1)
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)