Example #1
0
scale_factor = 0.01
bound = 4


# First we define the callback function for the stream
def update(data):
    global pos_x
    global pos_y
    data = data.channels_data
    move = model(torch.from_numpy(data).float())
    v = scale_factor * np.asarray(
        [float(move[2] - move[0]),
         float(move[1] - move[3])])
    pos_x += v[0]
    pos_y += v[1]
    # truncate
    pos_x = max(min(bound, pos_x), -1 * bound)
    pos_y = max(min(bound, pos_y), -1 * bound)
    # plot boundaries
    ax.cla()
    ax.plot([-1 * bound, bound, bound, -1 * bound, -1 * bound],
            [-1 * bound, -1 * bound, bound, bound, -1 * bound])
    # Draw circle at interpreted coordinates
    ax.add_artist(plt.Circle((pos_x, pos_y), 0.1, color='blue'))
    fig.canvas.draw()


# Start the stream
stream = StreamHandler(-1, update)
stream.start_stream()
    # quit
    if (user_input == "q"): break

    # ping bci
    if (user_input == "p"):
        test = OpenBCICyton(daisy="True")

    # record
    elif (user_input == "r"):
        row_to_modify = int(
            input(
                "Row to record to? [0 - Left] [1 - Up] [2 - Right] [3 - Down]")
        )
        frame_input = int(input("Recording how many frames?"))
        mystream = StreamHandler(frame_input, collect_data)
        mystream.start_stream()
        print("Finished recording to", row_to_modify)

    # save or save as
    elif (user_input == "s" or user_input == "sa"):
        if (LOADED and user_input == "s"):
            np.save(LOADED_PATH, np.asarray(data))
        else:
            file_name = str(input("File path?"))
            np.save(file_name, np.asarray(data))

    # load
    elif (user_input == "l"):
        file_name = str(input("File path?"))
        arrdata = np.load(file_name, allow_pickle=True)
        for i in range(NUM_CONTROLS):