RunStateMachine()

Description

Runs the last state machine that was loaded to Bpod with SendStateMachine(), and returns events, state transitions and timestamps after the state machine reaches the exit state.

  • This command will block MATLAB execution until data is returned. Scripts to be run during a trial can be added as SoftCodeHandlers and triggered from the state machine.

  • The events returned are in a raw format (not human-readable), and should be subsequently packaged into your session data with the AddTrialEvents() function.

Syntax

RawEvents = RunStateMachine()

Parameters

-None

Returns

  • A struct with the following fields:

    • States: a vector listing the integer codes of states visited, in sequential order.

      • The list of codes can be found in BpodSystem.StateMatrix.StateNames

    • Events: a vector listing the byte codes of events captured.

      • The list of events can be found in BpodSystem.StateMachineInfo.EventNames

    • StateTimestamps: a vector listing the entry times of each state listed in the "States" field (in seconds from matrix start).

    • EventTimestamps: a vector listing the times of each event listed in the "Events" field (in seconds from matrix start).

    • TrialStartTimestamp: The time the matrix started (in seconds from session start).

Example

% This code sends "sma" (a state machine description) to Bpod, runs it 10 times, and packages the raw events for analysis.

SendStateMachine(sma);

SessionData = struct;

for i = 1:10

RawEvents = RunStateMachine;

SessionData = AddTrialEvents(SessionData, RawEvents);

end