Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions motorimagery.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from psychopy import visual, core, event
import random
import sys
import csv_collector

class MotorImagery(object):
Expand All @@ -13,9 +14,9 @@ class MotorImagery(object):
#which equals 2/60 == 30Hz
#Flash frequency = refreshrate/(frame_on+frame_off)

def __init__(self, mywin= visual.Window([800, 600], fullscr=False, monitor='testMonitor',units='deg'),
def __init__(self, mywin= visual.Window([800, 600], fullscr=True, monitor='testMonitor',units='deg'),
trialdur = 10.0, port=None,
fname='motor_imagery.csv', num_repeats=4, waitdur=5):
fname='motor_imagery.csv', num_repeats=5, waitdur=5):

self.mywin = mywin
self.trialdur = trialdur
Expand All @@ -26,6 +27,7 @@ def __init__(self, mywin= visual.Window([800, 600], fullscr=False, monitor='test
self.labels = ['Right hand', 'Left hand', 'Feet', 'Tongue']
self.patterns = [ visual.TextStim(win=self.mywin, text=lbl) for lbl in self.labels ]

self.mywin.setMouseVisible(False)


def collecting(self):
Expand All @@ -43,12 +45,15 @@ def generate_pattern_order(self):
self.pattern_order.extend(x)

def start(self):
self.mywin.flip()

#start saving data from EEG device.
self.collecting()
self.epoch(0)


###Testing framerate grabber###
print self.mywin.getActualFrameRate()
self.Trialclock = core.Clock()
# ###Testing framerate grabber###
# print self.mywin.getActualFrameRate()
# self.Trialclock = core.Clock()

#possibly convert trialdur into frames given refresh rate (normally set at 60Hz)
# self.framerate = self.mywin.getActualFrameRate()
Expand All @@ -57,24 +62,21 @@ def start(self):
self.generate_pattern_order()
self.count = 0
self.trial_num = 0

#start saving data from EEG device.
self.collecting()

while self.trial_num < len(self.labels) * self.num_repeats:
self.mywin.flip()
core.wait(self.waitdur)

while self.trial_num < len(self.labels) * self.num_repeats:
#reset tagging
self.should_tag = False
self.epoch(0)

# self.Trialclock.reset()

p = self.pattern_order[self.trial_num]

self.patterns[p].draw()
self.mywin.flip()
self.epoch(p)
self.epoch(p+1)
core.wait(self.trialdur)

#clean black screen off
Expand All @@ -88,9 +90,8 @@ def start(self):

self.collector.stop()
self.collector.disconnect()



self.mywin.close()

"""
Here are some test cases
Just run this program by itself if you don't want to use run.py
Expand All @@ -100,7 +101,9 @@ def start(self):
if __name__ == '__main__':
motorimagery = MotorImagery()
motorimagery.start()

print('trying exit')
core.quit()
sys.exit()



Expand Down