6 import ensenso_camera.ros2
as ros2py
11 CalibrateHandEye = ros2py.import_action(
"ensenso_camera_msgs",
"CalibrateHandEye")
13 DATA_SET_DIRECTORY = ros2py_testing.get_test_data_path(
"hand_eye_calibration/")
15 ROBOT_BASE_FRAME =
"robot_base"
16 ROBOT_WRIST_FRAME =
"robot_wrist"
19 FRAMES_WITHOUT_PATTERNS = [2, 3]
24 self.
node = ros2py.create_node(
"test_hand_eye_calibration")
27 success = ros2py.wait_for_server(
30 self.assertTrue(success, msg=
"Timeout reached for servers.")
33 result = response.get_result()
34 self.assertTrue(response.successful())
35 self.assertEqual(result.error.code, 0)
36 self.assertEqual(result.command, goal.command)
44 timestamp = self.
node.get_clock().now()
45 ros2py_testing.send_tf_transform(self.
tf_broadcaster, pose, timestamp, child_frame, parent_frame)
50 result = response.get_result()
51 self.assertEqual(result.command, CalibrateHandEye.Goal.RESET)
52 self.assertEqual(result.error_message,
"")
53 self.assertEqual(result.error.code, 0)
55 link_files = sorted(glob.glob(os.path.join(DATA_SET_DIRECTORY,
"links/links*")))
56 self.assertEqual(len(link_files), 22)
57 for i, link_file
in enumerate(link_files):
58 current_robot_pose = Pose.from_json(link_file)
60 self.
_broadcast_tf(current_robot_pose, ROBOT_WRIST_FRAME, ROBOT_BASE_FRAME)
61 response = self.
send_calibration_goal(CalibrateHandEye.Goal(command=CalibrateHandEye.Goal.CAPTURE_PATTERN))
63 result = response.get_result()
64 self.assertEqual(result.command, CalibrateHandEye.Goal.CAPTURE_PATTERN)
65 self.assertEqual(result.error_message,
"")
66 self.assertEqual(result.error.code, 0)
68 if not result.found_pattern:
69 self.assertIn(i, FRAMES_WITHOUT_PATTERNS)
71 self.assertEqual(result.pattern.thickness, 0.001)
72 self.assertEqual(result.pattern.grid_spacing, 0.01875)
73 self.assertEqual(result.pattern.grid_size_x, 7)
74 self.assertEqual(result.pattern.grid_size_y, 7)
75 self.assertEqual(len(result.pattern.left_points), 49)
76 self.assertEqual(len(result.pattern.right_points), 49)
78 robot_pose = Pose.from_message(result.robot_pose)
79 self.assertTrue(robot_pose.equals(current_robot_pose))
81 pattern_pose = Pose.from_message(result.pattern_pose)
82 self.assertTrue(all([x != 0
for x
in pattern_pose.position]))
86 @ros2py_testing.feedback_callback
87 def on_feedback(feedback):
90 goal = CalibrateHandEye.Goal(command=CalibrateHandEye.Goal.START_CALIBRATION)
94 self.assertNotEqual(self.
last_feedback.number_of_iterations, 0)
97 result = response.get_result()
98 self.assertEqual(result.command, CalibrateHandEye.Goal.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)))
113 ros2py_testing.run_ros1_test(
"test_hand_eye_calibration", TestHandEyeCalibration)
116 if __name__ ==
"__main__":