Bpod¶
- class bpod_core.bpod.Bpod ¶
Bases:
SerialDevice,AbstractBpodClass for interfacing with a Bpod Finite State Machine.
- close() ¶
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 (
Datetime) – absolute Bpod timestamp.trial (
UInt16) – zero-based trial index.state machine (
Categorical) – state machine hash, seehash().state (
Categorical) – state name.type (
Enum) – event type.event (
Categorical) – input event name.channel (
Categorical) – channel name.value (
UInt8) – channel value.
- Return type:
- Raises:
BpodError – If the queue is empty and no state machine is currently running.
- open() ¶
Open the connection to the Bpod.
- Raises:
SerialException – If the port could not be opened.
BpodError – If the handshake fails.
- Return type:
- peek_data(trigger_states=None, *, lazy=False) ¶
Return a snapshot of the current trial’s data.
- Parameters:
trigger_states (
Collectionofstr, optional) – Block until at least one of the given states has been entered, then return the snapshot. IfNone(default), returns immediately.lazy (
bool, default:False) – IfTrue, return apolars.LazyFrame. IfFalse(default), return apolars.DataFrame.
- Returns:
Events recorded so far in the current trial. Returns an empty DataFrame if no trial is running.
- Return type:
- Raises:
ValueError – If one or several of the trigger states are not part of the state machine.
- reset_session_clock() ¶
Reset the Bpod session clock.
- run(state_machine=None, *, trial_number=None, validate=True) ¶
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.trial_number (
int, optional) – The trial number to assign to the state machine. If not provided, the trial number is automatically incremented with each run.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.
ValidationError – 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) ¶
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) ¶
Set the handler function for softcodes sent from the Bpod.
- set_status_led(enable) ¶
Enable or disable the Bpod status LED.
- validate_state_machine(state_machine) ¶
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() ¶
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:
- 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.