Change sma (e.g. value of global timer) of next trial based on previous trial

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change sma (e.g. value of global timer) of next trial based on previous trial
#1
I am hoping to have a global random process that determines when each tone is presented in each trial. Say I have tone timing at 5.6s, 8.4s, 14.9s, etc, and the first trial last for 7s, second last for 5s, then the tone is presented at 5.6s, 1.4s, 2.9s on the first 3 trials. 
Basically I need to change the time of the global timers in each trial based on the duration of the preceding trial, which will be determined by the action of the mice on that trial. Currently, we send the state of next trials into the state machine before we execute this trial, meaning that we can’t change the sma of the next trial after we get the time of this trial (e.g. from the RawEvent variable). So I am wondering:
 
1. if there is a way to dynamically change the sma (specifically the value of global timers) of the future trial based on the data from the previous trial.
Two additional questions:
2. if there is a way to pause a global timer and pick it up afterwards, instead of triggering and cancelling it
3. is ‘GlobalTimer1_End’ only triggered when the timer just ended, or is it a continuous state (of 0 or 1)
 
Our current code is below:
 
sma = PrepareStateMachine(S, TrialTypes, 1, []); % Prepare state machine for trial 1 with empty "current events" variable
TrialManager.startTrial(sma); % Sends & starts running first trial's state machine. A MATLAB timer object updates the
                              % console UI, while code below proceeds in parallel.
% In this case, we don't need trial events to build the state machine - but
% they are available in currentTrialEvents.
%% Main trial loop
for currentTrial = 1:MaxTrials
    currentTrialEvents = TrialManager.getCurrentEvents({'WaitForLick', 'OpenValve'}); % Hangs here until Bpod enters one of the listed trigger states, then returns current trial's states visited + events captured to this point
    if BpodSystem.Status.BeingUsed == 0; return; end % If user hit console "stop" button, end session
    [sma, S] = PrepareStateMachine(S, TrialTypes, currentTrial+1, currentTrialEvents); % Prepare next state machine.
    % Since PrepareStateMachine is a function with a separate workspace, pass any local variables needed to make
    % the state machine as fields of settings struct S e.g. S.learningRate = 0.2.
    SendStateMachine(sma, 'RunASAP'); % With TrialManager, you can send the next trial's state machine while the current trial is ongoing
    RawEvents = TrialManager.getTrialData; % Hangs here until trial is over, then retrieves full trial's raw data
…… etc.
 
I.e. I want to use ‘RawEvents’ of this trial to change the sma of the next trial.
Please let me know if that is possible.
 
Thank you very very much
Ziyi Zhu
Reply
#2
(09-16-2019, 02:44 PM)ziyi Wrote: I am hoping to have a global random process that determines when each tone is presented in each trial. Say I have tone timing at 5.6s, 8.4s, 14.9s, etc, and the first trial last for 7s, sesscond last for 5s, then the tone is presented at 5.6s, 1.4s, 2.9s on the first 3 trials. 
Basically I need to change the time of the global timers in each trial based on the duration of the preceding trial, which will be determined by the action of the mice on that trial. Currently, we send the state of next trials into the state machine before we execute this trial, meaning that we can’t change the sma of the next trial after we get the time of this trial (e.g. from the RawEvent variable). So I am wondering:
 
1. if there is a way to dynamically change the sma (specifically the value of global timers) of the future trial based on the data from the previous trial.
Two additional questions:
2. if there is a way to pause a global timer and pick it up afterwards, instead of triggering and cancelling it
s ss
Our current code is below:
 
sma = PrepareStateMachine(S, TrialTypes, 1, []); % Prepare state machine for trial 1 with empty "current events" variable
TrialManager.startTrial(sma); % Sends & starts running first trial's state machine. A MATLAB timer object updates the
                              % console UI, while code below proceeds in parallel.
% In this case, we don't need trial events to build the state machine - but
% they are available in currentTrialEvents.
%% Main trial loop
for currentTrial = 1:MaxTrials
    currentTrialEvents = TrialManager.getCurrentEvents({'WaitForLick', 'OpenValve'}); % Hangs here until Bpod enters one of the listed trigger states, then returns current trial's states visited + events captured to this point
    if BpodSystem.Status.BeingUsed == 0; return; end % If user hit console "stop" button, end session
    [sma, S] = PrepareStateMachine(S, TrialTypes, currentTrial+1, currentTrialEvents); % Prepare next state machine.
    % Since PrepareStateMachine is a function with a separate workspace, pass any local variables needed to make
    % the state machine as fields of settings struct S e.g. S.learningRate = 0.2.
    SendStateMachine(sma, 'RunASAP'); % With TrialManager, you can send the next trial's state machine while the current trial is ongoing
    RawEvents = TrialManager.getTrialData; % Hangs here until trial is over, then retrieves full trial's raw data
…… etc.
 
I.e. I want to use ‘RawEvents’ of this trial to change the sma of the next trial.
Please let me know if that is possible.
 
Thank you very very much
Ziyi Zhu
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)