Ejemplo n.º 1
0
 def test_learnKnownObject(self):
     self.db_mock.get_feature = Mock(return_value=123)
     object_name = "green cover"
     object_spatial_desc = None
     object_entity = ObjectEntity()
     object_entity.name = object_name
     object_entity.spatial_descriptions = object_spatial_desc
     self.returned = self.grounding.learn_new_object(object_entity)
     self.assertEqual(self.returned.error_code,
                      GroundingErrorType.ALREADY_KNOWN)
Ejemplo n.º 2
0
 def test_unknownObject(self):
     object_info = ObjectInfoWithFeatures()
     features = []
     object_info.features = np.array([1, 1, 1, 1, 1])
     object_info.bbox_xxyy = np.array([1, 2, 3, 4])
     object_info.mask_full = np.array([4, 3, 2, 1])
     object_info.mask_cropped = np.array([5, 5, 5, 5])
     features.append(object_info)
     self.vision_mock.get_masks_with_features = Mock(return_value=features)
     object_name = "albert is cool"
     object_spatial_desc = None
     object_entity = ObjectEntity()
     object_entity.name = object_name
     self.returned = self.grounding.find_object(object_entity)
     self.assertEqual(self.returned.error_code, GroundingErrorType.UNKNOWN)
 def test_clarify_objects__cant_find_no_restart_request_grounding_fail_new_error__returns_clarify_state(
         self):
     entities = [(EntityType.LOCATION, "blue"),
                 (EntityType.LOCATION, "cover"),
                 (EntityType.OBJECT, "next"),
                 (EntityType.LOCATION, "black"),
                 (EntityType.OBJECT, "bottom cover"),
                 (EntityType.LOCATION, "above"),
                 (EntityType.OBJECT, "bottom cover")]
     grounding_return = GroundingReturn()
     grounding_return.is_success = False
     grounding_return.error_code = GroundingErrorType.ALREADY_KNOWN
     self.container.ner.get_entities = Mock(return_value=entities)
     self.container.grounding.find_object = Mock(
         return_value=grounding_return)
     clarify_objects_state = dialog_flow.ClarifyObjects(
         self.state_dict, self.container)
     base_task = Task(name="Dummy name")
     dummy_object = ObjectEntity(name="dummy")
     base_task.objects_to_execute_on.append(dummy_object)
     base_task.task_type = TaskType.PICK
     task_grounding_return = TaskGroundingReturn()
     task_grounding_return.task_info.append(base_task)
     clarify_objects_state.state_dict["base_task"] = base_task
     clarify_objects_state.state_dict[
         "task_grounding_return"] = task_grounding_return
     clarify_objects_state.error = GroundingErrorType.CANT_FIND
     clarify_objects_state.is_first_run = False
     self.container.speak = Mock()
     return_state = clarify_objects_state.execute()
     self.assertTrue(isinstance(return_state, dialog_flow.ClarifyObjects))
 def test_perform_task__succeeds_to_perform_task__returns_perform_task_state(
         self):
     grounding_return = GroundingReturn()
     grounding_return.is_success = True
     grounding_return.object_infos.append("dummy")
     self.container.speak = Mock()
     self.container.robot.move_out_of_view = Mock()
     self.container.camera.get_image = Mock()
     self.container.camera.get_depth = Mock()
     self.container.grounding.find_object = Mock(
         return_value=grounding_return)
     self.container.robot.pick_up = Mock(return_value=True)
     perform_task_state = dialog_flow.PerformTaskState(
         self.state_dict, self.container)
     base_task = Task(name="Dummy name")
     dummy_object = ObjectEntity(name="dummy")
     base_task.objects_to_execute_on.append(dummy_object)
     base_task.task_type = TaskType.PICK
     task_grounding_return = TaskGroundingReturn()
     task_grounding_return.task_info.append(base_task)
     perform_task_state.state_dict["base_task"] = base_task
     perform_task_state.state_dict[
         "task_grounding_return"] = task_grounding_return
     return_state = perform_task_state.execute()
     self.assertTrue(isinstance(return_state, dialog_flow.PerformTaskState))
Ejemplo n.º 5
0
 def test_updateCorrectObject(self):
     object_info = ObjectInfoWithFeatures()
     features = []
     object_info.features = np.array([1, 1, 1, 1, 1])
     object_info.bbox_xxyy = np.array([1, 2, 3, 4])
     object_info.mask_full = np.array([4, 3, 2, 1])
     object_info.mask_cropped = np.array([5, 5, 5, 5])
     features.append(object_info)
     self.vision_mock.get_masks_with_features = Mock(return_value=features)
     object_name = "black cover"
     object_spatial_desc = None
     object_entity = ObjectEntity()
     object_entity.name = object_name
     object_entity.spatial_descriptions = object_spatial_desc
     self.returned = self.grounding.update_features(object_entity)
     self.assertTrue(self.returned.is_success)
