Skip to content

Commit

Permalink
Docs updated & moved EventsNames, OutputChannels
Browse files Browse the repository at this point in the history
  • Loading branch information
UmSenhorQualquer committed Jan 18, 2018
1 parent 6661c16 commit 70a7257
Show file tree
Hide file tree
Showing 24 changed files with 641 additions and 691 deletions.
10 changes: 4 additions & 6 deletions docs/source/getting_started/manual_interaction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,20 @@ After :ref:`installing <installing-label>` pybpod-api, open a python terminal an

.. code-block:: python
from pybpodapi.bpod import Bpod # import Bpod main class
from pybpodapi.bpod.hardware.channels import ChannelType # import available types of channels
from pybpodapi.bpod.hardware.channels import ChannelName # import available names of channels
from pybpodapi.protocol import Bpod # import Bpod main class
# connect to bpod
my_bpod = Bpod() # Start bpod
# set poke led connected on port 1 to maximum intensity
my_bpod.manual_override(ChannelType.OUTPUT, ChannelName.PWM, channel_number=1, value=255)
my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.PWM, channel_number=1, value=255)
# set poke led connected on port 1 to half intensity
my_bpod.manual_override(ChannelType.OUTPUT, ChannelName.PWM, channel_number=1, value=128)
my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.PWM, channel_number=1, value=128)
# turn off poke led connected on port 1
my_bpod.manual_override(ChannelType.OUTPUT, ChannelName.PWM, channel_number=1, value=128)
my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.PWM, channel_number=1, value=128)
# disconnect from bpod
my_bpod.stop()
Expand Down
25 changes: 11 additions & 14 deletions docs/source/getting_started/writing_protocols.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ First, you will need to import Bpod modules.
:linenos:
:lineno-start: 1
from pybpodapi.bpod import Bpod # Bpod main module
from pybpodapi.state_machine import StateMachine # State machine module
from pybpodapi.bpod.hardware.events import EventName # Input events labels
from pybpodapi.bpod.hardware.output_channels import OutputChannel # Output action labels
from pybpodapi.protocol import Bpod, StateMachine
2. Initialize Bpod
Expand Down Expand Up @@ -68,12 +65,12 @@ Fun several trials in each Bpod execution. In this example, we will use 5 trials
print('Trial: ', i+1)
thisTrialType = random.choice(trialTypes) # Randomly choose trial type =
if thisTrialType == 1:
stimulus = OutputChannel.PWM1 # set stimulus channel for trial type 1
stimulus = Bpod.OutputChannels.PWM1 # set stimulus channel for trial type 1
leftAction = 'Reward'
rightAction = 'Punish'
rewardValve = 1
elif thisTrialType == 2:
stimulus = OutputChannel.PWM3 # set stimulus channel for trial type 1
stimulus = Bpod.OutputChannels.PWM3 # set stimulus channel for trial type 1
leftAction = 'Punish'
rightAction = 'Reward'
rewardValve = 3
Expand All @@ -95,28 +92,28 @@ Please see :ref:`State Machine API <api_state_machine-label>` for detailed infor
sma.add_state(
state_name='WaitForPort2Poke',
state_timer=1,
state_change_conditions={EventName.Port2In: 'FlashStimulus'},
output_actions=[(OutputChannel.PWM2, 255)])
state_change_conditions={Bpod.Events.Port2In: 'FlashStimulus'},
output_actions=[(Bpod.OutputChannels.PWM2, 255)])
sma.add_state(
state_name='FlashStimulus',
state_timer=0.1,
state_change_conditions={EventName.Tup: 'WaitForResponse'},
state_change_conditions={Bpod.Events.Tup: 'WaitForResponse'},
output_actions=[(stimulus, 255)])
sma.add_state(
state_name='WaitForResponse',
state_timer=1,
state_change_conditions={EventName.Port1In: leftAction, EventName.Port3In: rightAction},
state_change_conditions={Bpod.Events.Port1In: leftAction, Bpod.Events.Port3In: rightAction},
output_actions=[])
sma.add_state(
state_name='Reward',
state_timer=0.1,
state_change_conditions={EventName.Tup: 'exit'},
output_actions=[(OutputChannel.Valve, rewardValve)]) # Reward correct choice
state_change_conditions={Bpod.Events.Tup: 'exit'},
output_actions=[(Bpod.OutputChannels.Valve, rewardValve)]) # Reward correct choice
sma.add_state(
state_name='Punish',
state_timer=3,
state_change_conditions={EventName.Tup: 'exit'},
output_actions=[(OutputChannel.LED, 1), (OutputChannel.LED, 2), (OutputChannel.LED, 3)]) # Signal incorrect choice
state_change_conditions={Bpod.Events.Tup: 'exit'},
output_actions=[(Bpod.OutputChannels.LED, 1), (Bpod.OutputChannels.LED, 2), (Bpod.OutputChannels.LED, 3)]) # Signal incorrect choice
After configuring the state machine, we send it to the Bpod device by calling the method *send_state_machine*. We are then ready to run the next trial, by calling the *run_state_machine* method.
Expand Down
28 changes: 11 additions & 17 deletions examples/function_examples/add_trial_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@
"""

import random

from pybpodapi.bpod import Bpod
from pybpodapi.state_machine import StateMachine
from pybpodapi.bpod.hardware.events import EventName
from pybpodapi.bpod.hardware.output_channels import OutputChannel


from pybpodapi.protocol import Bpod, StateMachine

my_bpod = Bpod()

Expand All @@ -28,12 +22,12 @@

thisTrialType = random.choice(trialTypes) # Randomly choose trial type
if thisTrialType == 1:
stimulus = OutputChannel.PWM1 # set stimulus channel for trial type 1
stimulus = Bpod.OutputChannels.PWM1 # set stimulus channel for trial type 1
leftAction = 'Reward'
rightAction = 'Punish'
rewardValve = 1
elif thisTrialType == 2:
stimulus = OutputChannel.PWM3 # set stimulus channel for trial type 1
stimulus = Bpod.OutputChannels.PWM3 # set stimulus channel for trial type 1
leftAction = 'Punish'
rightAction = 'Reward'
rewardValve = 3
Expand All @@ -43,28 +37,28 @@
sma.add_state(
state_name='WaitForPort2Poke',
state_timer=1,
state_change_conditions={EventName.Port2In: 'FlashStimulus'},
output_actions=[(OutputChannel.PWM2, 255)])
state_change_conditions={Bpod.Events.Port2In: 'FlashStimulus'},
output_actions=[(Bpod.OutputChannels.PWM2, 255)])
sma.add_state(
state_name='FlashStimulus',
state_timer=0.1,
state_change_conditions={EventName.Tup: 'WaitForResponse'},
state_change_conditions={Bpod.Events.Tup: 'WaitForResponse'},
output_actions=[(stimulus, 255)])
sma.add_state(
state_name='WaitForResponse',
state_timer=1,
state_change_conditions={EventName.Port1In: leftAction, EventName.Port3In: rightAction},
state_change_conditions={Bpod.Events.Port1In: leftAction, Bpod.Events.Port3In: rightAction},
output_actions=[])
sma.add_state(
state_name='Reward',
state_timer=0.1,
state_change_conditions={EventName.Tup: 'exit'},
output_actions=[(OutputChannel.Valve, rewardValve)]) # Reward correct choice
state_change_conditions={Bpod.Events.Tup: 'exit'},
output_actions=[(Bpod.OutputChannels.Valve, rewardValve)]) # Reward correct choice
sma.add_state(
state_name='Punish',
state_timer=3,
state_change_conditions={EventName.Tup: 'exit'},
output_actions=[(OutputChannel.LED, 1), (OutputChannel.LED, 2), (OutputChannel.LED, 3)]) # Signal incorrect choice
state_change_conditions={Bpod.Events.Tup: 'exit'},
output_actions=[(Bpod.OutputChannels.LED, 1), (Bpod.OutputChannels.LED, 2), (Bpod.OutputChannels.LED, 3)]) # Signal incorrect choice

my_bpod.send_state_machine(sma) # Send state machine description to Bpod device

Expand Down
53 changes: 25 additions & 28 deletions examples/function_examples/add_trial_events2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
"""

