Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Behavior timeout and logic judegement within session
#1
Hi Josh,

I have two issues. 
1. Is it possible to exit from the whole loop rather than the current loop? In my case, I'd like to terminate the session if mice did not have an action within a specific period (like 5        minutes). However, 'exit' only allows me to step out of the current loop.
2. Is it possible to measure the interval between two different events and then decide the next state according to the interval? In my case, I need mice to poke for at least 1s.              If they stayed in the poke for >=1s, they will get the reward. Otherwise, they need to poke again and the timer will recount from 0.

Thanks, advance,
Lei
Reply
#2
Hello Lei,

To terminate the session, you have to add some MATLAB code to determine whether a state was greater than some threshold.
For instance, if you have a state:


Code:
sma = AddState(sma, 'Name', 'WaitForAction', ...
   'Timer', 300,...
   'StateChangeConditions', {'Port1In', 'NextState', 'Tup', '>exit'},...
   'OutputActions', {});

After RawEvents = RunStateMachine(), you'd use something like:
Code:
BpodSystem.Data = AddTrialEvents(BpodSystem.Data,RawEvents);
StartTime = BpodSystem.Data.RawEvents.Trial{currentTrial}.States.WaitForAction(1);
EndTime = BpodSystem.Data.RawEvents.Trial{currentTrial}.States.WaitForAction(2);
if EndTime - StartTime >= 299
RunProtocol('Stop');
end

Please let me know if this works for you.

Regarding the interval, you can split the state in two - when a sufficient sampling time has passed, move to a second state you'd only reach if you had waited. This branches the state machine description, unfortunately. 

-Josh
Reply
#3
(06-03-2021, 09:52 PM)Hi Josh,Thank you for the quick response. Regarding the termination of experiment, your solution does not work for me, as I did not simply count the duration of a specific state. In fact, as long as mice generated an action, the counter should restart. I succefully used a second timer- global timer2, which can be triggered again by an action, to solve this issue. Wrote:
Code:
sma = AddState(sma, 'Name', 'ResetGlobalCounter', ...
       'Timer', 0,...
       'StateChangeConditions', {'Tup', 'TriggerGlobalTimer1'},...
       'OutputActions', {'GlobalCounterReset', 1});
   
sma = AddState(sma, 'Name', 'TriggerGlobalTimer1', ...
       'Timer', 0,...
       'StateChangeConditions', {'Tup', 'TriggerGlobalTimer2'},...
       'OutputActions', {'GlobalTimerTrig', 1});
   
sma = AddState(sma, 'Name', 'TriggerGlobalTimer2', ...
       'Timer', 0,...
       'StateChangeConditions', {'Tup', 'WaitForPoke'},...
       'OutputActions', {'GlobalTimerTrig', 2});
   
sma = AddState(sma, 'Name', 'WaitForPoke', ...
       'Timer', 0, ...
       'StateChangeConditions', {'GlobalCounter1_End','WaitForLick',BehaviorAction, 'TriggerGlobalTimer2','GlobalTimer1_End','exit','GlobalTimer2_End','exit'}, ...
       'OutputActions', {});
Then if ... break was used to step out of the experiment based on whether some following states were skipped.

For the interval issue, I actually don't understand your solution. Can you examplify for me? Remember, this state duration was dependent on mice's response and once mice left the poke, the timer will count from 0 when they poked again.

Thanks very much
Lei
Reply
#4
Hi Lei,

Is this what you're looking for?


Code:
sma = NewStateMachine;

sma = AddState(sma, 'Name', 'WaitForPoke', ...
   'Timer', 0,...
   'StateChangeConditions', {'Port1In', 'NextState'},...
   'OutputActions', {});
sma = AddState(sma, 'Name', 'MeasurePoke', ...
   'Timer', 1,...
   'StateChangeConditions', {'Port1Out', 'WaitForPoke', 'Tup', 'Reward'},...
   'OutputActions', {});

The first state waits indefinitely for a poke.
The second state measures 1s, during which the system returns to the first state if the subject pokes out.
After 1s, the system proceeds to a reward state.
-Josh
Reply
#5
Hi Josh,

This is exactly what I was looking for. Thanks for the solution.

Lei
Reply


Forum Jump: