Josh
Excellent, glad I asked.
I am working with Bonsai v2.8.0, Bpod_Gen2 v1.75, and Bpod r2 2.0 (hardware v2, firmware v23).
Feedback so far:
Where the wiki page says
"Another example is provided in the state machine example folder here."
it might help the rank beginner if you say
"Another example which you can test from the command line is provided here:"
otherwise there may be a tendency for a beginner to assume an "example" is something that can be launched from the bpod console, and user might waste time trying to make that work before realizing they need to read the comments in the code.
There were also a few things not immediately obvious about how to run that code; the user has to know to run Bpod() first, and to execute the lines in the code below before running the lines in the comments at top. I have a suggested edit but I'm not seeing how to attach a file, is that not supported? Edited code pasted below.
Pamela
% Example state matrix: Switches states when soft code 5 arrives from an
% external app connected to the state machine's app serial port.
% The name of the app serial port is at: BpodSystem.HW.AppSerialPortName
% Note: This feature is only available on FSM 2 or newer, and requires Firmware v23
% Note: app event byte codes are 0-indexed, in range 0-14
%
% Run this demo from the MATLAB command line, not by launching from the
% Bpod console.
% first launch the Bpod console from the command line:
Bpod()
% then define a state machine whose transitions depend on a softcode:
sma = NewStateMatrix();
sma = AddState(sma, 'Name', 'Port1LightOn', ...
'Timer', 1,...
'StateChangeConditions', {'APP_SoftCode5', 'Port2LightOn'},...
'OutputActions', {'PWM1', 255});
sma = AddState(sma, 'Name', 'Port2LightOn', ...
'Timer', 1,...
'StateChangeConditions', {'Tup', '>exit'},...
'OutputActions', {'PWM2', 255});
% then create a TrialManagerObject:
T = TrialManagerObject;
% Then create an ArCOM serial object with the app serial port:
A = ArCOMObject_Bpod(BpodSystem.HW.AppSerialPortName);
% Then, run the state machine. Note, you can't use RunStateMachine() because
% you'll need to control it from the command line. Instead use:
T.startTrial(sma);
% In the Bpod console you will see that the protocol is now running.
% While the trial is running, send soft code 5 from the command line with:
A.write(5, 'uint8');
% When the trial is over, get the raw data with:
RawEvents = T.getTrialData
% Finally, clear the trial manager and the app serial port:
clear A T
% Note: after this, the protocol will still be running, you can stop it in
% the Bpod console.