1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534 |
-
- """
- This experiment was created using PsychoPy3 Experiment Builder (v2023.2.3),
- on 十二月 18, 2023, at 10:55
- If you publish work using this script the most relevant publication is:
- Peirce J, Gray JR, Simpson S, MacAskill M, Höchenberger R, Sogo H, Kastman E, Lindeløv JK. (2019)
- PsychoPy2: Experiments in behavior made easy Behav Res 51: 195.
- https://doi.org/10.3758/s13428-018-01193-y
- """
- from psychopy import locale_setup
- from psychopy import prefs
- from psychopy import plugins
- plugins.activatePlugins()
- prefs.hardware['audioLib'] = 'ptb'
- prefs.hardware['audioLatencyMode'] = '3'
- from psychopy import sound, gui, visual, core, data, event, logging, clock, colors, layout
- from psychopy.tools import environmenttools
- from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED,
- STOPPED, FINISHED, PRESSED, RELEASED, FOREVER, priority)
- import numpy as np
- from numpy import (sin, cos, tan, log, log10, pi, average,
- sqrt, std, deg2rad, rad2deg, linspace, asarray)
- from numpy.random import random, randint, normal, shuffle, choice as randchoice
- import os
- import sys
- import psychopy.iohub as io
- from psychopy.hardware import keyboard
- import argparse
- import time
- from device.fubo_pneumatic_finger import FuboPneumaticFingerClient
- from device.trigger_box import TriggerNeuracle
- from settings.config import settings
- def parse_args():
- parser = argparse.ArgumentParser(
- description='Grasp training'
- )
- parser.add_argument(
- '--n-trials',
- dest='n_trials',
- help='Trial number',
- type=int,
- )
- parser.add_argument(
- '--com',
- dest='com',
- help='Peripheral serial port',
- type=str
- )
- parser.add_argument(
- '--finger-model',
- '-fm',
- dest='finger_model',
- help='Gesture to train',
- type=str
- )
- return parser.parse_args()
- args = parse_args()
- hand_device = FuboPneumaticFingerClient({'port': args.com})
- trigger = TriggerNeuracle()
- _thisDir = os.path.dirname(os.path.abspath(__file__))
- psychopyVersion = '2023.2.3'
- expName = 'grasp_data_collection'
- expInfo = {
- 'participant': f"{randint(0, 999999):06.0f}",
- 'session': '001',
- 'date': data.getDateStr(),
- 'expName': expName,
- 'psychopyVersion': psychopyVersion,
- }
- def showExpInfoDlg(expInfo):
- """
- Show participant info dialog.
- Parameters
- ==========
- expInfo : dict
- Information about this experiment, created by the `setupExpInfo` function.
-
- Returns
- ==========
- dict
- Information about this experiment.
- """
-
- poppedKeys = {
- 'date': expInfo.pop('date', data.getDateStr()),
- 'expName': expInfo.pop('expName', expName),
- 'psychopyVersion': expInfo.pop('psychopyVersion', psychopyVersion),
- }
-
- dlg = gui.DlgFromDict(dictionary=expInfo, sortKeys=False, title=expName)
- if dlg.OK == False:
- core.quit()
-
- expInfo.update(poppedKeys)
-
- return expInfo
- def setupData(expInfo, dataDir=None):
- """
- Make an ExperimentHandler to handle trials and saving.
-
- Parameters
- ==========
- expInfo : dict
- Information about this experiment, created by the `setupExpInfo` function.
- dataDir : Path, str or None
- Folder to save the data to, leave as None to create a folder in the current directory.
- Returns
- ==========
- psychopy.data.ExperimentHandler
- Handler object for this experiment, contains the data to save and information about
- where to save it to.
- """
-
-
- if dataDir is None:
- dataDir = _thisDir
- filename = u'data/%s_%s_%s' % (expInfo['participant'], expName, expInfo['date'])
-
- if os.path.isabs(filename):
- dataDir = os.path.commonprefix([dataDir, filename])
- filename = os.path.relpath(filename, dataDir)
-
-
- thisExp = data.ExperimentHandler(
- name=expName, version='',
- extraInfo=expInfo, runtimeInfo=None,
- originPath='D:\\Graduate\\kraken\\backend\\grasp_data_collection.py',
- savePickle=True, saveWideText=True,
- dataFileName=dataDir + os.sep + filename, sortColumns='time'
- )
- thisExp.setPriority('thisRow.t', priority.CRITICAL)
- thisExp.setPriority('expName', priority.LOW)
-
- return thisExp
- def setupLogging(filename):
- """
- Setup a log file and tell it what level to log at.
-
- Parameters
- ==========
- filename : str or pathlib.Path
- Filename to save log file and data files as, doesn't need an extension.
-
- Returns
- ==========
- psychopy.logging.LogFile
- Text stream to receive inputs from the logging system.
- """
-
- logging.console.setLevel(logging.EXP)
-
- logFile = logging.LogFile(filename+'.log', level=logging.EXP)
-
- return logFile
- def setupWindow(expInfo=None, win=None):
- """
- Setup the Window
-
- Parameters
- ==========
- expInfo : dict
- Information about this experiment, created by the `setupExpInfo` function.
- win : psychopy.visual.Window
- Window to setup - leave as None to create a new window.
-
- Returns
- ==========
- psychopy.visual.Window
- Window in which to run this experiment.
- """
- if win is None:
-
- win = visual.Window(
- size=[1707, 1067], fullscr=True, screen=0,
- winType='pyglet', allowStencil=False,
- monitor='testMonitor', color=[1,1,1], colorSpace='rgb',
- backgroundImage='', backgroundFit='none',
- blendMode='avg', useFBO=True,
- units='height'
- )
- if expInfo is not None:
-
- expInfo['frameRate'] = win.getActualFrameRate()
- else:
-
- win.color = [1,1,1]
- win.colorSpace = 'rgb'
- win.backgroundImage = ''
- win.backgroundFit = 'none'
- win.units = 'height'
- win.mouseVisible = False
- win.hideMessage()
- return win
- def setupInputs(expInfo, thisExp, win):
- """
- Setup whatever inputs are available (mouse, keyboard, eyetracker, etc.)
-
- Parameters
- ==========
- expInfo : dict
- Information about this experiment, created by the `setupExpInfo` function.
- thisExp : psychopy.data.ExperimentHandler
- Handler object for this experiment, contains the data to save and information about
- where to save it to.
- win : psychopy.visual.Window
- Window in which to run this experiment.
- Returns
- ==========
- dict
- Dictionary of input devices by name.
- """
-
- inputs = {}
- ioConfig = {}
-
-
- ioConfig['Keyboard'] = dict(use_keymap='psychopy')
-
- ioSession = '1'
- if 'session' in expInfo:
- ioSession = str(expInfo['session'])
- ioServer = io.launchHubServer(window=win, **ioConfig)
- eyetracker = None
-
-
- defaultKeyboard = keyboard.Keyboard(backend='iohub')
-
- return {
- 'ioServer': ioServer,
- 'defaultKeyboard': defaultKeyboard,
- 'eyetracker': eyetracker,
- }
- def pauseExperiment(thisExp, inputs=None, win=None, timers=[], playbackComponents=[]):
- """
- Pause this experiment, preventing the flow from advancing to the next routine until resumed.
-
- Parameters
- ==========
- thisExp : psychopy.data.ExperimentHandler
- Handler object for this experiment, contains the data to save and information about
- where to save it to.
- inputs : dict
- Dictionary of input devices by name.
- win : psychopy.visual.Window
- Window for this experiment.
- timers : list, tuple
- List of timers to reset once pausing is finished.
- playbackComponents : list, tuple
- List of any components with a `pause` method which need to be paused.
- """
-
- if thisExp.status != PAUSED:
- return
-
-
- for comp in playbackComponents:
- comp.pause()
-
- win.stashAutoDraw()
-
- while thisExp.status == PAUSED:
-
- if inputs is None:
- inputs = {
- 'defaultKeyboard': keyboard.Keyboard(backend='ioHub')
- }
-
- if inputs['defaultKeyboard'].getKeys(keyList=['escape']):
- endExperiment(thisExp, win=win, inputs=inputs)
-
- win.flip()
-
- if thisExp.status == FINISHED:
- endExperiment(thisExp, inputs=inputs, win=win)
-
- for comp in playbackComponents:
- comp.play()
-
- win.retrieveAutoDraw()
-
- for timer in timers:
- timer.reset()
- def run(expInfo, thisExp, win, inputs, globalClock=None, thisSession=None):
- """
- Run the experiment flow.
-
- Parameters
- ==========
- expInfo : dict
- Information about this experiment, created by the `setupExpInfo` function.
- thisExp : psychopy.data.ExperimentHandler
- Handler object for this experiment, contains the data to save and information about
- where to save it to.
- psychopy.visual.Window
- Window in which to run this experiment.
- inputs : dict
- Dictionary of input devices by name.
- globalClock : psychopy.core.clock.Clock or None
- Clock to get global time from - supply None to make a new one.
- thisSession : psychopy.session.Session or None
- Handle of the Session object this experiment is being run from, if any.
- """
-
- thisExp.status = STARTED
-
- exec = environmenttools.setExecEnvironment(globals())
-
- ioServer = inputs['ioServer']
- defaultKeyboard = inputs['defaultKeyboard']
- eyetracker = inputs['eyetracker']
-
- os.chdir(_thisDir)
-
- filename = thisExp.dataFileName
- frameTolerance = 0.001
- endExpNow = False
-
- if 'frameRate' in expInfo and expInfo['frameRate'] is not None:
- frameDur = 1.0 / round(expInfo['frameRate'])
- else:
- frameDur = 1.0 / 60.0
-
-
-
-
- text = visual.TextStim(win=win, name='text',
- text='抓握训练即将开始\n如果准备好了,请按空格键',
- font='Open Sans',
- pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0,
- color='black', colorSpace='rgb', opacity=1.0,
- languageStyle='LTR',
- depth=0.0);
- key_resp = keyboard.Keyboard()
-
-
- ready_text = visual.TextStim(win=win, name='ready_text',
- text='请准备',
- font='Open Sans',
- pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0,
- color='black', colorSpace='rgb', opacity=None,
- languageStyle='LTR',
- depth=0.0);
-
-
- extend_img = visual.ImageStim(
- win=win,
- name='extend_img',
- image='static/images/extend.png', mask=None, anchor='center',
- ori=0.0, pos=(0, 0), size=(0.5, 0.5),
- color=[1,1,1], colorSpace='rgb', opacity=None,
- flipHoriz=False, flipVert=False,
- texRes=128.0, interpolate=True, depth=0.0)
- attention = sound.Sound('static/audios/ding.wav', secs=1.0, stereo=True, hamming=True,
- name='attention')
- attention.setVolume(1.0)
- extend_wav = sound.Sound('static/audios/extend.wav', secs=2, stereo=True, hamming=True,
- name='extend_wav')
- extend_wav.setVolume(1.0)
-
-
- flex_img = visual.ImageStim(
- win=win,
- name='flex_img',
- image='static/images/flex.png', mask=None, anchor='center',
- ori=0.0, pos=(0, 0), size=(0.5, 0.5),
- color=[1,1,1], colorSpace='rgb', opacity=None,
- flipHoriz=False, flipVert=False,
- texRes=128.0, interpolate=True, depth=0.0)
- flex_wav = sound.Sound('static/audios/flex.wav', secs=2, stereo=True, hamming=True,
- name='flex_wav')
- flex_wav.setVolume(1.0)
-
-
- hold_img = visual.ImageStim(
- win=win,
- name='hold_img',
- image='static/images/hold.png', mask=None, anchor='center',
- ori=0.0, pos=(0, 0), size=(0.5, 0.5),
- color=[1,1,1], colorSpace='rgb', opacity=None,
- flipHoriz=False, flipVert=False,
- texRes=128.0, interpolate=True, depth=0.0)
- hold_wav = sound.Sound('static/audios/hold.wav', secs=2, stereo=True, hamming=True,
- name='hold_wav')
- hold_wav.setVolume(1.0)
-
-
- rest_img = visual.ImageStim(
- win=win,
- name='rest_img',
- image='static/images/rest.png', mask=None, anchor='center',
- ori=0.0, pos=(0, 0), size=(0.5, 0.5),
- color=[1,1,1], colorSpace='rgb', opacity=None,
- flipHoriz=False, flipVert=False,
- texRes=128.0, interpolate=True, depth=0.0)
- rest_wav1 = sound.Sound('static/audios/ding.wav', secs=1.0, stereo=True, hamming=True,
- name='rest_wav1')
- rest_wav1.setVolume(1.0)
- rest_wav2 = sound.Sound('static/audios/rest.wav', secs=2, stereo=True, hamming=True,
- name='rest_wav2')
- rest_wav2.setVolume(1.0)
-
-
- end_text = visual.TextStim(win=win, name='end_text',
- text='恭喜您!\n完成训练!',
- font='Open Sans',
- pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0,
- color='black', colorSpace='rgb', opacity=1.0,
- languageStyle='LTR',
- depth=0.0);
-
-
- if globalClock is None:
- globalClock = core.Clock()
- if ioServer is not None:
- ioServer.syncClock(globalClock)
- logging.setDefaultClock(globalClock)
- routineTimer = core.Clock()
- win.flip()
-
- expInfo['expStart'] = data.getDateStr(format='%Y-%m-%d %Hh%M.%S.%f %z', fractionalSecondDigits=6)
-
-
- continueRoutine = True
-
- thisExp.addData('prepare.started', globalClock.getTime())
- key_resp.keys = []
- key_resp.rt = []
- _key_resp_allKeys = []
-
-
-
-
- prepareComponents = [text, key_resp]
- for thisComponent in prepareComponents:
- thisComponent.tStart = None
- thisComponent.tStop = None
- thisComponent.tStartRefresh = None
- thisComponent.tStopRefresh = None
- if hasattr(thisComponent, 'status'):
- thisComponent.status = NOT_STARTED
-
- t = 0
- _timeToFirstFrame = win.getFutureFlipTime(clock="now")
- frameN = -1
-
-
- routineForceEnded = not continueRoutine
- while continueRoutine:
-
- t = routineTimer.getTime()
- tThisFlip = win.getFutureFlipTime(clock=routineTimer)
- tThisFlipGlobal = win.getFutureFlipTime(clock=None)
- frameN = frameN + 1
-
-
-
-
-
- if text.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
-
- text.frameNStart = frameN
- text.tStart = t
- text.tStartRefresh = tThisFlipGlobal
- win.timeOnFlip(text, 'tStartRefresh')
-
- thisExp.timestampOnFlip(win, 'text.started')
-
- text.status = STARTED
- text.setAutoDraw(True)
-
-
- if text.status == STARTED:
-
- pass
-
-
- waitOnFlip = False
-
-
- if key_resp.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
-
- key_resp.frameNStart = frameN
- key_resp.tStart = t
- key_resp.tStartRefresh = tThisFlipGlobal
- win.timeOnFlip(key_resp, 'tStartRefresh')
-
- thisExp.timestampOnFlip(win, 'key_resp.started')
-
- key_resp.status = STARTED
-
- waitOnFlip = True
- win.callOnFlip(key_resp.clock.reset)
- win.callOnFlip(key_resp.clearEvents, eventType='keyboard')
- if key_resp.status == STARTED and not waitOnFlip:
- theseKeys = key_resp.getKeys(keyList=['space'], ignoreKeys=["escape"], waitRelease=False)
- _key_resp_allKeys.extend(theseKeys)
- if len(_key_resp_allKeys):
- key_resp.keys = _key_resp_allKeys[-1].name
- key_resp.rt = _key_resp_allKeys[-1].rt
- key_resp.duration = _key_resp_allKeys[-1].duration
-
- continueRoutine = False
-
-
- if defaultKeyboard.getKeys(keyList=["escape"]):
- thisExp.status = FINISHED
- if thisExp.status == FINISHED or endExpNow:
- endExperiment(thisExp, inputs=inputs, win=win)
- return
-
-
- if not continueRoutine:
- routineForceEnded = True
- break
- continueRoutine = False
- for thisComponent in prepareComponents:
- if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
- continueRoutine = True
- break
-
-
- if continueRoutine:
- win.flip()
-
-
- for thisComponent in prepareComponents:
- if hasattr(thisComponent, "setAutoDraw"):
- thisComponent.setAutoDraw(False)
- thisExp.addData('prepare.stopped', globalClock.getTime())
-
- if key_resp.keys in ['', [], None]:
- key_resp.keys = None
- thisExp.addData('key_resp.keys',key_resp.keys)
- if key_resp.keys != None:
- thisExp.addData('key_resp.rt', key_resp.rt)
- thisExp.addData('key_resp.duration', key_resp.duration)
- thisExp.nextEntry()
-
- routineTimer.reset()
-
-
- trials = data.TrialHandler(nReps=args.n_trials, method='random',
- extraInfo=expInfo, originPath=-1,
- trialList=[None],
- seed=None, name='trials')
- thisExp.addLoop(trials)
- thisTrial = trials.trialList[0]
-
- if thisTrial != None:
- for paramName in thisTrial:
- globals()[paramName] = thisTrial[paramName]
-
- for thisTrial in trials:
- currentLoop = trials
- thisExp.timestampOnFlip(win, 'thisRow.t')
-
- if thisExp.status == PAUSED:
- pauseExperiment(
- thisExp=thisExp,
- inputs=inputs,
- win=win,
- timers=[routineTimer],
- playbackComponents=[]
- )
-
- if thisTrial != None:
- for paramName in thisTrial:
- globals()[paramName] = thisTrial[paramName]
-
-
- continueRoutine = True
-
- thisExp.addData('ready.started', globalClock.getTime())
-
- readyComponents = [ready_text]
- for thisComponent in readyComponents:
- thisComponent.tStart = None
- thisComponent.tStop = None
- thisComponent.tStartRefresh = None
- thisComponent.tStopRefresh = None
- if hasattr(thisComponent, 'status'):
- thisComponent.status = NOT_STARTED
-
- t = 0
- _timeToFirstFrame = win.getFutureFlipTime(clock="now")
- frameN = -1
-
-
- routineForceEnded = not continueRoutine
- while continueRoutine and routineTimer.getTime() < 1.5:
-
- t = routineTimer.getTime()
- tThisFlip = win.getFutureFlipTime(clock=routineTimer)
- tThisFlipGlobal = win.getFutureFlipTime(clock=None)
- frameN = frameN + 1
-
-
-
-
-
- if ready_text.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
-
- ready_text.frameNStart = frameN
- ready_text.tStart = t
- ready_text.tStartRefresh = tThisFlipGlobal
- win.timeOnFlip(ready_text, 'tStartRefresh')
-
- thisExp.timestampOnFlip(win, 'ready_text.started')
-
- ready_text.status = STARTED
- ready_text.setAutoDraw(True)
-
-
- if ready_text.status == STARTED:
-
- pass
-
-
- if ready_text.status == STARTED:
-
- if tThisFlipGlobal > ready_text.tStartRefresh + 1.5-frameTolerance:
-
- ready_text.tStop = t
- ready_text.frameNStop = frameN
-
- thisExp.timestampOnFlip(win, 'ready_text.stopped')
-
- ready_text.status = FINISHED
- ready_text.setAutoDraw(False)
-
-
- if defaultKeyboard.getKeys(keyList=["escape"]):
- thisExp.status = FINISHED
- if thisExp.status == FINISHED or endExpNow:
- endExperiment(thisExp, inputs=inputs, win=win)
- return
-
-
- if not continueRoutine:
- routineForceEnded = True
- break
- continueRoutine = False
- for thisComponent in readyComponents:
- if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
- continueRoutine = True
- break
-
-
- if continueRoutine:
- win.flip()
-
-
- for thisComponent in readyComponents:
- if hasattr(thisComponent, "setAutoDraw"):
- thisComponent.setAutoDraw(False)
- thisExp.addData('ready.stopped', globalClock.getTime())
-
- if routineForceEnded:
- routineTimer.reset()
- else:
- routineTimer.addTime(-1.500000)
-
-
- continueRoutine = True
-
- thisExp.addData('extend.started', globalClock.getTime())
- attention.setSound('static/audios/ding.wav', secs=1.0, hamming=True)
- attention.setVolume(1.0, log=False)
- attention.seek(0)
-
- i = 0
-
- extend_wav.setSound('static/audios/extend.wav', secs=2, hamming=True)
- extend_wav.setVolume(1.0, log=False)
- extend_wav.seek(0)
-
- extendComponents = [extend_img, attention, extend_wav]
- for thisComponent in extendComponents:
- thisComponent.tStart = None
- thisComponent.tStop = None
- thisComponent.tStartRefresh = None
- thisComponent.tStopRefresh = None
- if hasattr(thisComponent, 'status'):
- thisComponent.status = NOT_STARTED
-
- t = 0
- _timeToFirstFrame = win.getFutureFlipTime(clock="now")
- frameN = -1
-
-
- routineForceEnded = not continueRoutine
- while continueRoutine and routineTimer.getTime() < 7.0:
-
- t = routineTimer.getTime()
- tThisFlip = win.getFutureFlipTime(clock=routineTimer)
- tThisFlipGlobal = win.getFutureFlipTime(clock=None)
- frameN = frameN + 1
-
-
-
-
-
- if extend_img.status == NOT_STARTED and tThisFlip >= 1-frameTolerance:
-
- extend_img.frameNStart = frameN
- extend_img.tStart = t
- extend_img.tStartRefresh = tThisFlipGlobal
- win.timeOnFlip(extend_img, 'tStartRefresh')
-
- thisExp.timestampOnFlip(win, 'extend_img.started')
-
- extend_img.status = STARTED
- extend_img.setAutoDraw(True)
-
-
- if extend_img.status == STARTED:
-
- pass
-
-
- if extend_img.status == STARTED:
-
- if tThisFlipGlobal > extend_img.tStartRefresh + 6-frameTolerance:
-
- extend_img.tStop = t
- extend_img.frameNStop = frameN
-
- thisExp.timestampOnFlip(win, 'extend_img.stopped')
-
- extend_img.status = FINISHED
- extend_img.setAutoDraw(False)
-
-
- if attention.status == NOT_STARTED and tThisFlip >= 1-frameTolerance:
-
- attention.frameNStart = frameN
- attention.tStart = t
- attention.tStartRefresh = tThisFlipGlobal
-
- thisExp.addData('attention.started', tThisFlipGlobal)
-
- attention.status = STARTED
- attention.play(when=win)
-
-
- if attention.status == STARTED:
-
- if tThisFlipGlobal > attention.tStartRefresh + 1.0-frameTolerance:
-
- attention.tStop = t
- attention.frameNStop = frameN
-
- thisExp.timestampOnFlip(win, 'attention.stopped')
-
- attention.status = FINISHED
- attention.stop()
-
- if attention.isPlaying:
- attention.status = STARTED
- elif attention.isFinished:
- attention.status = FINISHED
-
-
- if i== 119:
- hand_device.start('extend')
-
- current_true_label = settings.FINGERMODEL_IDS['extend']
- win.callOnFlip(trigger.send_trigger, current_true_label)
-
- i += 1
-
-
-
- if extend_wav.status == NOT_STARTED and tThisFlip >= 1.8-frameTolerance:
-
- extend_wav.frameNStart = frameN
- extend_wav.tStart = t
- extend_wav.tStartRefresh = tThisFlipGlobal
-
- thisExp.addData('extend_wav.started', tThisFlipGlobal)
-
- extend_wav.status = STARTED
- extend_wav.play(when=win)
-
-
- if extend_wav.status == STARTED:
-
- if tThisFlipGlobal > extend_wav.tStartRefresh + 2-frameTolerance:
-
- extend_wav.tStop = t
- extend_wav.frameNStop = frameN
-
- thisExp.timestampOnFlip(win, 'extend_wav.stopped')
-
- extend_wav.status = FINISHED
- extend_wav.stop()
-
- if extend_wav.isPlaying:
- extend_wav.status = STARTED
- elif extend_wav.isFinished:
- extend_wav.status = FINISHED
-
-
- if defaultKeyboard.getKeys(keyList=["escape"]):
- thisExp.status = FINISHED
- if thisExp.status == FINISHED or endExpNow:
- endExperiment(thisExp, inputs=inputs, win=win)
- return
-
-
- if not continueRoutine:
- routineForceEnded = True
- break
- continueRoutine = False
- for thisComponent in extendComponents:
- if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
- continueRoutine = True
- break
-
-
- if continueRoutine:
- win.flip()
-
-
- for thisComponent in extendComponents:
- if hasattr(thisComponent, "setAutoDraw"):
- thisComponent.setAutoDraw(False)
- thisExp.addData('extend.stopped', globalClock.getTime())
- attention.pause()
- extend_wav.pause()
-
- if routineForceEnded:
- routineTimer.reset()
- else:
- routineTimer.addTime(-7.000000)
-
-
- continueRoutine = True
-
- thisExp.addData('flex.started', globalClock.getTime())
-
- i = 0
-
- flex_wav.setSound('static/audios/flex.wav', secs=2, hamming=True)
- flex_wav.setVolume(1.0, log=False)
- flex_wav.seek(0)
-
- flexComponents = [flex_img, flex_wav]
- for thisComponent in flexComponents:
- thisComponent.tStart = None
- thisComponent.tStop = None
- thisComponent.tStartRefresh = None
- thisComponent.tStopRefresh = None
- if hasattr(thisComponent, 'status'):
- thisComponent.status = NOT_STARTED
-
- t = 0
- _timeToFirstFrame = win.getFutureFlipTime(clock="now")
- frameN = -1
-
-
- routineForceEnded = not continueRoutine
- while continueRoutine and routineTimer.getTime() < 6.0:
-
- t = routineTimer.getTime()
- tThisFlip = win.getFutureFlipTime(clock=routineTimer)
- tThisFlipGlobal = win.getFutureFlipTime(clock=None)
- frameN = frameN + 1
-
-
-
-
-
- if flex_img.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
-
- flex_img.frameNStart = frameN
- flex_img.tStart = t
- flex_img.tStartRefresh = tThisFlipGlobal
- win.timeOnFlip(flex_img, 'tStartRefresh')
-
- thisExp.timestampOnFlip(win, 'flex_img.started')
-
- flex_img.status = STARTED
- flex_img.setAutoDraw(True)
-
-
- if flex_img.status == STARTED:
-
- pass
-
-
- if flex_img.status == STARTED:
-
- if tThisFlipGlobal > flex_img.tStartRefresh + 6-frameTolerance:
-
- flex_img.tStop = t
- flex_img.frameNStop = frameN
-
- thisExp.timestampOnFlip(win, 'flex_img.stopped')
-
- flex_img.status = FINISHED
- flex_img.setAutoDraw(False)
-
- if i == 59:
- hand_device.start(args.finger_model)
-
- current_true_label = settings.FINGERMODEL_IDS[args.finger_model]
- win.callOnFlip(trigger.send_trigger, current_true_label)
-
- i += 1
-
-
-
-
- if flex_wav.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
-
- flex_wav.frameNStart = frameN
- flex_wav.tStart = t
- flex_wav.tStartRefresh = tThisFlipGlobal
-
- thisExp.addData('flex_wav.started', tThisFlipGlobal)
-
- flex_wav.status = STARTED
- flex_wav.play(when=win)
-
-
- if flex_wav.status == STARTED:
-
- if tThisFlipGlobal > flex_wav.tStartRefresh + 2-frameTolerance:
-
- flex_wav.tStop = t
- flex_wav.frameNStop = frameN
-
- thisExp.timestampOnFlip(win, 'flex_wav.stopped')
-
- flex_wav.status = FINISHED
- flex_wav.stop()
-
- if flex_wav.isPlaying:
- flex_wav.status = STARTED
- elif flex_wav.isFinished:
- flex_wav.status = FINISHED
-
-
- if defaultKeyboard.getKeys(keyList=["escape"]):
- thisExp.status = FINISHED
- if thisExp.status == FINISHED or endExpNow:
- endExperiment(thisExp, inputs=inputs, win=win)
- return
-
-
- if not continueRoutine:
- routineForceEnded = True
- break
- continueRoutine = False
- for thisComponent in flexComponents:
- if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
- continueRoutine = True
- break
-
-
- if continueRoutine:
- win.flip()
-
-
- for thisComponent in flexComponents:
- if hasattr(thisComponent, "setAutoDraw"):
- thisComponent.setAutoDraw(False)
- thisExp.addData('flex.stopped', globalClock.getTime())
- flex_wav.pause()
-
- if routineForceEnded:
- routineTimer.reset()
- else:
- routineTimer.addTime(-6.000000)
-
-
- continueRoutine = True
-
- thisExp.addData('hold.started', globalClock.getTime())
-
- win.callOnFlip(trigger.send_trigger, settings.FINGERMODEL_IDS['hold'])
- hold_wav.setSound('static/audios/hold.wav', secs=2, hamming=True)
- hold_wav.setVolume(1.0, log=False)
- hold_wav.seek(0)
-
- holdComponents = [hold_img, hold_wav]
- for thisComponent in holdComponents:
- thisComponent.tStart = None
- thisComponent.tStop = None
- thisComponent.tStartRefresh = None
- thisComponent.tStopRefresh = None
- if hasattr(thisComponent, 'status'):
- thisComponent.status = NOT_STARTED
-
- t = 0
- _timeToFirstFrame = win.getFutureFlipTime(clock="now")
- frameN = -1
-
-
- routineForceEnded = not continueRoutine
- while continueRoutine and routineTimer.getTime() < 5.0:
-
- t = routineTimer.getTime()
- tThisFlip = win.getFutureFlipTime(clock=routineTimer)
- tThisFlipGlobal = win.getFutureFlipTime(clock=None)
- frameN = frameN + 1
-
-
-
-
-
- if hold_img.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
-
- hold_img.frameNStart = frameN
- hold_img.tStart = t
- hold_img.tStartRefresh = tThisFlipGlobal
- win.timeOnFlip(hold_img, 'tStartRefresh')
-
- thisExp.timestampOnFlip(win, 'hold_img.started')
-
- hold_img.status = STARTED
- hold_img.setAutoDraw(True)
-
-
- if hold_img.status == STARTED:
-
- pass
-
-
- if hold_img.status == STARTED:
-
- if tThisFlipGlobal > hold_img.tStartRefresh + 5-frameTolerance:
-
- hold_img.tStop = t
- hold_img.frameNStop = frameN
-
- thisExp.timestampOnFlip(win, 'hold_img.stopped')
-
- hold_img.status = FINISHED
- hold_img.setAutoDraw(False)
-
-
- if hold_wav.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
-
- hold_wav.frameNStart = frameN
- hold_wav.tStart = t
- hold_wav.tStartRefresh = tThisFlipGlobal
-
- thisExp.addData('hold_wav.started', tThisFlipGlobal)
-
- hold_wav.status = STARTED
- hold_wav.play(when=win)
-
-
- if hold_wav.status == STARTED:
-
- if tThisFlipGlobal > hold_wav.tStartRefresh + 2-frameTolerance:
-
- hold_wav.tStop = t
- hold_wav.frameNStop = frameN
-
- thisExp.timestampOnFlip(win, 'hold_wav.stopped')
-
- hold_wav.status = FINISHED
- hold_wav.stop()
-
- if hold_wav.isPlaying:
- hold_wav.status = STARTED
- elif hold_wav.isFinished:
- hold_wav.status = FINISHED
-
-
- if defaultKeyboard.getKeys(keyList=["escape"]):
- thisExp.status = FINISHED
- if thisExp.status == FINISHED or endExpNow:
- endExperiment(thisExp, inputs=inputs, win=win)
- return
-
-
- if not continueRoutine:
- routineForceEnded = True
- break
- continueRoutine = False
- for thisComponent in holdComponents:
- if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
- continueRoutine = True
- break
-
-
- if continueRoutine:
- win.flip()
-
-
- for thisComponent in holdComponents:
- if hasattr(thisComponent, "setAutoDraw"):
- thisComponent.setAutoDraw(False)
- thisExp.addData('hold.stopped', globalClock.getTime())
- hold_wav.pause()
-
- if routineForceEnded:
- routineTimer.reset()
- else:
- routineTimer.addTime(-5.000000)
-
-
- continueRoutine = True
-
- thisExp.addData('rest.started', globalClock.getTime())
-
- i = 0
- rest_wav1.setSound('static/audios/ding.wav', secs=1.0, hamming=True)
- rest_wav1.setVolume(1.0, log=False)
- rest_wav1.seek(0)
- rest_wav2.setSound('static/audios/rest.wav', secs=2, hamming=True)
- rest_wav2.setVolume(1.0, log=False)
- rest_wav2.seek(0)
-
- restComponents = [rest_img, rest_wav1, rest_wav2]
- for thisComponent in restComponents:
- thisComponent.tStart = None
- thisComponent.tStop = None
- thisComponent.tStartRefresh = None
- thisComponent.tStopRefresh = None
- if hasattr(thisComponent, 'status'):
- thisComponent.status = NOT_STARTED
-
- t = 0
- _timeToFirstFrame = win.getFutureFlipTime(clock="now")
- frameN = -1
-
-
- routineForceEnded = not continueRoutine
- while continueRoutine and routineTimer.getTime() < 6.0:
-
- t = routineTimer.getTime()
- tThisFlip = win.getFutureFlipTime(clock=routineTimer)
- tThisFlipGlobal = win.getFutureFlipTime(clock=None)
- frameN = frameN + 1
-
-
-
-
-
- if rest_img.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
-
- rest_img.frameNStart = frameN
- rest_img.tStart = t
- rest_img.tStartRefresh = tThisFlipGlobal
- win.timeOnFlip(rest_img, 'tStartRefresh')
-
- thisExp.timestampOnFlip(win, 'rest_img.started')
-
- rest_img.status = STARTED
- rest_img.setAutoDraw(True)
-
-
- if rest_img.status == STARTED:
-
- pass
-
-
- if rest_img.status == STARTED:
-
- if tThisFlipGlobal > rest_img.tStartRefresh + 6-frameTolerance:
-
- rest_img.tStop = t
- rest_img.frameNStop = frameN
-
- thisExp.timestampOnFlip(win, 'rest_img.stopped')
-
- rest_img.status = FINISHED
- rest_img.setAutoDraw(False)
-
- if i== 59:
- hand_device.start('rest')
-
- win.callOnFlip(trigger.send_trigger, settings.FINGERMODEL_IDS['rest'])
-
- i += 1
-
-
- if rest_wav1.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
-
- rest_wav1.frameNStart = frameN
- rest_wav1.tStart = t
- rest_wav1.tStartRefresh = tThisFlipGlobal
-
- thisExp.addData('rest_wav1.started', tThisFlipGlobal)
-
- rest_wav1.status = STARTED
- rest_wav1.play(when=win)
-
-
- if rest_wav1.status == STARTED:
-
- if tThisFlipGlobal > rest_wav1.tStartRefresh + 1.0-frameTolerance:
-
- rest_wav1.tStop = t
- rest_wav1.frameNStop = frameN
-
- thisExp.timestampOnFlip(win, 'rest_wav1.stopped')
-
- rest_wav1.status = FINISHED
- rest_wav1.stop()
-
- if rest_wav1.isPlaying:
- rest_wav1.status = STARTED
- elif rest_wav1.isFinished:
- rest_wav1.status = FINISHED
-
-
- if rest_wav2.status == NOT_STARTED and tThisFlip >= 0.8-frameTolerance:
-
- rest_wav2.frameNStart = frameN
- rest_wav2.tStart = t
- rest_wav2.tStartRefresh = tThisFlipGlobal
-
- thisExp.addData('rest_wav2.started', tThisFlipGlobal)
-
- rest_wav2.status = STARTED
- rest_wav2.play(when=win)
-
-
- if rest_wav2.status == STARTED:
-
- if tThisFlipGlobal > rest_wav2.tStartRefresh + 2-frameTolerance:
-
- rest_wav2.tStop = t
- rest_wav2.frameNStop = frameN
-
- thisExp.timestampOnFlip(win, 'rest_wav2.stopped')
-
- rest_wav2.status = FINISHED
- rest_wav2.stop()
-
- if rest_wav2.isPlaying:
- rest_wav2.status = STARTED
- elif rest_wav2.isFinished:
- rest_wav2.status = FINISHED
-
-
- if defaultKeyboard.getKeys(keyList=["escape"]):
- thisExp.status = FINISHED
- if thisExp.status == FINISHED or endExpNow:
- endExperiment(thisExp, inputs=inputs, win=win)
- return
-
-
- if not continueRoutine:
- routineForceEnded = True
- break
- continueRoutine = False
- for thisComponent in restComponents:
- if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
- continueRoutine = True
- break
-
-
- if continueRoutine:
- win.flip()
-
-
- for thisComponent in restComponents:
- if hasattr(thisComponent, "setAutoDraw"):
- thisComponent.setAutoDraw(False)
- thisExp.addData('rest.stopped', globalClock.getTime())
- rest_wav1.pause()
- rest_wav2.pause()
-
- if routineForceEnded:
- routineTimer.reset()
- else:
- routineTimer.addTime(-6.000000)
- thisExp.nextEntry()
-
- if thisSession is not None:
-
- thisSession.sendExperimentData()
-
-
-
-
- continueRoutine = True
-
- thisExp.addData('end.started', globalClock.getTime())
-
- endComponents = [end_text]
- for thisComponent in endComponents:
- thisComponent.tStart = None
- thisComponent.tStop = None
- thisComponent.tStartRefresh = None
- thisComponent.tStopRefresh = None
- if hasattr(thisComponent, 'status'):
- thisComponent.status = NOT_STARTED
-
- t = 0
- _timeToFirstFrame = win.getFutureFlipTime(clock="now")
- frameN = -1
-
-
- routineForceEnded = not continueRoutine
- while continueRoutine and routineTimer.getTime() < 3.0:
-
- t = routineTimer.getTime()
- tThisFlip = win.getFutureFlipTime(clock=routineTimer)
- tThisFlipGlobal = win.getFutureFlipTime(clock=None)
- frameN = frameN + 1
-
-
-
-
-
- if end_text.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
-
- end_text.frameNStart = frameN
- end_text.tStart = t
- end_text.tStartRefresh = tThisFlipGlobal
- win.timeOnFlip(end_text, 'tStartRefresh')
-
- thisExp.timestampOnFlip(win, 'end_text.started')
-
- end_text.status = STARTED
- end_text.setAutoDraw(True)
-
-
- if end_text.status == STARTED:
-
- pass
-
-
- if end_text.status == STARTED:
-
- if tThisFlipGlobal > end_text.tStartRefresh + 3-frameTolerance:
-
- end_text.tStop = t
- end_text.frameNStop = frameN
-
- thisExp.timestampOnFlip(win, 'end_text.stopped')
-
- end_text.status = FINISHED
- end_text.setAutoDraw(False)
-
-
- if defaultKeyboard.getKeys(keyList=["escape"]):
- thisExp.status = FINISHED
- if thisExp.status == FINISHED or endExpNow:
- endExperiment(thisExp, inputs=inputs, win=win)
- return
-
-
- if not continueRoutine:
- routineForceEnded = True
- break
- continueRoutine = False
- for thisComponent in endComponents:
- if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
- continueRoutine = True
- break
-
-
- if continueRoutine:
- win.flip()
-
-
- for thisComponent in endComponents:
- if hasattr(thisComponent, "setAutoDraw"):
- thisComponent.setAutoDraw(False)
- thisExp.addData('end.stopped', globalClock.getTime())
-
- if routineForceEnded:
- routineTimer.reset()
- else:
- routineTimer.addTime(-3.000000)
-
-
- endExperiment(thisExp, win=win, inputs=inputs)
- def saveData(thisExp):
- """
- Save data from this experiment
-
- Parameters
- ==========
- thisExp : psychopy.data.ExperimentHandler
- Handler object for this experiment, contains the data to save and information about
- where to save it to.
- """
- filename = thisExp.dataFileName
-
- thisExp.saveAsWideText(filename + '.csv', delim='auto')
- thisExp.saveAsPickle(filename)
- def endExperiment(thisExp, inputs=None, win=None):
- """
- End this experiment, performing final shut down operations.
-
- This function does NOT close the window or end the Python process - use `quit` for this.
-
- Parameters
- ==========
- thisExp : psychopy.data.ExperimentHandler
- Handler object for this experiment, contains the data to save and information about
- where to save it to.
- inputs : dict
- Dictionary of input devices by name.
- win : psychopy.visual.Window
- Window for this experiment.
- """
- if win is not None:
-
- win.clearAutoDraw()
-
-
- win.flip()
-
- thisExp.status = FINISHED
-
- if inputs is not None:
- if 'eyetracker' in inputs and inputs['eyetracker'] is not None:
- inputs['eyetracker'].setConnectionState(False)
- logging.flush()
- def quit(thisExp, win=None, inputs=None, thisSession=None):
- """
- Fully quit, closing the window and ending the Python process.
-
- Parameters
- ==========
- win : psychopy.visual.Window
- Window to close.
- inputs : dict
- Dictionary of input devices by name.
- thisSession : psychopy.session.Session or None
- Handle of the Session object this experiment is being run from, if any.
- """
- thisExp.abort()
-
- if win is not None:
-
-
- win.flip()
- win.close()
- if inputs is not None:
- if 'eyetracker' in inputs and inputs['eyetracker'] is not None:
- inputs['eyetracker'].setConnectionState(False)
- logging.flush()
- if thisSession is not None:
- thisSession.stop()
-
- core.quit()
- if __name__ == '__main__':
-
- expInfo = showExpInfoDlg(expInfo=expInfo)
- thisExp = setupData(expInfo=expInfo)
- logFile = setupLogging(filename=thisExp.dataFileName)
- win = setupWindow(expInfo=expInfo)
- inputs = setupInputs(expInfo=expInfo, thisExp=thisExp, win=win)
- run(
- expInfo=expInfo,
- thisExp=thisExp,
- win=win,
- inputs=inputs
- )
- saveData(thisExp=thisExp)
- quit(thisExp=thisExp, win=win, inputs=inputs)
|