Ejemplo n.º 6
0
 def test_newObject(self):
     object_info = ObjectInfoWithFeatures()
     features = []
     object_info.features = np.array([1, 1, 1, 1, 1])
     object_info.bbox_xxyy = np.array([1, 2, 3, 4])
     object_info.mask_full = np.array([4, 3, 2, 1])
     object_info.mask_cropped = np.array([5, 5, 5, 5])
     features.append(object_info)
     self.vision_mock.get_masks_with_features = Mock(return_value=features)
     entity_name = "green cover"  # Make sure this is a new object.
     spatial_desc = None
     object_entity = ObjectEntity()
     object_entity.name = entity_name
     object_entity.spatial_descriptions = spatial_desc
     self.returned = self.grounding.learn_new_object(object_entity)
     self.assertTrue(self.returned.is_success)
    def test_get_specific_task_from_task__task_is_find__returns_task_with_find(self):
        self.db_mock.get_task = Mock(return_value=(1, "find"))
        task = Task(name="find")
        task.objects_to_execute_on = [ObjectEntity()]

        returned = self.task_grounding.get_specific_task_from_task(task)

        self.assertEqual(TaskType.FIND, returned.task_info[0].task_type)
Ejemplo n.º 8
0
 def test_learnKnownObject(self):
     object_info = ObjectInfoWithFeatures()
     features = []
     object_info.features = np.array([1, 1, 1, 1, 1])
     object_info.bbox_xxyy = np.array([1, 2, 3, 4])
     object_info.mask_full = np.array([4, 3, 2, 1])
     object_info.mask_cropped = np.array([5, 5, 5, 5])
     features.append(object_info)
     self.vision_mock.get_masks_with_features = Mock(return_value=features)
     object_name = "black cover"
     object_spatial_desc = None
     object_entity = ObjectEntity()
     object_entity.name = object_name
     object_entity.spatial_descriptions = object_spatial_desc
     self.returned = self.grounding.learn_new_object(object_entity)
     self.assertEqual(self.returned.error_code,
                      GroundingErrorType.ALREADY_KNOWN)
    def test_get_specific_task_from_task__task_is_custom_task__returns_list_of_primary_skills(self):
        pick_up_task = Task("pick up")
        pick_up_task.task_type = TaskType.PICK
        pick_up_task.objects_to_execute_on = [ObjectEntity()]
        move_task = Task("pick up")
        move_task.task_type = TaskType.MOVE
        move_task.objects_to_execute_on = [ObjectEntity()]
        place_task = Task("pick up")
        place_task.task_type = TaskType.PICK
        place_task.objects_to_execute_on = [ObjectEntity()]
        sub_tasks = [[1, 2, 3], ["pick up", "move", "place"], [pick_up_task, move_task, place_task]]
        tasks = [TaskType.PICK, TaskType.MOVE, TaskType.PLACE]
        self.db_mock.get_task = Mock(return_value=(1, "clear table"))
        self.db_mock.get_sub_tasks = Mock(return_value=sub_tasks)
        task = Task("tidy")

        returned = self.task_grounding.get_specific_task_from_task(task)

        returned_tasks = [returned.task_info[0].task_type,
                          returned.task_info[1].task_type,
                          returned.task_info[2].task_type]

        self.assertEqual(tasks, returned_tasks)
Ejemplo n.º 10
0
    def test_locate_specific_object__static_location_2__returns_closest_object(
            self):
        object_entity = ObjectEntity(name="blue cover")
        spatial_description = SpatialDescription(
            spatial_type=SpatialType.OTHER)
        spatial_description.object_entity.name = "top left corner"
        object_entity.spatial_descriptions.append(spatial_description)
        self.db_mock.get_location_by_name = Mock(return_value=(700, 100, 0))

        expected_index = self.objects[1][0]
        actual_indices, success_enum = self.spatial.locate_specific_object(
            object_entity, self.objects)

        self.assertEqual(expected_index, actual_indices[0])
 def test_clarify_objects__first_run_cant_find_object__returns_wait_response_state(
         self):
     clarify_objects_state = dialog_flow.ClarifyObjects(
         self.state_dict, self.container)
     clarify_objects_state.error = GroundingErrorType.CANT_FIND
     self.container.speak = Mock()
     base_task = Task(name="Dummy name")
     dummy_object = ObjectEntity(name="dummy")
     base_task.objects_to_execute_on.append(dummy_object)
     base_task.task_type = TaskType.PICK
     task_grounding_return = TaskGroundingReturn()
     task_grounding_return.task_info.append(base_task)
     clarify_objects_state.state_dict["base_task"] = base_task
     clarify_objects_state.state_dict[
         "task_grounding_return"] = task_grounding_return
     return_state = clarify_objects_state.execute()
     self.assertTrue(
         isinstance(return_state, dialog_flow.WaitForResponseState))