Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to stop the Bpod after 1h automatically
#1
Hi Josh,

I would like to restrict the duration of each behavioral bock to be 1 hour. The tic/toc does not work for me because the behavioral process can be paused in the middle of one trial.

Is there any convenient way to stop the Bpod after 1h automatically?

Thanks,
Xiong
Reply
#2
Hi Xiong,


If you want the hour to include time while the protocol is paused, you could also use:

Code:
% Just before the main loop
startTime = now*100000;

...
% Inside the main loop
currentTime = now*100000;

% At the bottom of the main loop
if (currentTime - startTime >= 3600)
   % End the protocol
end

MATLAB's now() function returns the current time (multiply by 100000 to get seconds, 3600 seconds per hour).

If the idea is to exclude time while the protocol is paused, you can create a local variable, you can add the trial duration of each trial, and compare the sum to 3600:
Code:
% Just before the main loop
totalTrialTime = 0;
...

% After each call to AddTrialEvents()
totalTrialTime = totalTrialTime + (BpodSystem.Data.TrialEndTimestamp(currentTrial) - BpodSystem.Data.TrialStartTimestamp(currentTrial));

% At the bottom of the main loop
if (totalTrialTime >= 3600)
 % End the protocol
end

This works because pauses occur in the inter-trial interval. Please note that your sum will not include the ~7-10ms of dead-time between trials (assuming that you're not using TrialManager).

I hope this helps!
-Josh
Reply
#3
(12-17-2019, 05:21 PM)Josh Wrote: Hi Xiong,


If you want the hour to include time while the protocol is paused, you could also use:

Code:
% Just before the main loop
startTime = now*100000;

...
% Inside the main loop
currentTime = now*100000;

% At the bottom of the main loop
if (currentTime - startTime >= 3600)
  % End the protocol
end

MATLAB's now() function returns the current time (multiply by 100000 to get seconds, 3600 seconds per hour).

If the idea is to exclude time while the protocol is paused, you can create a local variable, you can add the trial duration of each trial, and compare the sum to 3600:
Code:
% Just before the main loop
totalTrialTime = 0;
...

% After each call to AddTrialEvents()
totalTrialTime = totalTrialTime + (BpodSystem.Data.TrialEndTimestamp(currentTrial) - BpodSystem.Data.TrialStartTimestamp(currentTrial));

% At the bottom of the main loop
if (totalTrialTime >= 3600)
 % End the protocol
end

This works because pauses occur in the inter-trial interval. Please note that your sum will not include the ~7-10ms of dead-time between trials (assuming that you're not using TrialManager).

I hope this helps!
-Josh

Hi Josh,

This seems does not work for me. The behavioral task that I am using is an operand task that mice will gradually reduce the motivation to finish the whole trial (the task requires more actions in the later phase). The trial was paused usually during the middle steps of a trial, but not the ITI period (the trial can be paused for several minitues). So I cannot use the "now" function in the Matlab to get the current time, because the Matlab process was paused in the "RawEvents = RunStateMatrix;" line.

Thanks,
Josh
Reply


Forum Jump: