Browse Source

Revert "set the hold time to random"

This reverts commit 30b9d478b29b0eafb769323d377cc35308ef213c.
lfs___ 1 year ago
parent
commit
d4f0a36b33

+ 2 - 2
.vscode/launch.json

@@ -25,12 +25,12 @@
             "name": "Grasp training",
             "name": "Grasp training",
             "type": "python",
             "type": "python",
             "request": "launch",
             "request": "launch",
-            "program": "grasp_data_collection_no_release.py",
+            "program": "grasp_data_collection.py",
             "console": "integratedTerminal",
             "console": "integratedTerminal",
             "cwd": "${workspaceFolder}/backend",
             "cwd": "${workspaceFolder}/backend",
             "justMyCode": true,
             "justMyCode": true,
             "args": ["--n-trials", "15", 
             "args": ["--n-trials", "15", 
-            "--com", "COM8", 
+            "--com", "COM3", 
             "-fm", "flex"]
             "-fm", "flex"]
         },
         },
         {
         {

+ 4 - 4
backend/grasp_data_collection_no_release.psyexp

@@ -134,7 +134,7 @@
         <Param val="True" valType="bool" updates="constant" name="syncScreenRefresh"/>
         <Param val="True" valType="bool" updates="constant" name="syncScreenRefresh"/>
       </KeyboardComponent>
       </KeyboardComponent>
       <CodeComponent name="config" plugin="None">
       <CodeComponent name="config" plugin="None">
-        <Param val="import argparse&amp;#10;import time&amp;#10;from device.fubo_pneumatic_finger import FuboPneumaticFingerClient&amp;#10;from device.trigger_box import TriggerNeuracle&amp;#10;from settings.config import settings&amp;#10;import random&amp;#10;&amp;#10;# get train params&amp;#10;&amp;#10;def parse_args():&amp;#10;&amp;#10;    parser = argparse.ArgumentParser(&amp;#10;&amp;#10;        description='Grasp training'&amp;#10;&amp;#10;    )&amp;#10;&amp;#10;    parser.add_argument(&amp;#10;&amp;#10;        '--n-trials',&amp;#10;&amp;#10;        dest='n_trials',&amp;#10;&amp;#10;        help='Trial number',&amp;#10;&amp;#10;        type=int,&amp;#10;&amp;#10;    )&amp;#10;&amp;#10;    parser.add_argument(&amp;#10;&amp;#10;        '--com',&amp;#10;&amp;#10;        dest='com',&amp;#10;&amp;#10;        help='Peripheral serial port',&amp;#10;&amp;#10;        type=str&amp;#10;&amp;#10;    )&amp;#10;&amp;#10;    parser.add_argument(&amp;#10;&amp;#10;        '--finger-model',&amp;#10;&amp;#10;        '-fm',&amp;#10;&amp;#10;        dest='finger_model',&amp;#10;&amp;#10;        help='Gesture to train',&amp;#10;&amp;#10;        type=str&amp;#10;&amp;#10;    )&amp;#10;&amp;#10;    return parser.parse_args()&amp;#10;&amp;#10;&amp;#10;&amp;#10;args = parse_args()&amp;#10;&amp;#10;hand_device = FuboPneumaticFingerClient({'port': args.com})&amp;#10;&amp;#10;# connect to trigger box&amp;#10;trigger = TriggerNeuracle()&amp;#10;" valType="extendedCode" updates="constant" name="Before Experiment"/>
+        <Param val="import argparse&amp;#10;import time&amp;#10;from device.fubo_pneumatic_finger import FuboPneumaticFingerClient&amp;#10;from device.trigger_box import TriggerNeuracle&amp;#10;from settings.config import settings&amp;#10;&amp;#10;&amp;#10;# get train params&amp;#10;&amp;#10;def parse_args():&amp;#10;&amp;#10;    parser = argparse.ArgumentParser(&amp;#10;&amp;#10;        description='Grasp training'&amp;#10;&amp;#10;    )&amp;#10;&amp;#10;    parser.add_argument(&amp;#10;&amp;#10;        '--n-trials',&amp;#10;&amp;#10;        dest='n_trials',&amp;#10;&amp;#10;        help='Trial number',&amp;#10;&amp;#10;        type=int,&amp;#10;&amp;#10;    )&amp;#10;&amp;#10;    parser.add_argument(&amp;#10;&amp;#10;        '--com',&amp;#10;&amp;#10;        dest='com',&amp;#10;&amp;#10;        help='Peripheral serial port',&amp;#10;&amp;#10;        type=str&amp;#10;&amp;#10;    )&amp;#10;&amp;#10;    parser.add_argument(&amp;#10;&amp;#10;        '--finger-model',&amp;#10;&amp;#10;        '-fm',&amp;#10;&amp;#10;        dest='finger_model',&amp;#10;&amp;#10;        help='Gesture to train',&amp;#10;&amp;#10;        type=str&amp;#10;&amp;#10;    )&amp;#10;&amp;#10;    return parser.parse_args()&amp;#10;&amp;#10;&amp;#10;&amp;#10;args = parse_args()&amp;#10;&amp;#10;hand_device = FuboPneumaticFingerClient({'port': args.com})&amp;#10;&amp;#10;# connect to trigger box&amp;#10;trigger = TriggerNeuracle()&amp;#10;" valType="extendedCode" updates="constant" name="Before Experiment"/>
         <Param val="" valType="extendedCode" updates="constant" name="Before JS Experiment"/>
         <Param val="" valType="extendedCode" updates="constant" name="Before JS Experiment"/>
         <Param val="" valType="extendedCode" updates="constant" name="Begin Experiment"/>
         <Param val="" valType="extendedCode" updates="constant" name="Begin Experiment"/>
         <Param val="" valType="extendedCode" updates="constant" name="Begin JS Experiment"/>
         <Param val="" valType="extendedCode" updates="constant" name="Begin JS Experiment"/>
@@ -231,7 +231,7 @@
         <Param val="time (s)" valType="str" updates="None" name="startType"/>
         <Param val="time (s)" valType="str" updates="None" name="startType"/>
         <Param val="0.0" valType="code" updates="None" name="startVal"/>
         <Param val="0.0" valType="code" updates="None" name="startVal"/>
         <Param val="duration (s)" valType="str" updates="None" name="stopType"/>
         <Param val="duration (s)" valType="str" updates="None" name="stopType"/>
-        <Param val="" valType="code" updates="constant" name="stopVal"/>
+        <Param val="5" valType="code" updates="constant" name="stopVal"/>
         <Param val="True" valType="bool" updates="None" name="syncScreenRefresh"/>
         <Param val="True" valType="bool" updates="None" name="syncScreenRefresh"/>
         <Param val="128" valType="num" updates="constant" name="texture resolution"/>
         <Param val="128" valType="num" updates="constant" name="texture resolution"/>
         <Param val="from exp settings" valType="str" updates="None" name="units"/>
         <Param val="from exp settings" valType="str" updates="None" name="units"/>
@@ -242,9 +242,9 @@
         <Param val="" valType="extendedCode" updates="constant" name="Begin Experiment"/>
         <Param val="" valType="extendedCode" updates="constant" name="Begin Experiment"/>
         <Param val="" valType="extendedCode" updates="constant" name="Begin JS Experiment"/>
         <Param val="" valType="extendedCode" updates="constant" name="Begin JS Experiment"/>
         <Param val="" valType="extendedCode" updates="constant" name="Begin JS Routine"/>
         <Param val="" valType="extendedCode" updates="constant" name="Begin JS Routine"/>
-        <Param val="win.callOnFlip(trigger.send_trigger, settings.FINGERMODEL_IDS['hold'])&amp;#10;# hold trigger(图片)后5s,出现extend图片&amp;#10;&amp;#10;# 生成3~10s的随机持续时间&amp;#10;random_duration = random.uniform(3, 10)&amp;#10;thisExp.addData('random_duration', random_duration)&amp;#10;#print(f&quot;Holding duration is {random_duration} seconds.&quot;)" valType="extendedCode" updates="constant" name="Begin Routine"/>
+        <Param val="win.callOnFlip(trigger.send_trigger, settings.FINGERMODEL_IDS['hold'])&amp;#10;# hold trigger(图片)后5s,出现extend图片" valType="extendedCode" updates="constant" name="Begin Routine"/>
         <Param val="Py" valType="str" updates="None" name="Code Type"/>
         <Param val="Py" valType="str" updates="None" name="Code Type"/>
-        <Param val="current_time = t&amp;#10;&amp;#10;if current_time &lt; random_duration:&amp;#10;    continueRoutine = True&amp;#10;else:&amp;#10;    continueRoutine = False" valType="extendedCode" updates="constant" name="Each Frame"/>
+        <Param val="" valType="extendedCode" updates="constant" name="Each Frame"/>
         <Param val="" valType="extendedCode" updates="constant" name="Each JS Frame"/>
         <Param val="" valType="extendedCode" updates="constant" name="Each JS Frame"/>
         <Param val="" valType="extendedCode" updates="constant" name="End Experiment"/>
         <Param val="" valType="extendedCode" updates="constant" name="End Experiment"/>
         <Param val="" valType="extendedCode" updates="constant" name="End JS Experiment"/>
         <Param val="" valType="extendedCode" updates="constant" name="End JS Experiment"/>

+ 21 - 17
backend/grasp_data_collection_no_release.py

@@ -2,7 +2,7 @@
 # -*- coding: utf-8 -*-
 # -*- coding: utf-8 -*-
 """
 """
 This experiment was created using PsychoPy3 Experiment Builder (v2023.2.3),
 This experiment was created using PsychoPy3 Experiment Builder (v2023.2.3),
-    on 十二月 21, 2023, at 18:41
+    on 十二月 18, 2023, at 10:48
 If you publish work using this script the most relevant publication is:
 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) 
     Peirce J, Gray JR, Simpson S, MacAskill M, Höchenberger R, Sogo H, Kastman E, Lindeløv JK. (2019) 
@@ -39,7 +39,7 @@ import time
 from device.fubo_pneumatic_finger import FuboPneumaticFingerClient
 from device.fubo_pneumatic_finger import FuboPneumaticFingerClient
 from device.trigger_box import TriggerNeuracle
 from device.trigger_box import TriggerNeuracle
 from settings.config import settings
 from settings.config import settings
-import random
+
 
 
 # get train params
 # get train params
 
 
@@ -177,7 +177,7 @@ def setupData(expInfo, dataDir=None):
     thisExp = data.ExperimentHandler(
     thisExp = data.ExperimentHandler(
         name=expName, version='',
         name=expName, version='',
         extraInfo=expInfo, runtimeInfo=None,
         extraInfo=expInfo, runtimeInfo=None,
-        originPath='D:\\Graduate\\Research\\kraken_project\\backend\\grasp_data_collection_no_release.py',
+        originPath='D:\\Graduate\\kraken\\backend\\grasp_data_collection_no_release.py',
         savePickle=True, saveWideText=True,
         savePickle=True, saveWideText=True,
         dataFileName=dataDir + os.sep + filename, sortColumns='time'
         dataFileName=dataDir + os.sep + filename, sortColumns='time'
     )
     )
@@ -902,11 +902,6 @@ def run(expInfo, thisExp, win, inputs, globalClock=None, thisSession=None):
         # Run 'Begin Routine' code from code_3
         # Run 'Begin Routine' code from code_3
         win.callOnFlip(trigger.send_trigger, settings.FINGERMODEL_IDS['hold'])
         win.callOnFlip(trigger.send_trigger, settings.FINGERMODEL_IDS['hold'])
         # hold trigger(图片)后5s,出现extend图片
         # hold trigger(图片)后5s,出现extend图片
-        
-        # 生成3~10s的随机持续时间
-        random_duration = random.uniform(3, 10)
-        thisExp.addData('random_duration', random_duration)
-        #print(f"Holding duration is {random_duration} seconds.")
         hold_wav.setSound('static/audios/hold.wav', secs=2.5, hamming=True)
         hold_wav.setSound('static/audios/hold.wav', secs=2.5, hamming=True)
         hold_wav.setVolume(1.0, log=False)
         hold_wav.setVolume(1.0, log=False)
         hold_wav.seek(0)
         hold_wav.seek(0)
@@ -926,7 +921,7 @@ def run(expInfo, thisExp, win, inputs, globalClock=None, thisSession=None):
         
         
         # --- Run Routine "hold" ---
         # --- Run Routine "hold" ---
         routineForceEnded = not continueRoutine
         routineForceEnded = not continueRoutine
-        while continueRoutine:
+        while continueRoutine and routineTimer.getTime() < 5.0:
             # get current time
             # get current time
             t = routineTimer.getTime()
             t = routineTimer.getTime()
             tThisFlip = win.getFutureFlipTime(clock=routineTimer)
             tThisFlip = win.getFutureFlipTime(clock=routineTimer)
@@ -953,13 +948,19 @@ def run(expInfo, thisExp, win, inputs, globalClock=None, thisSession=None):
             if hold_img.status == STARTED:
             if hold_img.status == STARTED:
                 # update params
                 # update params
                 pass
                 pass
-            # Run 'Each Frame' code from code_3
-            current_time = t
             
             
-            if current_time < random_duration:
-                continueRoutine = True
-            else:
-                continueRoutine = False
+            # if hold_img is stopping this frame...
+            if hold_img.status == STARTED:
+                # is it time to stop? (based on global clock, using actual start)
+                if tThisFlipGlobal > hold_img.tStartRefresh + 5-frameTolerance:
+                    # keep track of stop time/frame for later
+                    hold_img.tStop = t  # not accounting for scr refresh
+                    hold_img.frameNStop = frameN  # exact frame index
+                    # add timestamp to datafile
+                    thisExp.timestampOnFlip(win, 'hold_img.stopped')
+                    # update status
+                    hold_img.status = FINISHED
+                    hold_img.setAutoDraw(False)
             
             
             # if hold_wav is starting this frame...
             # if hold_wav is starting this frame...
             if hold_wav.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
             if hold_wav.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
@@ -1018,8 +1019,11 @@ def run(expInfo, thisExp, win, inputs, globalClock=None, thisSession=None):
                 thisComponent.setAutoDraw(False)
                 thisComponent.setAutoDraw(False)
         thisExp.addData('hold.stopped', globalClock.getTime())
         thisExp.addData('hold.stopped', globalClock.getTime())
         hold_wav.pause()  # ensure sound has stopped at end of Routine
         hold_wav.pause()  # ensure sound has stopped at end of Routine
-        # the Routine "hold" was not non-slip safe, so reset the non-slip timer
-        routineTimer.reset()
+        # using non-slip timing so subtract the expected duration of this Routine (unless ended on request)
+        if routineForceEnded:
+            routineTimer.reset()
+        else:
+            routineTimer.addTime(-5.000000)
         
         
         # --- Prepare to start Routine "extend" ---
         # --- Prepare to start Routine "extend" ---
         continueRoutine = True
         continueRoutine = True