Hi Josh,
I am trying to "teleport" the position of a wheel at the beginning of a new state by setting a new position using the output action {'RotaryEncoder1' ['P' 2-bytearray]} with no luck. Here is my code.
%%
startingPositionsWheelInDegree = [-90 90];
startingPositionsWheelInTics = round(startingPositionsWheelInDegree*1024/360);
startingPositionsWheelInTics_TwoBytesArray = [];
for idxPos = 1:length(startingPositionsWheelInTics)
int16Number = int16(startingPositionsWheelInTics(idxPos));
byteArray = typecast(int16Number, 'uint8');
byteArray = fliplr(byteArray);
startingPositionsWheelInTics_TwoBytesArray = [startingPositionsWheelInTics_TwoBytesArray; byteArray];
end
newPosition1 = {'RotaryEncoder1', ['P' char(startingPositionsWheelInTics_TwoBytesArray( 1, : ))]};
newPosition2 = {'RotaryEncoder1', ['P' char(startingPositionsWheelInTics_TwoBytesArray( 2, : ))]};
BpodSystem.Data.StartingPositionsWheelInDegree = [];
R = RotaryEncoderModule('/dev/cu.usbmodem35800201');
R.wrapPoint = 360 * 32;
R.startUSBStream;
for currentTrial = 1:2
S = BpodParameterGUI('sync', S);
sma = NewStateMachine();
sma = AddState(sma, 'Name', 'State1', ...
'Timer', 2,...
'StateChangeConditions', {'Tup', 'State2'},...
'OutputActions', newPosition1);
sma = AddState(sma, 'Name', 'State2', ...
'Timer', 2,...
'StateChangeConditions', {'Tup', 'State3'},...
'OutputActions', newPosition2);
sma = AddState(sma, 'Name', 'State3', ...
'Timer', 2,...
'StateChangeConditions', {'Tup', '>exit'},...
'OutputActions', {'RotaryEncoder1' 'Z'});
SendStateMachine(sma);
RawEvents = RunStateMachine;
if ~isempty(fieldnames(RawEvents))
BpodSystem.Data = AddTrialEvents(BpodSystem.Data,RawEvents);
BpodSystem.Data.TrialSettings(currentTrial) = S;
BpodSystem.Data.EncoderData{currentTrial} = R.readUSBStream();
BpodSystem.Data.StartingPositionsWheelInDegree(currentTrial) = startingPositionsWheelInDegree(currentTrial);
SaveBpodSessionData;
end
HandlePauseCondition;
if BpodSystem.Status.BeingUsed == 0
R.stopUSBStream;
return
end
end
R.stopUSBStream;
%%
I also tried 'OutputActions,' {'RotaryEncoder1', ['P' 'x' '1']} at the end of State1 and State2; however, plotting the recorded Encoder.Data revealed that the position had not been changed at the beginning of the two states. Can you please help me?