12 from actionlib_msgs.msg
import GoalStatus
13 from ensenso_camera_msgs.msg
import CalibrateHandEyeAction, CalibrateHandEyeGoal
15 from helper
import Pose
17 DATA_SET_DIRECTORY =
"../data/hand_eye_calibration/" 19 ROBOT_BASE_FRAME =
"robot_base" 20 ROBOT_WRIST_FRAME =
"robot_wrist" 23 FRAMES_WITHOUT_PATTERNS = [2, 3]
31 self.calibration_client.wait_for_server()
34 self.assertEqual(self.calibration_client.get_state(), GoalStatus.SUCCEEDED)
35 self.assertEqual(self.calibration_client.get_result().error.code, 0)
38 self.calibration_client.send_goal(goal, feedback_cb=feedback_cb)
41 self.calibration_client.wait_for_result()
43 self.assertEqual(self.calibration_client.get_result().command, goal.command)
46 self.tf_broadcaster.sendTransform(pose.position, pose.orientation, rospy.Time.now(), child_frame, parent_frame)
51 result = self.calibration_client.get_result()
52 self.assertEqual(result.command, CalibrateHandEyeGoal.RESET)
53 self.assertEqual(result.error_message,
"")
54 self.assertEqual(result.error.code, 0)
56 link_files = sorted(glob.glob(os.path.join(DATA_SET_DIRECTORY,
"links/links*")))
57 self.assertEqual(len(link_files), 22)
58 for i, link_file
in enumerate(link_files):
59 current_robot_pose = Pose.from_json(link_file)
61 self.
_broadcast_tf(current_robot_pose, ROBOT_WRIST_FRAME, ROBOT_BASE_FRAME)
64 result = self.calibration_client.get_result()
65 self.assertEqual(result.command, CalibrateHandEyeGoal.CAPTURE_PATTERN)
66 self.assertEqual(result.error_message,
"")
67 self.assertEqual(result.error.code, 0)
69 if not result.found_pattern:
70 self.assertIn(i, FRAMES_WITHOUT_PATTERNS)
72 self.assertEqual(result.pattern.thickness, 0.001)
73 self.assertEqual(result.pattern.grid_spacing, 0.01875)
74 self.assertEqual(result.pattern.grid_size_x, 7)
75 self.assertEqual(result.pattern.grid_size_y, 7)
76 self.assertEqual(len(result.pattern.left_points), 49)
77 self.assertEqual(len(result.pattern.right_points), 49)
79 robot_pose = Pose.from_message(result.robot_pose)
80 self.assertTrue(robot_pose.equals(current_robot_pose))
82 pattern_pose = Pose.from_message(result.pattern_pose)
83 self.assertTrue(all([x != 0
for x
in pattern_pose.position]))
87 def on_feedback(feedback):
91 feedback_cb=on_feedback)
94 self.assertNotEqual(self.last_feedback.number_of_iterations, 0)
95 self.assertNotEqual(self.last_feedback.residual, 0)
97 result = self.calibration_client.get_result()
98 self.assertEqual(result.command, CalibrateHandEyeGoal.START_CALIBRATION)
99 self.assertEqual(result.error_message,
"")
100 self.assertEqual(result.error.code, 0)
102 self.assertNotEqual(result.calibration_time, 0)
103 self.assertNotEqual(result.number_of_iterations, 0)
104 self.assertNotEqual(result.residual, 0)
106 final_link = Pose.from_json(os.path.join(DATA_SET_DIRECTORY,
"final_link.json")).inverse()
107 final_pattern_pose = Pose.from_json(os.path.join(DATA_SET_DIRECTORY,
"final_pattern_pose.json"))
108 self.assertTrue(final_link.equals(Pose.from_message(result.link)))
109 self.assertTrue(final_pattern_pose.equals(Pose.from_message(result.pattern_pose)))
112 if __name__ ==
"__main__":
114 rospy.init_node(
"test_hand_eye_calibration")
115 rostest.rosrun(
"ensenso_camera_test",
"test_hand_eye_calibration", TestHandEyeCalibration)
116 except rospy.ROSInterruptException:
def send_calibration_goal(self, goal, feedback_cb=None, wait=True)
def test_hand_eye_calibration(self)
def _broadcast_tf(self, pose, child_frame, parent_frame)
def assert_goal_successful(self)