class autopilot.tasks.task.Task[source]

Bases: object

Generic Task metaclass

  • PARAMS (collections.OrderedDict) –

    Params to define task, like:

    PARAMS = odict() PARAMS[‘reward’] = {‘tag’:’Reward Duration (ms)’,

    PARAMS[‘req_reward’] = {‘tag’:’Request Rewards’,
  • HARDWARE (dict) –

    dict for necessary hardware, like:

    HARDWARE = {
    ‘L’: hardware.Beambreak, …

    }, ‘PORTS’:{

    ’L’: hardware.Solenoid, …



  • PLOT (dict) –

    Dict of plotting parameters, like:

    PLOT = {
    ‘data’: {
    ‘target’ : ‘point’, ‘response’ : ‘segment’, ‘correct’ : ‘rollmean’

    }, ‘chance_bar’ : True, # Draw a red bar at 50% ‘roll_window’ : 50 # number of trials to roll window over


  • Trial_Data (tables.IsDescription) –

    Data table description, like:

    class TrialData(tables.IsDescription):
    trial_num = tables.Int32Col() target = tables.StringCol(1) response = tables.StringCol(1) correct = tables.Int32Col() correction = tables.Int32Col() RQ_timestamp = tables.StringCol(26) DC_timestamp = tables.StringCol(26) bailed = tables.Int32Col()
  • STAGE_NAMES (list) – List of stage method names
  • stage_block (threading.Event) – Signal when task stages complete.
  • punish_stim (bool) – Do a punishment stimulus
  • stages (iterator) – Some generator or iterator that continuously returns the next stage method of a trial
  • triggers (dict) – Some mapping of some pin to callback methods
  • pins (dict) – Dict to store references to hardware
  • pin_id (dict) – Reverse dictionary, pin numbers back to pin letters.
  • punish_block (threading.Event) – Event to mark when punishment is occuring
  • logger (logging.Logger) – gets the ‘main’ logger for now.
PLOT = {}
TrialData = None

Use the HARDWARE dict that specifies what we need to run the task alongside the PINS subdict in prefs to tell us how they’re plugged in to the pi

Instantiate the hardware, assign it Task.handle_trigger() as a callback if it is a trigger.

set_reward(vol=None, duration=None, port=None)[source]

Set the reward value for each of the ‘PORTS’.

  • vol (float, int) – Volume of reward in uL
  • duration (float) – Duration to open port in ms
  • port (None, Port_ID) – If None, set everything in ‘PORTS’, otherwise only set port
handle_trigger(pin, level, tick)[source]

All GPIO triggers call this function with the pin number, level (high, low), and ticks since booting pigpio.

Calls any trigger assigned to the pin in self.triggers , unless during punishment (returns).

  • pin (int) – BCM Pin number
  • level (bool) – True, False high/low
  • tick (int) – ticks since booting pigpio

Set the color of all LEDs at once.

Parameters:color_dict (dict) –

If None, turn LEDs off, otherwise like:

{‘pin’: [R,G,B], ‘pin2: [R,G,B]}


flash lights for punish_dir


Release all hardware objects