import random
from pybpodapi.bpod import Bpod
from pybpodapi.state_machine import StateMachine
from pybpodapi.bpod.hardware.events import EventName
from pybpodapi.bpod.hardware.output_channels import OutputChannel
from pybpodapi.protocol import Bpod, StateMachine


my_bpod = Bpod()
Expand All @@ -27,12 +24,12 @@

thisTrialType = random.choice(trialTypes) # Randomly choose trial type
if thisTrialType == 1:
stimulus = OutputChannel.PWM1 # set stimulus channel for trial type 1
stimulus = Bpod.OutputChannels.PWM1 # set stimulus channel for trial type 1
leftAction = 'Reward'
rightAction = 'Punish'
rewardValve = 1
elif thisTrialType == 2:
stimulus = OutputChannel.PWM3 # set stimulus channel for trial type 1
stimulus = Bpod.OutputChannels.PWM3 # set stimulus channel for trial type 1
leftAction = 'Punish'
rightAction = 'Reward'
rewardValve = 3
Expand All @@ -44,54 +41,54 @@
sma.add_state(
state_name='WaitForPort2Poke',
state_timer=1,
state_change_conditions={EventName.Port2In: 'FlashStimulus'},
state_change_conditions={Bpod.Events.Port2In: 'FlashStimulus'},
output_actions=[('PWM2', 255)])

