„scenarios/scripts/p300-tactile-stimulator.lua“ ändern
This commit is contained in:
parent
f198fd7a69
commit
d1b78e738e
@ -1,136 +1,138 @@
|
|||||||
-- This Lua script sends Stimulations to the speller visualization box for a tactile p300-System with 6 stimulators
|
-- This Lua script sends Stimulations to the speller visualization box for a tactile p300-System with 6 stimulators
|
||||||
--
|
--
|
||||||
-- Author : Tobias Baumann
|
-- Author : Tobias Baumann
|
||||||
-- Date : 2021-12-06
|
-- Date : 2021-12-06
|
||||||
-- Revised: 2021-19-11
|
-- Revised: 2021-19-11
|
||||||
|
|
||||||
--This function lets the box sleep until a fixed moment
|
--This function lets the box sleep until a fixed moment
|
||||||
function wait_until(box, time)
|
function wait_until(box, time)
|
||||||
while box:get_current_time() < time do
|
while box:get_current_time() < time do
|
||||||
box:sleep()
|
box:sleep()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--This function lets the box wait for a fixed duration
|
--This function lets the box wait for a fixed duration
|
||||||
function wait_for(box, duration)
|
function wait_for(box, duration)
|
||||||
wait_until(box, box:get_current_time() + duration)
|
wait_until(box, box:get_current_time() + duration)
|
||||||
end
|
end
|
||||||
|
|
||||||
--this function checks, wether value already is an element of the given stim_matrix
|
--this function checks, wether value already is an element of the given stim_matrix
|
||||||
function is_element(matrix, value)
|
function is_element(matrix, value)
|
||||||
for i = 1, #matrix do
|
for i = 1, #matrix do
|
||||||
if #matrix == 0 then
|
if #matrix == 0 then
|
||||||
return(false)
|
return(false)
|
||||||
elseif value == matrix[i] then
|
elseif value == matrix[i] then
|
||||||
return(true)
|
return(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return(false)
|
return(false)
|
||||||
end
|
end
|
||||||
--this function creates a sequence of stimulations by shuffeling the values of the given stim_matrix
|
--this function creates a sequence of stimulations by shuffeling the values of the given stim_matrix
|
||||||
function create_sequence(matrix)
|
function create_sequence(matrix)
|
||||||
math.randomseed(os.time())
|
local stim_matrix = {}
|
||||||
local stim_matrix = {}
|
local stim_code = 0
|
||||||
local stim_code = 0
|
local i = 1
|
||||||
local i = 1
|
while i <= #matrix do
|
||||||
while i <= #matrix do
|
stim_code = matrix[math.random(1,#matrix)]
|
||||||
stim_code = matrix[math.random(1,#matrix)]
|
if is_element(stim_matrix, stim_code) == false then
|
||||||
if is_element(stim_matrix, stim_code) == false then
|
stim_matrix[i] = stim_code
|
||||||
stim_matrix[i] = stim_code
|
i = i + 1
|
||||||
i = i + 1
|
end
|
||||||
end
|
end
|
||||||
end
|
return(stim_matrix)
|
||||||
return(stim_matrix)
|
end
|
||||||
end
|
|
||||||
|
-- this function is called when the box is initialized
|
||||||
-- this function is called when the box is initialized
|
function initialize(box)
|
||||||
function initialize(box)
|
--randomseed
|
||||||
--load stimulation codes
|
math.randomseed(os.time())
|
||||||
dofile(box:get_config("${Path_Data}") .. "/plugins/stimulation/lua-stimulator-stim-codes.lua")
|
|
||||||
|
--load stimulation codes
|
||||||
--load box settings
|
dofile(box:get_config("${Path_Data}") .. "/plugins/stimulation/lua-stimulator-stim-codes.lua")
|
||||||
row_base = _G[box:get_setting(2)]
|
|
||||||
n_tactilos = box:get_setting(3)
|
--load box settings
|
||||||
n_repetitions = box:get_setting(4)
|
row_base = _G[box:get_setting(2)]
|
||||||
n_trials = box:get_setting(5)
|
n_tactilos = box:get_setting(3)
|
||||||
flash_duration = box:get_setting(6)
|
n_repetitions = box:get_setting(4)
|
||||||
noflash_duration = box:get_setting(7)
|
n_trials = box:get_setting(5)
|
||||||
inter_repetition_delay = box:get_setting(8)
|
flash_duration = box:get_setting(6)
|
||||||
inter_trial_delay = box:get_setting(9)
|
noflash_duration = box:get_setting(7)
|
||||||
send_toggle = _G[box:get_setting(10)]
|
inter_repetition_delay = box:get_setting(8)
|
||||||
free_spelling = box:get_setting(11)
|
inter_trial_delay = box:get_setting(9)
|
||||||
time_to_send = box:get_setting(12)
|
send_toggle = _G[box:get_setting(10)]
|
||||||
|
free_spelling = box:get_setting(11)
|
||||||
--Set number of trials to 1 in free spelling mode
|
time_to_send = box:get_setting(12)
|
||||||
if free_spelling == 'true' then
|
|
||||||
n_trials = 1
|
--Set number of trials to 1 in free spelling mode
|
||||||
end
|
if free_spelling == 'true' then
|
||||||
|
n_trials = 1
|
||||||
--Lua variables
|
end
|
||||||
send = false
|
|
||||||
experiment_end = false
|
--Lua variables
|
||||||
tactilo_stimcodes = {}
|
send = false
|
||||||
for x = 1, n_tactilos do
|
experiment_end = false
|
||||||
tactilo_stimcodes[x] = row_base + x - 1
|
tactilo_stimcodes = {}
|
||||||
end
|
for x = 1, n_tactilos do
|
||||||
end
|
tactilo_stimcodes[x] = row_base + x - 1
|
||||||
|
end
|
||||||
-- this function is called when the box is uninitialized
|
end
|
||||||
function uninitialize(box)
|
|
||||||
|
-- this function is called when the box is uninitialized
|
||||||
end
|
function uninitialize(box)
|
||||||
|
|
||||||
-- this function is called once by the box
|
end
|
||||||
function process(box)
|
|
||||||
while box:keep_processing() do
|
-- this function is called once by the box
|
||||||
|
function process(box)
|
||||||
if send and not experiment_end then
|
while box:keep_processing() do
|
||||||
-- iterate over the number of trials
|
|
||||||
for trial = 1, n_trials do
|
if send and not experiment_end then
|
||||||
box:send_stimulation(1, OVTK_StimulationId_RestStart, box:get_current_time() , 0)
|
-- iterate over the number of trials
|
||||||
wait_for(box, inter_trial_delay)
|
for trial = 1, n_trials do
|
||||||
box:send_stimulation(1, OVTK_StimulationId_RestStop, box:get_current_time() , 0)
|
box:send_stimulation(1, OVTK_StimulationId_RestStart, box:get_current_time() , 0)
|
||||||
box:send_stimulation(1, OVTK_StimulationId_TrialStart ,box:get_current_time() , 0)
|
wait_for(box, inter_trial_delay)
|
||||||
|
box:send_stimulation(1, OVTK_StimulationId_RestStop, box:get_current_time() , 0)
|
||||||
-- iterate over the number of repetitions
|
box:send_stimulation(1, OVTK_StimulationId_TrialStart ,box:get_current_time() , 0)
|
||||||
for segment = 1, n_repetitions do
|
|
||||||
tactilo_stimcodes = create_sequence(tactilo_stimcodes)
|
-- iterate over the number of repetitions
|
||||||
box:send_stimulation(1, OVTK_StimulationId_SegmentStart ,box:get_current_time() , 0)
|
for segment = 1, n_repetitions do
|
||||||
|
tactilo_stimcodes = create_sequence(tactilo_stimcodes)
|
||||||
-- iterate over the number of tactilos
|
box:send_stimulation(1, OVTK_StimulationId_SegmentStart ,box:get_current_time() , 0)
|
||||||
for i = 1, #tactilo_stimcodes do
|
|
||||||
box:send_stimulation(1, tactilo_stimcodes[i] ,box:get_current_time() , 0)
|
-- iterate over the number of tactilos
|
||||||
box:send_stimulation(1, OVTK_StimulationId_VisualStimulationStart ,box:get_current_time() , 0)
|
for i = 1, #tactilo_stimcodes do
|
||||||
wait_for(box, flash_duration)
|
box:send_stimulation(1, tactilo_stimcodes[i] ,box:get_current_time() , 0)
|
||||||
box:send_stimulation(1, OVTK_StimulationId_VisualStimulationStop ,box:get_current_time() , 0)
|
box:send_stimulation(1, OVTK_StimulationId_VisualStimulationStart ,box:get_current_time() , 0)
|
||||||
wait_for(box, noflash_duration)
|
wait_for(box, flash_duration)
|
||||||
end
|
box:send_stimulation(1, OVTK_StimulationId_VisualStimulationStop ,box:get_current_time() , 0)
|
||||||
|
wait_for(box, noflash_duration)
|
||||||
box:send_stimulation(1, OVTK_StimulationId_SegmentStop ,box:get_current_time() , 0)
|
end
|
||||||
wait_for(box, inter_repetition_delay)
|
|
||||||
end
|
box:send_stimulation(1, OVTK_StimulationId_SegmentStop ,box:get_current_time() , 0)
|
||||||
|
wait_for(box, inter_repetition_delay)
|
||||||
box:send_stimulation(1, OVTK_StimulationId_TrialStop ,box:get_current_time() , 0)
|
end
|
||||||
|
|
||||||
end
|
box:send_stimulation(1, OVTK_StimulationId_TrialStop ,box:get_current_time() , 0)
|
||||||
|
|
||||||
if free_spelling == 'false' then
|
end
|
||||||
-- end experiment if set to copy spelling
|
|
||||||
box:send_stimulation(1, OVTK_StimulationId_ExperimentStop ,box:get_current_time() , 0)
|
if free_spelling == 'false' then
|
||||||
send = false
|
-- end experiment if set to copy spelling
|
||||||
experiment_end = true
|
box:send_stimulation(1, OVTK_StimulationId_ExperimentStop ,box:get_current_time() , 0)
|
||||||
end
|
send = false
|
||||||
|
experiment_end = true
|
||||||
else if not send and not experiment_end then
|
end
|
||||||
-- delay the start of the experiment by t = time_to_send
|
|
||||||
wait_for(box, time_to_send)
|
else if not send and not experiment_end then
|
||||||
send = true
|
-- delay the start of the experiment by t = time_to_send
|
||||||
box:send_stimulation(1, OVTK_StimulationId_ExperimentStart ,box:get_current_time() , 0)
|
wait_for(box, time_to_send)
|
||||||
end
|
send = true
|
||||||
|
box:send_stimulation(1, OVTK_StimulationId_ExperimentStart ,box:get_current_time() , 0)
|
||||||
end
|
end
|
||||||
-- releases cpu
|
|
||||||
box:sleep()
|
end
|
||||||
end
|
-- releases cpu
|
||||||
|
box:sleep()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user