Exemple #1
0
def stream():
    con = Consider()
    meditation_threshold = 55
    attention_threshold = 35
    print "waiting for BCI headset signal ..."
    turn = False
    for p in con.packet_generator():
        if p.poor_signal == 0:
            print "meditation: %s / 100 | attention : %s / 100" % (
                p.meditation, p.attention)
            if p.meditation > meditation_threshold:
                t1 = threading.Thread(target=sound.play_meditation_sound)
                t1.daemon = True
                t1.start()

                if not turn:
                    t2 = threading.Thread(target=arduino.send_turn_left())
                    t2.daemon = True
                    t2.start()
                    turn = True
                else:
                    time.sleep(1)
                    turn = False

            if p.attention > attention_threshold:
                t3 = threading.Thread(target=sound.play_attention_sound)
                t3.daemon = True
                t3.start()

                t4 = threading.Thread(target=arduino.send_go_foreward())
                t4.daemon = True
                t4.start()

        else:
            print "no signal yet"
Exemple #2
0
def record(out):
    con = Consider()
    for p in con.packet_generator():
        data = map(str, [
            p.low_alpha, p.high_alpha, p.low_beta, p.high_beta, p.attention,
            p.meditation, p.poor_signal
        ])
        out.write(','.join(data))
        out.write('\n')
 def run(self):
   con = Consider()
   for p in con.packet_generator():
     if p.poor_signal == 0:
       timestamp = int(time.time() * 1000)
       packet = json.dumps({'meditation': p.meditation,
                            'attention': p.attention,
                            'signal_strength': p.signal,
                            'timestamp': timestamp})
       self.sock.sendto(packet, (self.receiver_ip, self.receiver_port))
def record(out, session):
    con = Consider()


    if next1 == "y":

    	print "Very good, we'll monitor your brain activity for 2 minutes, and then try to identify you\n"

    else:

    	raw_input("Please press enter to begin when you are ready")


    time = 120

    for p in con.packet_generator():


        if p.attention == 0 and p.meditation == 0:
            print "Please check your headset connection\n"


        #data = map(str, [p.delta, p.theta, p.low_alpha, p.high_alpha, p.low_beta, p.high_beta, p.low_gamma, p.high_gamma, p.attention, p.meditation, dt.now().strftime('%H:%M:%S')])

        data = map(str, [p.delta, p.theta, p.low_alpha, p.high_alpha, p.low_beta, p.high_beta, p.low_gamma, p.high_gamma, p.attention, p.meditation])


        num_samples = len(results)

        time_remaining = (time - num_samples)/60

        if num_samples > 0:

        	write_results(results)

        if num_samples > time:
        	

        	raw_input("Training has concluded, open MTest.csv to try identification")

        	write_results(results)

        else:

            if p.attention != 0 or p.meditation != 0:

                results.append(data)

        if num_samples == 0:

        	print 'Training is scheduled to continue for {} more minutes\n'.format(time_remaining)

        elif num_samples > 0 and (((time % num_samples) == 0 or (time % num_samples) == 60) and (((60 + num_samples) % 60) == 0)):

            print 'Training is scheduled to continue for {} more minutes\n'.format(time_remaining)
def record(out, name, session, next1):
    con = Consider()


    if next1 == "y":

    	print "\n"

    else:

    	raw_input("Please press enter to begin when you are ready")


    time = session * 60

    for p in con.packet_generator():


        if p.attention == 0 and p.meditation == 0:
            print "Please check your headset connection\n"


        #data = map(str, [p.delta, p.theta, p.low_alpha, p.high_alpha, p.low_beta, p.high_beta, p.low_gamma, p.high_gamma, p.attention, p.meditation, dt.now().strftime('%H:%M:%S')])

        data = map(str, [p.delta, p.theta, p.low_alpha, p.high_alpha, p.low_beta, p.high_beta, p.low_gamma, p.high_gamma, p.attention, p.meditation])


        num_samples = len(results)

        time_remaining = (time - num_samples)/60

        if num_samples > 0:

        	write_results(name, results)

        if num_samples > time:

        	write_results(name, results)

        	raw_input("Training has concluded, you may remove the headset at your leisure")

        	break

        else:

            if p.attention != 0 or p.meditation != 0:

                results.append(data)

        if num_samples > 0 and (((time % num_samples) == 0 or (time % num_samples) == 60) and (((60 + num_samples) % 60) == 0)):

            print 'Training is scheduled to continue for {} more minutes\n'.format(time_remaining)
 def run(self):
     con = Consider()
     for p in con.packet_generator():
         if p.poor_signal == 0:
             timestamp = int(time.time() * 1000)
             packet = json.dumps({
                 'meditation': p.meditation,
                 'attention': p.attention,
                 'signal_strength': p.signal,
                 'timestamp': timestamp
             })
             self.sock.sendto(packet,
                              (self.receiver_ip, self.receiver_port))
