17 from __future__
import absolute_import
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
32 Tests the Hand and Arm in Sim 37 rospy.wait_for_message(
'/move_group/status', GoalStatusArray)
38 cls.
hand_type = rospy.get_param(
'~test_hand_and_arm_sim/hand_type')
39 cls.
scene = rospy.get_param(
'~test_hand_and_arm_sim/scene')
44 cls.
side = rospy.get_param(
'~test_hand_and_arm_sim/side')
45 if cls.
side ==
'right':
47 elif cls.
side ==
'left':
49 except rospy.ROSException:
50 rospy.loginfo(
"No side param for this test type")
51 cls.
hand_id = rospy.get_param(
'/hand/mapping/1082')
62 cls.
arm_commander = SrArmCommander(name=
'left_arm', set_ground=
False)
64 rospy.Subscriber(
'/move_group/monitored_planning_scene', PlanningScene, cls.
scene_data_cb)
78 expected_and_final_joint_value_diff = 0
79 for expected_value, recieved_value
in zip(sorted(expected_joint_values), sorted(recieved_joint_values)):
80 expected_and_final_joint_value_diff += abs(expected_joint_values[expected_value] -
81 recieved_joint_values[recieved_value])
82 return expected_and_final_joint_value_diff
86 while counter < timeout:
88 if len(current_value) != 0:
98 'shoulder_lift_joint': -1.25,
'wrist_1_joint': -1,
99 'wrist_2_joint': 1.5708,
'wrist_3_joint': -2}
103 'shoulder_lift_joint': -1.89,
'wrist_1_joint': -2.1,
104 'wrist_2_joint': -1.5708,
'wrist_3_joint': 2}
107 expected_start_angles = {}
108 for key, value
in home_angles_no_id.items():
109 expected_start_angles[self.
arm_id +
'_' + key] = value
111 expected_and_actual_home_angles = self.
joints_error_check(expected_start_angles, start_arm_angles)
112 self.assertAlmostEqual(expected_and_actual_home_angles, 0, delta=0.2)
116 self.
scene = rospy.get_param(
'~test_hand_and_arm_sim/scene')
118 if self.
scene is True:
120 elif self.
scene is False:
124 hand_joints_target = {
125 'hand_e': {
'THJ1': 0.52,
'THJ2': 0.61,
'THJ3': 0.0,
'THJ4': 1.20,
'THJ5': 0.17,
126 'FFJ1': 1.5707,
'FFJ2': 1.5707,
'FFJ3': 1.5707,
'FFJ4': 0.0,
127 'MFJ1': 1.5707,
'MFJ2': 1.5707,
'MFJ3': 1.5707,
'MFJ4': 0.0,
128 'RFJ1': 1.5707,
'RFJ2': 1.5707,
'RFJ3': 1.5707,
'RFJ4': 0.0,
129 'LFJ1': 0.0,
'LFJ2': 0.0,
'LFJ3': 0.0,
'LFJ4': 0.0,
130 'LFJ5': 0.0,
'WRJ1': 0.0,
'WRJ2': 0.0},
131 'hand_lite': {
'THJ1': 0.52,
'THJ2': 0.61,
'THJ4': 1.20,
'THJ5': 0.17,
132 'FFJ1': 1.5707,
'FFJ2': 1.5707,
'FFJ3': 1.5707,
'FFJ4': 0.0,
133 'MFJ1': 1.5707,
'MFJ2': 1.5707,
'MFJ3': 1.5707,
'MFJ4': 0.0,
134 'RFJ1': 0.0,
'RFJ2': 0.0,
'RFJ3': 0.0,
'RFJ4': 0.0},
135 'hand_extra_lite': {
'THJ1': 0.52,
'THJ2': 0.61,
'THJ4': 1.20,
'THJ5': 0.17,
136 'FFJ1': 1.5707,
'FFJ2': 1.5707,
'FFJ3': 1.5707,
'FFJ4': 0.0,
137 'RFJ1': 0.0,
'RFJ2': 0.0,
'RFJ3': 0.0,
'RFJ4': 0.0}
140 hand_joints_target_no_id = hand_joints_target[self.
hand_type]
141 hand_joints_target = {}
142 for key, value
in hand_joints_target_no_id.items():
143 hand_joints_target[self.
hand_id +
'_' + key] = value
145 self.
hand_commander.move_to_joint_value_target(hand_joints_target, wait=
True)
149 expected_and_final_joint_value_diff_hand = self.
joints_error_check(hand_joints_target, final_hand_joint_values)
151 self.assertAlmostEqual(expected_and_final_joint_value_diff_hand, 0, delta=0.4)
156 arm_joints_target = {
'shoulder_pan_joint': 0.00,
'elbow_joint': -1.43,
157 'shoulder_lift_joint': -1.82,
'wrist_1_joint': 3.24,
158 'wrist_2_joint': -1.57,
'wrist_3_joint': 3.13}
160 arm_joints_target = {
'shoulder_pan_joint': 0.00,
'elbow_joint': 1.43,
161 'shoulder_lift_joint': -1.27,
'wrist_1_joint': -0.1,
162 'wrist_2_joint': 1.57,
'wrist_3_joint': 3.13}
164 arm_joints_target_no_id = arm_joints_target
165 arm_joints_target = {}
166 for key, value
in arm_joints_target_no_id.items():
167 arm_joints_target[self.
arm_id +
'_' + key] = value
169 self.
arm_commander.move_to_joint_value_target(arm_joints_target, wait=
True)
171 final_arm_joint_values = self.
arm_commander.get_current_state()
173 expected_and_final_joint_value_diff_arm = self.
joints_error_check(arm_joints_target, final_arm_joint_values)
175 self.assertAlmostEqual(expected_and_final_joint_value_diff_arm, 0, delta=0.2)
178 hand_joints_target = {
179 'hand_e': {
'THJ1': 0.52,
'THJ2': 0.61,
'THJ3': 0.0,
'THJ4': 1.20,
'THJ5': 0.17,
180 'FFJ1': 1.5707,
'FFJ2': 1.5707,
'FFJ3': 1.5707,
'FFJ4': 0.0,
181 'MFJ1': 1.5707,
'MFJ2': 1.5707,
'MFJ3': 1.5707,
'MFJ4': 0.0,
182 'RFJ1': 0.0,
'RFJ2': 0.0,
'RFJ3': 0.0,
'RFJ4': 0.0,
183 'LFJ1': 0.0,
'LFJ2': 0.0,
'LFJ3': 0.0,
'LFJ4': 0.0,
184 'LFJ5': 0.0,
'WRJ1': 0.0,
'WRJ2': 0.0},
185 'hand_lite': {
'THJ1': 0.52,
'THJ2': 0.61,
'THJ4': 1.20,
'THJ5': 0.17,
186 'FFJ1': 1.5707,
'FFJ2': 1.5707,
'FFJ3': 0.0,
'FFJ4': 0.0,
187 'MFJ1': 1.5707,
'MFJ2': 1.5707,
'MFJ3': 1.5707,
'MFJ4': 0.0,
188 'RFJ1': 0.0,
'RFJ2': 0.0,
'RFJ3': 0.0,
'RFJ4': 0.0},
189 'hand_extra_lite': {
'THJ1': 0.52,
'THJ2': 0.61,
'THJ4': 1.20,
'THJ5': 0.17,
190 'FFJ1': 1.5707,
'FFJ2': 1.5707,
'FFJ3': 1.5707,
'FFJ4': 0.0,
191 'RFJ1': 0.0,
'RFJ2': 0.0,
'RFJ3': 0.0,
'RFJ4': 0.0}
194 hand_joints_target_no_id = hand_joints_target[self.
hand_type]
195 hand_joints_target = {}
196 for key, value
in hand_joints_target_no_id.items():
197 hand_joints_target[self.
hand_id +
'_' + key] = value
200 arm_joints_target = {
'shoulder_pan_joint': 0.00,
'elbow_joint': 2.0,
201 'shoulder_lift_joint': -1.25,
'wrist_1_joint': -0.733,
202 'wrist_2_joint': 1.578,
'wrist_3_joint': -3.1416}
204 arm_joints_target = {
'shoulder_pan_joint': 0.0,
'elbow_joint': -2.0,
205 'shoulder_lift_joint': -1.89,
'wrist_1_joint': 3.8,
206 'wrist_2_joint': -1.5708,
'wrist_3_joint': 3.1416}
208 arm_joints_target_no_id = arm_joints_target
209 arm_joints_target = {}
210 for key, value
in arm_joints_target_no_id.items():
211 arm_joints_target[self.
arm_id +
'_' + key] = value
213 hand_and_arm_joints_target = {**hand_joints_target.items, **arm_joints_target}
214 self.
robot_commander.move_to_joint_value_target_unsafe(hand_and_arm_joints_target, 10.0,
True)
218 final_hand_and_arm_joint_values = self.
robot_commander.get_current_state()
221 final_hand_and_arm_joint_values)
223 self.assertAlmostEqual(joint_value_diff_arm_and_hand, 0, delta=0.4)
226 if __name__ ==
"__main__":
227 PKGNAME =
'sr_robot_launch' 228 NODENAME =
'test_hand_and_arm_sim' 230 rospy.init_node(NODENAME, anonymous=
True)
231 rostest.rosrun(PKGNAME, NODENAME, TestHandAndArmSim)
def test_5_hand_and_arm(self)
def joints_error_check(self, expected_joint_values, recieved_joint_values)
def scene_data_cb(cls, result)
def wait_for_topic_with_scene(self, timeout=50)
def test_1_home_position(self)