sma.add_state(
state_name='FlashStimulus',
state_timer=0.1,
state_change_conditions={EventName.Tup: 'WaitForResponse'},
output_actions=[(stimulus, 255, OutputChannel.GlobalTimerTrig, 1)])
state_change_conditions={Bpod.Events.Tup: 'WaitForResponse'},
output_actions=[(stimulus, 255, Bpod.OutputChannels.GlobalTimerTrig, 1)])

sma.add_state(
state_name='WaitForResponse',
state_timer=1,
state_change_conditions={EventName.Port1In: leftAction,
EventName.Port3In: rightAction,
EventName.Port2In: 'Warning',
EventName.GlobalTimer1_End: 'MiniPunish'},
state_change_conditions={Bpod.Events.Port1In: leftAction,
Bpod.Events.Port3In: rightAction,
Bpod.Events.Port2In: 'Warning',
Bpod.Events.GlobalTimer1_End: 'MiniPunish'},
output_actions=[])

sma.add_state(
state_name='Warning',
state_timer=0.1,
state_change_conditions={EventName.Tup: 'WaitForResponse',
EventName.GlobalTimer1_End: 'MiniPunish'},
output_actions=[(OutputChannel.LED, 1),
(OutputChannel.LED, 2),
(OutputChannel.LED, 3)]) # Reward correct choice
state_change_conditions={Bpod.Events.Tup: 'WaitForResponse',
Bpod.Events.GlobalTimer1_End: 'MiniPunish'},
output_actions=[(Bpod.OutputChannels.LED, 1),
(Bpod.OutputChannels.LED, 2),
(Bpod.OutputChannels.LED, 3)]) # Reward correct choice

sma.add_state(
state_name='Reward',
state_timer=0.1,
state_change_conditions={EventName.Tup: 'exit'},
output_actions=[(OutputChannel.Valve, rewardValve)]) # Reward correct choice
state_change_conditions={Bpod.Events.Tup: 'exit'},
output_actions=[(Bpod.OutputChannels.Valve, rewardValve)]) # Reward correct choice

sma.add_state(
state_name='Punish',
state_timer=3,
state_change_conditions={EventName.Tup: 'exit'},
output_actions=[(OutputChannel.LED, 1),
(OutputChannel.LED, 2),
(OutputChannel.LED, 3)]) # Signal incorrect choice
state_change_conditions={Bpod.Events.Tup: 'exit'},
output_actions=[(Bpod.OutputChannels.LED, 1),
(Bpod.OutputChannels.LED, 2),
(Bpod.OutputChannels.LED, 3)]) # Signal incorrect choice

sma.add_state(
state_name='MiniPunish',
state_timer=1,
state_change_conditions={EventName.Tup: 'exit'},
output_actions=[(OutputChannel.LED, 1),
(OutputChannel.LED, 2),
(OutputChannel.LED, 3)]) # Signal incorrect choice
state_change_conditions={Bpod.Events.Tup: 'exit'},
output_actions=[(Bpod.OutputChannels.LED, 1),
(Bpod.OutputChannels.LED, 2),
(Bpod.OutputChannels.LED, 3)]) # Signal incorrect choice

my_bpod.send_state_machine(sma) # Send state machine description to Bpod device

Expand Down
2 changes: 1 addition & 1 deletion examples/function_examples/bpod_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

from pybpodapi.bpod import Bpod
from pybpodapi.protocol import Bpod
from pysettings import conf


Expand Down
36 changes: 17 additions & 19 deletions examples/function_examples/manual_override.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

import time

from pybpodapi.bpod import Bpod
from pybpodapi.bpod.hardware.channels import ChannelType
from pybpodapi.bpod.hardware.channels import ChannelName
from pybpodapi.protocol import Bpod

