Пример #1
0
from pybpodapi.protocol import Bpod, StateMachine
my_bpod = Bpod(emulator_mode=True)
sma = StateMachine(my_bpod)
# Set global timer 1 for 5 seconds
sma.set_global_timer(timer_id=1, timer_duration=5)
sma.add_state(state_name='state1',
              state_timer=1,
              state_change_conditions={Bpod.Events.Tup: 'state2'},
              output_actions=[(Bpod.OutputChannels.GlobalTimerTrig, 1)])
for i in range(2, 10):
    sma.add_state(state_name=f'state{i}',
                  state_timer=0.2,
                  state_change_conditions={Bpod.Events.Tup: f'state{i+1}'},
                  output_actions=[])
# The next one shouldn't fire except after 15 seconds
sma.add_state(state_name='state10',
              state_timer=0,
              state_change_conditions={Bpod.Events.GlobalTimer1_End: 'exit'},
              output_actions=[])
my_bpod.send_state_machine(sma)
my_bpod.run_state_machine(sma)
my_bpod.close()
Пример #2
0
from pybpodapi.protocol import Bpod, StateMachine
my_bpod = Bpod(emulator_mode=True)
sma = StateMachine(my_bpod)
# Set global timer 1 for 3 seconds, following a 1.5 second onset delay after
# trigger. Link to LED of port 2.
sma.set_global_timer(timer_id=1, timer_duration=3, on_set_delay=1.5,
                     channel=Bpod.OutputChannels.PWM2, on_message=255)
sma.add_state(
    state_name='TimerTrig',  # Trigger global timer
    state_timer=0,
    state_change_conditions={Bpod.Events.Tup: 'Port1Lit_Pre'},
    output_actions=[('GlobalTimerTrig', 1)])
sma.add_state(
    state_name='Port1Lit_Pre',
    state_timer=.25,
    state_change_conditions={Bpod.Events.Tup: 'Port3Lit_Pre',
                             Bpod.Events.GlobalTimer1_Start: 'Port1Lit_Post'},
    output_actions=[(Bpod.OutputChannels.PWM1, 16)])
sma.add_state(
    state_name='Port3Lit_Pre',
    state_timer=.25,
    state_change_conditions={Bpod.Events.Tup: 'Port1Lit_Pre',
                             Bpod.Events.GlobalTimer1_Start: 'Port3Lit_Post'},
    output_actions=[(Bpod.OutputChannels.PWM3, 16)])
sma.add_state(
    state_name='Port1Lit_Post',
    state_timer=.25,
    state_change_conditions={
        Bpod.Events.Tup: 'Port3Lit_Post',
        Bpod.Events.GlobalTimer1_End: 'exit'},
    output_actions=[(Bpod.OutputChannels.PWM1, 255)])
Пример #3
0
"""
Example adapted from Josh Sanders' original version on Sanworks Bpod repository
"""
from pybpodapi.protocol import Bpod, StateMachine

"""
Run this protocol now
"""

my_bpod = Bpod()

sma = StateMachine(my_bpod)

# Set global timer 1 for 3 seconds, following a 1.5 second onset delay after trigger. Link to channel BNC2.
sma.set_global_timer(timer_id=1, timer_duration=3, on_set_delay=1.5, channel='BNC2')

sma.add_state(
	state_name='TimerTrig',  # Trigger global timer
	state_timer=0,
	state_change_conditions={Bpod.Events.Tup: 'Port1Lit'},
	output_actions=[(Bpod.OutputChannels.GlobalTimerTrig, 1)])

sma.add_state(
	state_name='Port1Lit',  # Infinite loop (with next state). Only a global timer can save us.
	state_timer=.25,
	state_change_conditions={Bpod.Events.Tup: 'Port3Lit', 'GlobalTimer1_End': 'exit'},
	output_actions=[(Bpod.OutputChannels.PWM1, 255)])

sma.add_state(
	state_name='Port3Lit',