Stim Time out on a Mismatch Negativity Scenario

Working with OpenViBE signal processing scenarios and doing scenario/BCI design
Post Reply
Posts: 1
Joined: Sat Jun 23, 2018 12:49 am

Stim Time out on a Mismatch Negativity Scenario

Post by juanjosanv »

Hello, Im working on a Mismath Negativity Scenario in wich I play a Stim A or Stim B randomly.

Ive created the Lua Script for this and its working except I need to have a 10 second delay between each trial. So after the first trial finishes (45 tones played) I need a 10 second rest time. The thing is Ive done this using the following Lua Code:

Code: Select all

 function process(box)  -

-- Delay Function for the loop so we shall insert a 10 second delay

local trial = t

local ti=0
local isi =10

-- Entering the "Busy Wait" function 

function wait_until(box, t)
  while box:get_current_time() <= t+isi do

function wait_for(box, duration)
  wait_until(box, box:get_current_time() + duration)

	box:send_stimulation (1,OVTK_StimulationId_ExperimentStart,ti,0)

-- Time definition

		box:send_stimulation (1,OVTK_StimulationId_TrialStart,ti,0)


	for k=1,4 do

		-- Testing if table values are 1(Stim A) or 2 (Stim B), out of the 52 values only 45 are tested.
		for i=1,45 do
			if trial[i]==1 then
				box:send_stimulation(1,OVTK_StimulationId_Label_00 , t2, 0)
				box:send_stimulation(2, OVTK_StimulationId_Number_01, t2, 0)

		wait_until(box, t_sleep+isi)

Basically I have a table of random 1s and 2s wich if table value is 1 Send Stim via channel A and if it is 2 send stim via channel B.

This code is giving me a time out in the box:send_stimulus function. Does anyone have an idea how can this be worked out? Sorry but Im not a very proficient progammer so any guidance is accepted. The error on console is the next one:

[ WARNING ] At time 44.508 sec <Box algorithm::(0x00004a4d, 0x000075c2) aka Odball Stim LUA> Ignored outdated stimulation 33024 43.000 sec 0.000 sec sent on output 1 - older than last chunk end time 44.500 sec -- And so on for each stim on the second iteration.

Thanks in Advanced for all the help.

Best Regards

Posts: 778
Joined: Tue Dec 04, 2012 3:53 pm
Location: INRIA Rennes, FRANCE

Re: Stim Time out on a Mismatch Negativity Scenario

Post by jtlindgren »

Hi, the problem is that the stimulation is not in the chunk which the kernel expects it to be.

Instead of debugging the issue, one possible approach is just to copy whats done in the motor imagery and ssvep scenarios: simply create all the stimulations right in the beginning and push them out. The OV kernel will take care that they are delivered at appropriate times. You can find examples under "bci-examples/" scenarios. Here's the key part of the motor imagery one for convenience.

Code: Select all

function process(box)

	local t=0

	-- manages baseline

	box:send_stimulation(1, OVTK_StimulationId_ExperimentStart, t, 0)
	t = t + 5

	box:send_stimulation(1, OVTK_StimulationId_BaselineStart, t, 0)
	box:send_stimulation(1, OVTK_StimulationId_Beep, t, 0)
	t = t + baseline_duration

	box:send_stimulation(1, OVTK_StimulationId_BaselineStop, t, 0)
	box:send_stimulation(1, OVTK_StimulationId_Beep, t, 0)
	t = t + 5

	-- manages trials

	for i = 1, number_of_trials*2 do

		-- first display cross on screen

		box:send_stimulation(1, OVTK_GDF_Start_Of_Trial, t, 0)
		box:send_stimulation(1, OVTK_GDF_Cross_On_Screen, t, 0)
		t = t + wait_for_beep_duration

		-- warn the user the cue is going to appear

		box:send_stimulation(1, OVTK_StimulationId_Beep, t, 0)
		t = t + wait_for_cue_duration

		-- display cue

		box:send_stimulation(1, sequence[i], t, 0)
		t = t + display_cue_duration

		-- provide feedback

		box:send_stimulation(1, OVTK_GDF_Feedback_Continuous, t, 0)
		t = t + feedback_duration

		-- ends trial

		box:send_stimulation(1, OVTK_GDF_End_Of_Trial, t, 0)
		t = t + math.random(end_of_trial_min_duration, end_of_trial_max_duration)


	-- send end for completeness	
	box:send_stimulation(1, OVTK_GDF_End_Of_Session, t, 0)
	t = t + 5

	box:send_stimulation(1, OVTK_StimulationId_Train, t, 0)
	t = t + 1
	-- used to cause the acquisition scenario to stop
	box:send_stimulation(1, OVTK_StimulationId_ExperimentStop, t, 0)
Following a similar approach you can add randomness to the timestamps where you need it.

There is no need to add waits to the lua scripts itself. You simply increment the time counter t by 10s after the last event of each trial. This will delay all subsequent events that amount, including the one that causes your stimulator (visualizer) to change state.


Post Reply