import examples.settings as settings

Expand All @@ -24,79 +22,79 @@
### PORT 1 LED ###

print("Set LED of port 1 to max intensity")
my_bpod.manual_override(ChannelType.OUTPUT, ChannelName.PWM, channel_number=1, value=255)
my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.PWM, channel_number=1, value=255)
time.sleep(wait_active_time_ms)

print("Set LED of port 1 to lower intensity")
my_bpod.manual_override(ChannelType.OUTPUT, ChannelName.PWM, channel_number=1, value=8)
my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.PWM, channel_number=1, value=8)
time.sleep(wait_active_time_ms)

print("Set LED of port 1 to zero intensity")
my_bpod.manual_override(ChannelType.OUTPUT, ChannelName.PWM, channel_number=1, value=0)
my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.PWM, channel_number=1, value=0)
time.sleep(1)

### PORT 2 LED ###

print("Set LED of port 2 to max intensity")
my_bpod.manual_override(ChannelType.OUTPUT, ChannelName.PWM, channel_number=2, value=255)
my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.PWM, channel_number=2, value=255)
time.sleep(wait_active_time_ms)

print("Set LED of port 2 to lower intensity")
my_bpod.manual_override(ChannelType.OUTPUT, ChannelName.PWM, channel_number=2, value=8)
my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.PWM, channel_number=2, value=8)
time.sleep(wait_active_time_ms)

print("Set LED of port 2 to zero intensity")
my_bpod.manual_override(ChannelType.OUTPUT, ChannelName.PWM, channel_number=2, value=0)
my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.PWM, channel_number=2, value=0)
time.sleep(1) # Wait 1s

### PORT 1 VALVE ###

print("Set valve of port 1 to open")
my_bpod.manual_override(ChannelType.OUTPUT, ChannelName.VALVE, 1, value=1)
my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.VALVE, 1, value=1)
time.sleep(wait_active_time_ms)

print("Set valve of port 1 to close")
my_bpod.manual_override(ChannelType.OUTPUT, ChannelName.VALVE, 1, value=0)
my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.VALVE, 1, value=0)
time.sleep(1) # Wait 1s

### PORT 3 VALVE ###

print("Set valve of port 3 to open")
my_bpod.manual_override(ChannelType.OUTPUT, ChannelName.VALVE, channel_number=3, value=1)
my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.VALVE, channel_number=3, value=1)
time.sleep(wait_active_time_ms) # Wait 250ms

print("Set valve of port 3 to close")
my_bpod.manual_override(ChannelType.OUTPUT, ChannelName.VALVE, channel_number=3, value=0)
my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.VALVE, channel_number=3, value=0)
time.sleep(1) # Wait 1s

### PORT 2 BNC ###

print("Set BNC output ch2 to high")
my_bpod.manual_override(ChannelType.OUTPUT, ChannelName.BNC, channel_number=2, value=1)
my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.BNC, channel_number=2, value=1)
time.sleep(0.01) # Wait 10ms

print("Set BNC output ch2 to low")
my_bpod.manual_override(ChannelType.OUTPUT, ChannelName.BNC, channel_number=2, value=0)
my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.BNC, channel_number=2, value=0)
time.sleep(1) # Wait 1s

### PORT 3 Wire ###

print("Set Wire output ch3 to high")
my_bpod.manual_override(ChannelType.OUTPUT, ChannelName.WIRE, channel_number=3, value=1)
my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.WIRE, channel_number=3, value=1)
time.sleep(0.01) # Wait 10ms

print("Set Wire output ch3 to low")
my_bpod.manual_override(ChannelType.OUTPUT, ChannelName.WIRE, channel_number=3, value=0)
my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.WIRE, channel_number=3, value=0)
time.sleep(1) # Wait 1s

### PORT 2 Serial ###

print("Send byte 65 on UART port 2")
my_bpod.manual_override(ChannelType.OUTPUT, ChannelName.SERIAL, channel_number=2, value=65)
my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.SERIAL, channel_number=2, value=65)
time.sleep(0.01) # Wait 10ms

print("Send byte 66 on UART port 1")
my_bpod.manual_override(ChannelType.OUTPUT, ChannelName.SERIAL, channel_number=1, value=66)
my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.SERIAL, channel_number=1, value=66)

# Stop Bpod
my_bpod.stop() # Sends a termination byte and closes the serial port. PulsePal stores current params to its EEPROM.

0 comments on commit 70a7257

Please sign in to comment.