4 import ensenso_camera.ros2
as ros2py
9 LocatePattern = ros2py.import_action(
"ensenso_camera_msgs",
"LocatePattern")
10 ProjectPattern = ros2py.import_action(
"ensenso_camera_msgs",
"ProjectPattern")
15 self.
node = ros2py.create_node(
"test_project_pattern")
20 ros2py.wait_for_servers(self.
node, clients)
24 location_result = response.get_result()
26 self.assertTrue(response.successful())
27 self.assertEqual(location_result.error.code, 0)
29 self.assertTrue(location_result.found_pattern)
30 self.assertEqual(len(location_result.patterns), 1)
31 self.assertEqual(len(location_result.pattern_poses), 1)
33 detected_pattern = location_result.patterns[0]
34 detected_pattern_pose = location_result.pattern_poses[0].pose
38 goal = ProjectPattern.Goal()
39 goal.grid_spacing = detected_pattern.grid_spacing
40 goal.grid_size_x = detected_pattern.grid_size_x
41 goal.grid_size_y = detected_pattern.grid_size_y
42 goal.pattern_pose = detected_pattern_pose
45 projection_result = response.get_result()
47 self.assertTrue(response.successful())
48 self.assertEqual(projection_result.error.code, 0)
50 self.assertEqual(projection_result.pattern_is_visible,
True)
51 self.assertEqual(len(detected_pattern.left_points), len(projection_result.left_points))
52 self.assertEqual(len(detected_pattern.right_points), len(projection_result.right_points))
54 reference_points = map(
55 lambda p: ImagePoint.from_message(p), detected_pattern.left_points + detected_pattern.right_points
57 projected_points = map(
58 lambda p: ImagePoint.from_message(p), projection_result.left_points + projection_result.right_points
60 for reference_point, projected_point
in zip(reference_points, projected_points):
61 self.assertTrue(reference_point.equals(projected_point))
65 ros2py_testing.run_ros1_test(
"test_project_pattern", TestProjectPattern)
68 if __name__ ==
"__main__":