Hi,
I'm trying to use the Rotary Encoder module during a lever press behavior. In this experiment, the lever starts at position 0 and needs to remain in the home period for a pre-determined amount of time, then pressed forward to a sound threshold, then continue forward to an apex threshold. Then the lever must be pulled back to the home position to trigger the start of the next trial. For some reason, after the lever reaches the apex threshold, it resets to the lever period of a new trial. I think there's an issue with the state machine recognizing that the lever must change directions, but I can't figure out why my thresholds do not work
Here are the advanced threshold values
RotaryEncoder1_1 = 0-3 (lever must remain here during a wait time)
RotaryEncoder1_2 = 20 (plays sound here)
RotaryEncoder1_3 = 40 (point where lever must reach to return home)
RotaryEncoder1_4 = 0 (lever must be brought back home to trigger a new trial - this is the part that does not work)
Here is the state machine code:
`sma = AddState(sma, 'Name', 'TrialStartTrigger',...
'Timer', 0,...
'StateChangeConditions', {'Tup', 'ResetThresholds'},...
'OutputActions', {'RotaryEncoder1', ['#' 0]}); % timestamp a new trial
sma = AddState(sma, 'Name', 'ResetThresholds',...
'Timer', 0,...
'StateChangeConditions', {'Tup', 'WaitPeriod'},...
'OutputActions', {'RotaryEncoder1', '*E'}); % reset all thresholds based on whether gui was updated and enable
sma = AddState(sma, 'Name', 'WaitPeriod',...
'Timer', S.GUI.LeverStillPeriod,...
'StateChangeConditions', {'Tup', 'LeverInit'},... % for testing purposes will always observe the wait period
'OutputActions', {});
sma = AddState(sma, 'Name', 'LeverInit',...
'Timer', 0,...
'StateChangeConditions', {'RotaryEncoder1_1', 'PressLever'},...
'OutputActions', {'RotaryEncoder1', [';' 1]});
sma = AddState(sma, 'Name', 'PressLever',...
'Timer', 2,... % once the lever starts moving, they should do this in a timely manner
'StateChangeConditions', {'RotaryEncoder1_2', 'DeliverStimulus'},...
'OutputActions', {'RotaryEncoder1', [';' 2]});
sma = AddState(sma, 'Name', 'DeliverStimulus',...
'Timer', S.GUI.SoundDuration,...
'StateChangeConditions', {'Tup', 'ReturnThreshold'},... % keep pressing forward to the return threshold
'OutputActions', {'SoftCode', 1, 'BNCState', 1});
sma = AddState(sma, 'Name', 'ReturnThreshold',...
'Timer', 2,... % arbitrary to help with smooth movement
'StateChangeConditions', {'RotaryEncoder1_3', 'DeliverThreshStimulus'},...
'OutputActions', {'RotaryEncoder1', [';' 4],});
sma = AddState(sma, 'Name', 'DeliverThreshStimulus',...
'Timer', S.GUI.SoundDuration,...
'StateChangeConditions', {'Tup', 'PullBack'},...
'OutputActions', {'SoftCode', 1, 'BNCState', 1}); % play sound here just for testing
sma = AddState(sma, 'Name', 'PullBack',...
'Timer', 2,...% must do this in a reasonable amount of time to actually get reward
'StateChangeConditions', {'RotaryEncoder1_4', 'TransitionToNext', 'Tup', 'PullBack'},...
'OutputActions', {'RotaryEncoder1',[';' 8]});
sma = AddState(sma, 'Name', 'TransitionToNext',...
'Timer', 0,...
'StateChangeConditions', {'Tup', 'Exit'},...
'OutputActions', {});
`
Any advice you have would be greatly appreciated!
Thanks!
amk22