Looptick functions

In parallel mode, it is possible to use looptick functions. Looptick functions are while-loops running at a client. The advantage of looptick functions is that processing on the BrainStream side can influence the behavior of the loop. We will first describe the general characteristics of looptick functions and then show how BrainStream can modify the loop.

Structure of looptick functions

The figure below gives a schematic overview of a looptick function:


A looptick function always has the input arguments tick_count and abort_loop. The tick_count variable is automatically increased by one each time the looptick function is called. [abort_loop?].

A looptick function should always produce the output arguments stoploop and waittime. If stoploop is set to 1, the loop will be finalized. If stoploop is set to 0, the looptick function will be called again. The waittime variable specifies the time in seconds until the next looptick call. For example, if you want to have an interval of 200 ms between successive calls to the looptick function, you must set the waittime variable to 0.2.

All calls to the looptick function belong to the same event. Thus, information can be passed between different calls to the looptick functions via the event structure. For example, if your looptick function presents a sequence of stimuli to the subject and you want to pass the last presented stimuli to the next call of the looptick function, you could make a field event.laststim and place your last stimulus in this field every time the looptick function is called. During the next call, the information can be retrieved from this event field.

Format of looptick functions

Looptick functions should have the following format:

function [event, stoploop, waittime] = looptickfunction(event, tick_count, abort_loop)
stoploop = 0;
waittime = 0;

if tick_count == 1
   % do initializations before the loop starts
if dosomething % add your own expression to determine moment of action
   % do it
   % set waittime > 0 if next looptick call can be delayed
   % set stoploop = 1 if you want to stop the loop
if abort_loop
   % finalize stuff before BrainStream forces the loop to exit

Specifying looptick functions in the Actions table

To specify a looptick function in the experiment definition table, you must add a column with header 'looptick'. In this column, one function can be specified. Defining a second looptick function for one marker will produce an error. In the client column, specify on which client the looptick function should run. If the function column defines functions also, they will be executed prior to entering the loop.

Below an example Actions table is shown:

marker time function looptick client
mrk1 EVENT fnc1 my_looptick stim
    fnc2   stim

When marker mrk1 arrives, first functions fnc1 and fnc2 will be executed on client 'stim'. When these functions have finished, looptick function my_looptick will be called. It will keep running on the client until the loop is finished or BrainStream aborts the loop.

Modifying the loop

Information from the BrainStream side can be sent to clients to influence the behaviour of looptick functions. In the BrainStream Matlab session, you can execute the function

success = bs_send_user_client(event, client_nickname, uservars) 

event = even structure
client_nickname = name of the client as specified in block file
uservars = variables to be sent

success = whether variables were sent successfully

On the client side, the user variables that were sent from BrainStream can be received with the function

varargout = bs_recv_user_brainstream(event, client_nickname)

So, you can start each call to the looptick function with checking if there is new information from the BrainStream side. For example, if you do your classification on the BrainStream side, your classification function might send a variable 'classified' when it has made a reliable estimate about which stimulus a subject is attending to. If the looptick function receives this variable, it means that the stimulus presentation can be stopped, so the stoploop variable can be set to 1 and the looptick function will end. In this way, actions at a client can be influenced by information from the BrainStream side.


An example of a looptick function is described in Part 5 of the Visual Speller example.

Topic attachments
I Attachment Action Size Date Who Comment
pngpng looptick2.png manage 101.0 K 06 Jan 2012 - 13:45 MarjoleinVanDerWaal  
Edit | Attach | Print version | History: r5 | r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r1 - 06 Jan 2012 - 15:45:01 - MarjoleinVanDerWaal
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback