inline scripts starting time in Coroutines: sending triggers for EEG
Hey everyone,
I've already opened the discussion about sending triggers for EEG from OpenSesame to NIC2 software, and after a while came up with the solution which is on this link.
Now, I'm trying to implement the same inline scripts for sending triggers in the Stop-Signal task which is a bit different in its structure since it has the coroutines item. The triggers are being sent, and communication between the two software is established but the timing of triggers onset seems wrong and sometimes random. Also, some of the triggers are being appeared in the trials when they shouldn't or more than once in the same trial which also shouldn't be happening.
You can see the overview of the practice block on the photo below:
The coroutines is consisted of a stimulus presentation sketchpad (which is the Go task, the participant needs to answer whether the triangle or circle is presented on the screen), presentation trigger inline script for sending triggers at the moment when triangle/circle is presented. Then we have a sketchpad for stop signal which is being presented on variable, adaptive delay after the go stimulus. The next item is the inline script for the trigger of Stop-signal presentation which should appear at the same moment as the stop signal. The next item is keyboard response which is related to the response for triangle/circle and then we have the inline script for sending triggers when the response is given.
You can see the coroutines settings on the photo below:
Participant has only 1 second to respond so the duration is set to 1000. Stimulus (Go condition) and go presentation trigger should always be presented at the beginning of the trial so their start time is set to 0. I'm not sure what should be set for the end time in this case (when I tried to put 1000 or some other value, it looked like so many triggers were being sent at the same moment and the NIC2 program would crash in a few seconds). The stop sketchpad is set to start at the adaptive SSD (which is being calculated by other inline scripts in the task). I've tried to put the same value ( [SSD] ) for the start time of presentation_trigger_stop but in that case, the task is crashing when it comes to the particular trial with the stop signal. I have the same doubt about the end time, should it be [SSD] + 1 or something else?
After that, we have the keyboard response item which should be always on and start at the beginning and record the participants response time whenever it happens within the 1-secondIts window. The next item is the inline script for sending triggers at the moment when participant gives the response. Its start time should be keypress (that didn't work when possibly tried it) or the exact time of the keyboard response (which is written on the photo and also didn't work). A possible reason that [response_time_keyboard_response] didn't work is because the variable is still not created before the coroutines have been run, but making that variable in some other inline script beforehand would help because the code wouldn't catch the exact response time from the specific trial. I'm also not sure about the End time for this item in the coroutines.
I think that the problem should be with the set-up of ending and starting times for every item but I'm not sure if I'm on the right way and if I can possibly change some other settings in order to succesfully send triggers at the right time.
I will also share the codes in inline scripts since I'm note sure if there is any mistake :
presentation trigger in the run section :
s.send(('<trigger>'+str(1)+'</trigger>').encode())
presentation trigger stop signal:
if var.stop_signal ==1 : s.send(('').encode())
and response_trigger:
s.send(('').encode()) else: s.send(('').encode())
These inline scripts are sending triggers, but specifically, the presentation trigger is being sent twice at the same moment, and the response trigger 5 (the else one) is being sent too early (with the presentation trigger). In the stop trials, we can observe all three triggers at the same time, practically. If I don't give any keyboard response, the response trigger is being appeared etc...
Does anyone have an idea how can I solve this or how to possibly set [response_time_keyboard_response] or [SSD] for a starting time of the inline scripts or is there any other way to do it via GUI or some simple coding or I should create a custom generator function (I've read a bit about that on the forum)? Thank you so much in advance, I hope that someone can come up with some solution.
All the best,
Uroš
Comments
Hi @Uros ,
If I understand correctly, and to simplify a long story, your main question is how you can send a trigger exactly once and at a predictable moment in the context of
coroutines
. Is that correct?The main thing to understand is that the run phase of an
inline_script
inside acoroutines
is executed over and over again with a frequency that depends on the speed of your computer and the other items that are part of thecoroutines
. See also this page:In your case, you're setting 0 and 1 ms durations for the
inline_script
items with the idea that therefore the code is executed only once. But that doesn't necessarily need to be the case. A more reliable way to accomplish what you need is to have a singleinline_script
that maintains a list of triggers that need to be sent, and sends them exactly once, like so:Insert an
inline_script
into thecoroutines
that runs for the entire duration. In the Prepare phase initialize the triggers:In the Run phase, send each trigger at the right moment:
This should work. One caveat: the triggers aren't explicitly locked to the presentations of the
sketchpads
. So check carefully whether the timing is accurate!— Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!