示例#1
0
def water_drop(open_time, ntrials=100, iti=1, bpod="bpod_instance"):
    if bpod == "bpod_instance":
        print("Need a Bpod instance to run a protocol")
        return 0

    # Start state machine definition
    for i in range(ntrials):

        sma = StateMachine(bpod)

        # open and close valve
        sma.add_state(
            state_name="reward",
            state_timer=open_time,
            state_change_conditions={"Tup": "iti"},
            output_actions=[("Valve1", 255)],
        )

        sma.add_state(
            state_name="iti",
            state_timer=iti,
            state_change_conditions={"Tup": "exit"},
            output_actions=[],
        )

        # Send state machine description to Bpod device and run
        bpod.send_state_machine(sma)
        if not bpod.run_state_machine(
                sma):  # Locks until state machine 'exit' is reached
            break
def water_drop(open_time, ntrials=100, iti=1, bpod='bpod_instance'):
    if bpod == 'bpod_instance':
        print('Need a Bpod instance to run a protocol')
        return 0

    # Start state machine definition
    for i in range(ntrials):

        sma = StateMachine(bpod)

        # open and close valve
        sma.add_state(
            state_name='reward',
            state_timer=open_time,
            state_change_conditions={'Tup': 'iti'},
            output_actions=[('Valve1', 255)])

        sma.add_state(
            state_name='iti',
            state_timer=iti,
            state_change_conditions={'Tup': 'exit'},
            output_actions=[])

        # Send state machine description to Bpod device and run
        bpod.send_state_machine(sma)
        bpod.run_state_machine(sma)
示例#3
0
def trial():
    for trial in range(trials):
        # send ttl to bnc1
        sma = StateMachine(bpod)
        # sart state blink green two times
        sma.add_state(
            state_name="start1",
            state_timer=1,
            state_change_conditions={"Tup": "start2"},
            output_actions=[("Serial1", 1), ("SoftCode", 2)],
        )
        sma.add_state(
            state_name="start2",
            state_timer=1,
            state_change_conditions={"Tup": "start3"},
            output_actions=[("BNC1", 1)],
        )
        sma.add_state(
            state_name="start3",
            state_timer=1,
            state_change_conditions={"Tup": "reset_rotary_encoder2"},
            output_actions=[],
        )
        # detect rotary encoder movement left -> blink red light
        sma.add_state(
            state_name="reset_rotary_encoder2",
            state_timer=0,
            state_change_conditions={"Tup": "detect"},
            output_actions=[("Serial1", 1)],
        )
        sma.add_state(
            state_name="detect",
            state_timer=30,
            state_change_conditions={
                movement_left: "blink_red_1x",
                movement_right: "blink_red_1x",
                "Tup": "start1"
            },
            output_actions=[("BNC1", 1)],
        )
        # blink red
        sma.add_state(
            state_name="blink_red_1x",
            state_timer=1,
            state_change_conditions={"Tup": "reset_rotary_encoder"},
            output_actions=[("BNC2", 1), ("Serial1", 2), ("SoftCode", 1)],
        )
        # reset rotary encoder to positin 0
        sma.add_state(
            state_name="reset_rotary_encoder",
            state_timer=0,
            state_change_conditions={"Tup": "exit"},
            output_actions=[("Serial1", 1)],
        )

        bpod.send_state_machine(sma)
        # Run state machine
        bpod.run_state_machine(sma)
    message1.stop()
示例#4
0
from pybpodapi.bpod import Bpod
from pybpodapi.state_machine import StateMachine

bpod = Bpod()

trials = 10
iti = 2

for trial in range(trials):

    # send ttl to bnc1
    sma = StateMachine(bpod)

    # initial state
    sma.add_state(
        state_name="start",
        state_timer=5,
        state_change_conditions={"Tup": "reward"},
        output_actions=[("BNC1", 1)],
    )

    # open valve1 for 20 seconds
    sma.add_state(
        state_name="reward",
        # output action will be performed for whole time state is active
        state_timer=20,
        state_change_conditions={"Tup": "exit"},
        # output action for valve open = 255
        # notation for valve alsways Valve + numer of port connected to
        output_actions=[("Valve1", 255)],
    )
my_bpod = Bpod()

# ----> Start the task
for valvetime in valvetimes:

    ValveOpenTime_L = valvetime

    ValveOpenTime_R = valvetime
    ValveOpenTime_M = valvetime

    print(ValveOpenTime_R)
    for i in range(Dropnum):  # Main loop
        print('Trial: ', i + 1)

        sma = StateMachine(my_bpod)
        sma.add_state(state_name='Wait',
                      state_timer=100,
                      state_change_conditions={
                          EventName.Port1In: 'Open Left',
                          EventName.Port2In: 'Open Left',
                          EventName.Port7In: 'Open Left',
                          EventName.Port8In: 'Open Left',
                          EventName.Tup: 'exit'
                      },
                      output_actions=[])
        sma.add_state(state_name='Open Left',
                      state_timer=ValveOpenTime_L,
                      state_change_conditions={EventName.Tup: 'wait1'},
                      output_actions=[('Valve', 1)])
        sma.add_state(state_name='wait1',