def main():

    # Calibrate camera to servo. This is a function
    get_angle = MU.calibrate_with_camera(
        13, 303, 50, 40)  #MU.calibrate_with_camera(13, 303, 50, 34)

    # Servo handler
    servo = ServoHandler(18, 100, 2.5, 20)

    # Pump Handler
    pump = PumpHandler(16)

    # Camera handler
    cam = CameraHandler(0, 8)

    # Keep track of the threads
    threads.append(cam)

    # This goes into a thread
    cam.start()

    # Create a background frame for comparisson
    background_frame = MU.get_background(cam)

    while True:

        smoothed_frame = cam.get_frame()
        component = MU.detect_main_change(background_frame, smoothed_frame)

        if len(component) != 0:

            component = component[0]

            # if the contour is too small, ignore it -> Not significant movement
            if MU.detect_contour(component):

                # Get the countour as a circle around the main change
                (x, y), radius = MU.get_enclosure(component)

                angle = int(get_angle(int(x)))
                print angle

                # Change the position only when it was changed (significantly)
                servo.set_angle(angle)

                # The pump shoots!!!
                pump.shot(1)

        # Reduce the speed of the readings
        dummy_event = threading.Event()
        dummy_event.wait(1)
def main():

	# Calibrate camera to servo. This is a function 
	get_angle = MU.calibrate_with_camera(13, 303, 50, 40)#MU.calibrate_with_camera(13, 303, 50, 34)

	# Servo handler
	servo = ServoHandler(18, 100, 2.5, 20)

	# Pump Handler
	pump = PumpHandler(16)

	# Camera handler 
	cam = CameraHandler(0, 8)

	# Keep track of the threads
	threads.append(cam)

	# This goes into a thread
	cam.start()

	# Create a background frame for comparisson
	background_frame = MU.get_background(cam)

	while True:

		smoothed_frame = cam.get_frame()
		component = MU.detect_main_change(background_frame, smoothed_frame)

		if len(component) != 0:

			component = component[0]

			# if the contour is too small, ignore it -> Not significant movement
			if MU.detect_contour(component):
				
				# Get the countour as a circle around the main change
				(x,y), radius = MU.get_enclosure(component)
				
				angle = int( get_angle(int(x)) )
				print angle

				# Change the position only when it was changed (significantly)
				servo.set_angle(angle)

				# The pump shoots!!!
				pump.shot(1)

		# Reduce the speed of the readings
		dummy_event = threading.Event()
		dummy_event.wait(1)
Ejemplo n.º 3
0
    def __archive_cameras(self, cams, result_path):
        """
        Archives images from array of cameras.  Places directory of all results at the given path.
        """
        camera_handlers = []
        for camera in cams:
            # Create a new thread to handle the camera.
            camera_handler = CameraHandler(camera, result_path)
            # Run the thread.
            camera_handler.start()
            # Add the thread to the array of threads.
            camera_handlers.append(camera_handler)

            # Sleep to shift the starting time of all the threads.
            # time.sleep(interval / len(cams)) # Old
            time.sleep(0.5)

        # Wait for all the threads to finish execution.
        for camera_handler in camera_handlers:
            camera_handler.join()