def stream():
    con = Consider()
    meditation_threshold = 55
    attention_threshold = 35
    print "waiting for BCI headset signal ..."
    turn = False
    for p in con.packet_generator():
        if p.poor_signal == 0:
            print "meditation: %s / 100 | attention : %s / 100" % (p.meditation, p.attention)
            if p.meditation > meditation_threshold:
                t1 = threading.Thread(target=sound.play_meditation_sound)
                t1.daemon = True
                t1.start()


                if not turn:
                    t2 = threading.Thread(target=arduino.send_turn_left())
                    t2.daemon = True
                    t2.start()
                    turn = True
                else:
                    time.sleep(1)
                    turn = False


            if p.attention > attention_threshold:
                t3 = threading.Thread(target=sound.play_attention_sound)
                t3.daemon = True
                t3.start()


                t4 = threading.Thread(target=arduino.send_go_foreward())
                t4.daemon = True
                t4.start()

        else:
            print "no signal yet"
def get_packs(Npacks, filename, overwrite):
    # Inputs:
    # Npacks - number of packets
    # filename - name of file for convenience
    # overwrite - set as 1 for overwrite
    # Outputs:
    # a file in your directory called "filename".txt
    # Initialize counter
    i = 1
    # Append .txt to filename
    filenametemp = filename + '.txt'
    # Check if file already exists and handle it appropriately with overwrite
    if (os.path.isfile(filenametemp) and overwrite == 1):
        os.remove(filenametemp)
    elif os.path.isfile(filenametemp):
        while os.path.isfile(filenametemp):
            filenametemp = filename + str(i) + '.txt'
            i += 1
    filename = filenametemp
    # Create file
    f = open(filename, 'w')
    # Initialize Consider object
    con = Consider()
    # Generate packets to file)
    print 'hello world'
    try:
        for p in islice(con.packet_generator(), Npacks):
            temp = str(p)
            temp = temp.replace(",", " ,")
            print temp
            f.write(temp + ' ' + strftime("%H:%M:%S") + '\n')
    except:
        print("Error: Check if headset is connected")
    # Close file
    f.close()
    del f
def record(out):
    con = Consider()
    for p in con.packet_generator():
        data = map(str, [p.low_alpha, p.high_alpha, p.low_beta, p.high_beta, p.attention, p.meditation, p.poor_signal])
        out.write(','.join(data))
        out.write('\n')
Exemple #10
0
def record(out):
    con = Consider()
    for p in con.packet_generator():
        #data = map(str, [p.low_alpha, p.high_alpha, p.low_beta, p.high_beta])
        #out.write(','.join(data))
        out.write(str(p))
 username = "******"
 pwd = "guest"
 
 user = "******"
 device = "neurosky"
 metric = "attention"
 routing_key = "%s:%s:%s" % (user, device, metric)
 
 buffer_size = 128
 data_buffer = []
 
 pub = PikaPublisher(host, username, pwd)
 pub.connect()
 pub.register(routing_key)
 
 con = Consider()
 
 print "Ready to publish data to '%s' on queue '%s'" % (host, str(routing_key))
 print "Waiting for BCI headset signal ..."
 for p in con.packet_generator():
   print "==> Signal quality: {}".format(p.poor_signal)
   
   if p.poor_signal == 0:
     print "Got good signal!"
     data = get_attention(p)
     
     if len(data_buffer) > buffer_size:
       pub.publish(routing_key, data_buffer)
       print "--> Published {}".format(data_buffer)
       data_buffer = []
     else: