예제 #1
0
def abrain():
    global left_velocity, right_velocity
    try:
        import keras
        import brain_model
    except:
        print("Error: Missing Keras for our brain.")

    # Load our brain
    model_path = "brain.model"
    try:
        model = keras.models.load_model(model_path)
    except:
        print("Error loading brain. That could be a problem.")
        print(sys.exc_info())
        pass

    # Brain loop
    while True:
        # What can we see?
        frame = camera.getFrame()
        #camera.showFrame( frame )

        # Use our brain
        outputs = model.predict(frame[None, :, :, :])
        left_v, right_v = outputs[0]
        left_velocity = left_v * 1.0
        right_velocity = right_v * 1.0
        #print( "\nRight: " + str( right_velocity ) + "  Left: " + str( left_velocity ) )
        if right_v > left_v:
            print("Right. ")
        else:
            print("Left. ")

    print("Brain done")
예제 #2
0
def detectBallProcess(ballLocation, ballLocated):
    name = multiprocessing.current_process().name
    print name, " Starting"

    # setup camera stream
    videoProxy, cam = camera.setupCamera(ip, port)

    try:
        while True:
            # get and process a camera frame
            image = camera.getFrame(videoProxy, cam)
            if image is not False:
                # Check if we can find a ball, and point the head towards it if so
                ballDet = camera.findBall(image)

                if ballDet != False:
                    ballLocated.value = True
                    centerOnBall(ballDet, ballLocation)
                    print "Ball detected"
                else:
                    ballLocated.value = False
                    print "No ball detected"

                if cv2.waitKey(33) == 27:
                    videoProxy.unsubscribe(cam)
                    break
            sleep(0.2)
    except:
        pass
    print name, " Exiting"
예제 #3
0
def main():
    global videoProxy, cam, blocked
    setup()

    say("Please give me the command start, to start")

    # start timer
    start = time()
    end = time()

    try:
        while end - start < duration:

            updateSonar()

            # get and process a camera frame
            image = camera.getFrame(videoProxy, cam)
            if image is not False:
                # Check if we can find a ball, and point the head towards it if so
                ballDet = camera.findBall(image)
                if not blocked:
                    onBallDetect(ballDet)

            # close the video proxy and end the script if escape is pressed
            if cv2.waitKey(33) == 27:
                videoProxy.unsubscribe(cam)
                break

            # start a random walk
            if not walking and not blocked and not foundBall:
                initRandomWalk()

            # look around if we are not doing much special
            if not blocked and not foundBall:
                # look around
                lookAround()

            # update time
            end = time()

        say("This was my presentation")

    except KeyboardInterrupt:
        print "Interrupted by user, shutting down"
    except Exception, e:
        print "Unexpected error:", sys.exc_info()[0], ": ", str(e)