bpod_core.bpod.Bpod
- class bpod_core.bpod.Bpod
Bases:
SerialDevice,AbstractBpodClass for interfacing with a Bpod Finite State Machine.
- close() None
Close the connection to the Bpod.
Waits for any running trial to finish before closing the serial port.
- Raises:
SerialException – If the port could not be closed.
- Return type:
- get_data(*, concat=True, rechunk=False, lazy=False)
Return trial data from the data queue.
- Parameters:
concat (
bool, default:True) – IfTrue, pop and concatenate all DataFrames currently in the queue into a single DataFrame, blocking until at least one is available. IfFalse, pop and return one DataFrame, blocking until one is available.rechunk (
bool, default:False) – IfTrue, make sure that the result data is in contiguous memory. Only applies whenconcat=True.lazy (
bool, default:False) – IfTrue, return apolars.LazyFrame. IfFalse, return apolars.DataFrame.
- Returns:
One trial’s data, or all available trials concatenated when
concat=True.Columns:
time– absolute Bpod timestamp (Datetime(time_unit='us'))trial– zero-based trial index (UInt16)state– state name (Categorical)type– event type (Enum)event– input event name (Categorical)channel– channel name (Categorical)value– channel value (UInt8)
- Return type:
pl.DataFrame- Raises:
BpodError – If the queue is empty and no state machine is currently running.
- peek_data(trigger_states=None, *, lazy=False)
Return a snapshot of the current trial’s data.
- Parameters:
- Returns:
Events recorded so far in the current trial. Returns an empty DataFrame if no trial is running.
- Return type:
pl.DataFrameorpl.LazyFrame- Raises:
ValueError – If one or several of the trigger states are not part of the state machine.
- run(state_machine=None, *, validate=True) None
Run a state machine on the Bpod.
Validates, compiles, sends, and queues a state machine for immediate execution. If the Bpod is currently running a state machine, the new one is queued to run as soon as the current one finishes, with no inter-trial gap.
If called without an argument, the previously sent state machine is re-sent from the compilation cache and queued for immediate back-to-back execution.
- Parameters:
state_machine (
StateMachine, optional) – The state machine to run. If not provided, the previously sent state machine is repeated.validate (
bool, default:True) – If False, the state machine will not be validated prior to compilation. This will speed up the process, but may result in errors or unexpected behavior if the state machine is invalid. Use with caution.
- Raises:
RuntimeError – If called without an argument and no state machine has been run yet.
ValueError – If the state machine is invalid or exceeds hardware limitations.
validate_callCallHintViolation – If function arguments don’t match type hints.
- Return type:
Notes
This method returns once the state machine has been queued on the Bpod. The Bpod will then begin executing the state machine as soon as possible — immediately if the device is idle or right after the current state machine finishes. Subsequent calls of this method will result in continuous acquisition and zero inter-trial downtime (as long as the Bpod’s run queue stays filled).
See also
validate_state_machineValidation of state machines.
waitBlock until the currently running state machine finishes.
- send_softcode(softcode) None
Send a softcode to the state machine.
Can be used to trigger transitions.
- Parameters:
softcode (
int) – The softcode value to send.- Raises:
ValueError – If
softcodeis out of range.- Return type:
- set_softcode_handler(softcode_handler=None) None
Set the handler function for softcodes sent from the Bpod.
- Parameters:
softcode_handler (
Callable, optional) – The function to call when a softcode is received.- Return type:
- validate_state_machine(state_machine) None
Validate the provided state machine for compatibility with the hardware.
- Parameters:
state_machine (
StateMachine) – The state machine to validate.- Raises:
ValueError – If the state machine is invalid or not compatible with the hardware.
- Return type:
- wait() None
Wait for the currently running state machine to finish.
Blocks until the state machine thread completes. If no state machine is currently running, this method returns immediately.
- Return type:
-
inputs:
NamedTuple Available input channels.
- modules: _ModuleDict
Available modules, keyed by name.
-
outputs:
NamedTuple Available output channels.
- property port: str
The name of the serial port.
- Returns:
The device path of the serial port (e.g., ‘/dev/ttyACM0’).
- Return type:
- property serial0: ExtendedSerial
Primary serial device for communication with the Bpod.
-
serial1:
ExtendedSerial|None= None Secondary serial device for communication with the Bpod.
-
serial2:
ExtendedSerial|None= None Tertiary serial device for communication with the Bpod - used by Bpod 2+ only.
- property version: VersionInfo
Version information of the Bpod’s firmware and hardware.