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 __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()
def setupCamera(self): self.camHandler = CameraHandler() self.camHandler.setTarget(self.environ.getX(), self.environ.getY(), self.environ.getZ())
def __init__(self, showbase): # Initialise Window self.showbase = showbase # total time since start of game, to keep ticks updating on time (rather, not before) self.total_time = 0 # packets queue self.incoming = deque() # this is unnecessary lol but meh ill comment it anyway self.hp = OnscreenText(text="HP: " + str(100.0), pos=(0.95, -0.95), scale=0.07, fg=(1, 1, 1, 1), align=TextNode.ACenter, mayChange=1) # Keys array (down if 1, up if 0) self.keys = {"left": 0, "right": 0, "up": 0, "down": 0, "c": 0, "x": 0} self.skybox = Skybox(self.showbase) self.ch = CameraHandler() # maybe this shit too, or this can stay here and just pass in an array of spells self.showbase.spell_man = SpellManager( self.showbase.num_warlocks ) # until the Game() class is created in here which i think it should for i in self.showbase.spells: self.showbase.spell_man.add_spell(i) self.game = Game(self.showbase, game_tick) self.warlock = self.game.warlock[self.showbase.which] self.warlock.attach_ring(self.showbase) self.tick = 0 self.temp_tick = 0 # Set event handlers for keys self.showbase.accept("escape", sys.exit) # holding c will focus the camera on clients warlock self.showbase.accept("c", set_value, [self.keys, "c", 1]) self.showbase.accept("c-up", set_value, [self.keys, "c", 0]) # variable to track which spell has been requested self.current_spell = -1 # keys to change spell self.showbase.accept("q", self.set_spell, [0]) self.showbase.accept("w", self.set_spell, [1]) self.showbase.accept("e", self.set_spell, [2]) self.showbase.accept("r", self.set_spell, [3]) # mouse 1 is for casting the spell set by the keys self.showbase.accept("mouse1", self.cast_spell) # mouse 3 is for movement, or canceling keys for casting spell self.showbase.accept("mouse3", self.update_destination) # sets the camera up behind clients warlock looking down on it from angle follow = self.warlock.model self.ch.setTarget(follow.getPos().getX(), follow.getPos().getY(), follow.getPos().getZ()) self.ch.turnCameraAroundPoint(follow.getH(), 0) # Add the game loop procedure to the task manager. self.showbase.taskMgr.add(self.game_loop, "Game Loop")
logging.info("arduino start") arduino = ArduinoManager( "/dev/ttyACM0", 115200, 0, queueJob, "A", sendCamera, fpReceived, fpNow, ) ph.registerHandler(arduino) jobList.append(arduino) logging.info("camera start") c = CameraHandler(queueJob, "R", sendCamera, currentRunNumber, algoVer) ph.registerHandler(c) jobList.append(c) if algoVer == 1: resultsFolder = "/home/pi/checklist-results" imageFolder = "/home/pi/checklist-images" statusFolder = "/home/pi/checklist-status" remvoveFilesInFolder(resultsFolder) remvoveFilesInFolder(imageFolder) remvoveFilesInFolder(statusFolder) while True: if queueJob.qsize() != 0:
from Config import * import direct.directbase.DirectStart from direct.gui.OnscreenText import OnscreenText from pandac.PandaModules import PandaNode, NodePath, Camera, TextNode, GeomTristrips, Geom, GeomVertexFormat, GeomVertexData, GeomVertexWriter, GeomNode, TransformState, OrthographicLens, TextureStage, TexGenAttrib, PNMImage, Texture, ColorBlendAttrib from panda3d.core import * from direct.gui.DirectGui import * from direct.interval.IntervalGlobal import * from direct.task import Task import Effect import Sprite from CameraHandler import CameraHandler camhandler = CameraHandler() terrain = render.attachNewNode('terrain') tile1 = loader.loadModel(GAME + "/models/slopes/flat") tile1.setScale(3.0) tile1.reparentTo(terrain) tile1.setColor(0, 0, 1, 1) tile1.setPos(9, 0, 0) sprite1 = Sprite.Sprite(GAME + '/textures/sprites/4C_F_1.png', 3) sprite1.node.reparentTo(terrain) sprite1.node.setPos(9, 0, 0) tile2 = loader.loadModel(GAME + "/models/slopes/flat") tile2.setScale(3.0) tile2.reparentTo(terrain) tile2.setColor(0, 0, 1, 1) tile2.setPos(-9, 0, 0) sprite2 = Sprite.Sprite(GAME + '/textures/sprites/4C_F_1.png', 1)