예제 #1
0
 def __init__(self, camera_arm_control_service):
     self._local_world_detector = LocalWorldDetector(camera_arm_control_service)
     self._local_world_map_drawing_service = LocalWorldMapDrawingService()
     self._on_detection_complete = EventHandler()
     self._detection_mode = LocalWorldMapDetectionMode.NONE
     self._local_world_map = LocalWorldMap()
     self._camera_arm_control_service = camera_arm_control_service
     self._detection_lock = Lock()
예제 #2
0
class LocalWorldMapService(object):

    DETECTION_MODE_SWITCH_WAIT_TIME = 1

    @property
    def local_world_map(self):
        return self._local_world_map

    @property
    def detection_mode(self):
        return self._detection_mode

    @detection_mode.setter
    def detection_mode(self, value):
        self._switch_detection_mode(value)

    @property
    def on_detection_complete(self):
        return self._on_detection_complete

    @on_detection_complete.setter
    def on_detection_complete(self, value):
        self._on_detection_complete = value

    def __init__(self, camera_arm_control_service):
        self._local_world_detector = LocalWorldDetector(camera_arm_control_service)
        self._local_world_map_drawing_service = LocalWorldMapDrawingService()
        self._on_detection_complete = EventHandler()
        self._detection_mode = LocalWorldMapDetectionMode.NONE
        self._local_world_map = LocalWorldMap()
        self._camera_arm_control_service = camera_arm_control_service
        self._detection_lock = Lock()

    def detect_objects(self, image):
        self._detection_lock.acquire()
        try:
            self._execute_detection(image)
        finally:
            self._detection_lock.release()
        self._on_detection_complete.fire()

    def _execute_detection(self, image):
        local_world_descriptor = self._local_world_detector.detect_objects(image, self._detection_mode, self._local_world_map)
        if local_world_descriptor is not None:
            self._local_world_map.merge_local_world_descriptor(local_world_descriptor)

    def reset(self, local_world_object_types):
        self._local_world_map.reset(local_world_object_types)

    def draw_local_world_map(self):
        self._local_world_map_drawing_service.draw(self._local_world_map)
        return self._local_world_map.reference_image 

    def wait_for_detection(self, local_world_object_types, timeout):
        start_time = datetime.datetime.now()
        while not self._local_world_map.contains(local_world_object_types):
            self._on_detection_complete.join(timeout)
            if (datetime.datetime.now() - start_time).total_seconds() > timeout:
                raise TimeoutError("Timeout was reached while waiting for the specified detection status.")
        return self._local_world_map

    def _switch_detection_mode(self, detection_mode):
        self._detection_mode = detection_mode
        self._detection_lock.acquire()
        if self._detection_mode == LocalWorldMapDetectionMode.TREASURE_PICKUP_SUCCESS_DETECTION:
            self._local_world_map.reset([LocalWorldObjectType.TREASURE])
        elif self._detection_mode != LocalWorldMapDetectionMode.NONE:
            self._local_world_map.reset(LocalWorldObjectType.all())
        self._detection_lock.release()