pilot

Classes:

Message([msg, expand_arrays])

A formatted message.

Net_Node(id, upstream, port, listens[, …])

Drop in networking object to be given to any sub-object behind some external-facing Station object.

Pilot([splash])

Drives the Raspberry Pi

Pilot_Station()

Station object used by Pilot objects.

Functions:

linregress(x[, y])

Calculate a linear least-squares regression for two sets of measurements.

class Pilot(splash=True)[source]

Bases: object

Drives the Raspberry Pi

Coordinates the hardware and networking objects to run tasks.

Typically used with a connection to a Terminal object to coordinate multiple subjects and tasks, but a high priority for future releases is to do the (trivial amount of) work to make this class optionally standalone.

Called as a module with the -f flag to give the location of a prefs file, eg:

python pilot.py -f prefs_file.json

if the -f flag is not passed, looks in the default location for prefs (ie. /usr/autopilot/prefs.json)

Needs the following prefs (typically established by setup.setup_pilot):

  • NAME - The name used by networking objects to address this Pilot

  • BASEDIR - The base directory for autopilot files (/usr/autopilot)

  • PUSHPORT - Router port used by the Terminal we connect to.

  • TERMINALIP - IP Address of our upstream Terminal.

  • MSGPORT - Port used by our own networking object

  • HARDWARE - Any hardware and its mapping to GPIO pins. No pins are required to be set, instead each task defines which pins it needs. Currently the default configuration asks for

    • POKES - hardware.Beambreak

    • LEDS - hardware.LED_RGB

    • PORTS - hardware.Solenoid

  • AUDIOSERVER - Which type, if any, audio server to use (‘jack’, ‘pyo’, or ‘none’)

  • NCHANNELS - Number of audio channels

  • FS - Sampling rate of audio output

  • JACKDSTRING - string used to start the jackd server, see the jack manpages eg:

    jackd -P75 -p16 -t2000 -dalsa -dhw:sndrpihifiberry -P -rfs -n3 -s &
    
  • PIGPIOMASK - Binary mask of pins for pigpio to control, see the pigpio docs , eg:

    1111110000111111111111110000
    
  • PULLUPS - Pin (board) numbers to pull up on boot

  • PULLDOWNS - Pin (board) numbers to pull down on boot.

Variables

Methods:

blank_LEDs()

If any ‘LEDS’ are defined in prefs.HARDWARE , instantiate them, set their color to [0,0,0], and then release them.

calibrate_port(port_name, n_clicks, …)

Run port calibration routine

calibration_curve([path, calibration])

# compute curve to compute duration from desired volume

get_ip()

Get our IP

handshake()

Send the terminal our name and IP to signal that we are alive

init_audio()

Initialize an audio server depending on the value of prefs.AUDIOSERVER

init_logging()

Start logging to a timestamped file in prefs.LOGDIR

init_pigpio()

l_bandwidth(value)

Send messages with a poissonian process according to the settings in value

l_cal_port(value)

Initiate the calibrate_port() routine.

l_cal_result(value)

Save the results of a port calibration

l_param(value)

Change a task parameter mid-run

l_start(value)

Start running a task.

l_stop(value)

Stop the task.

open_file()

Setup a table to store data locally.

run_task(task_class, task_params)

Called in a new thread, run the task.

update_state()

Send our current state to the Terminal, our Station object will cache this and will handle any future requests.

Attributes:

file_block

log_formatter

log_handler

logger

networking

node

running

server

stage_block

logger = None
log_handler = None
log_formatter = None
server = None
running = None
stage_block = None
file_block = None
networking = None
node = None
init_logging()[source]

Start logging to a timestamped file in prefs.LOGDIR

get_ip()[source]

Get our IP

handshake()[source]

Send the terminal our name and IP to signal that we are alive

update_state()[source]

Send our current state to the Terminal, our Station object will cache this and will handle any future requests.

l_start(value)[source]

Start running a task.

Get the task object by using value[‘task_type’] to select from tasks.TASK_LIST , then feed the rest of value as kwargs into the task object.

Calls autopilot.run_task() in a new thread

Parameters

value (dict) – A dictionary of task parameters

l_stop(value)[source]

Stop the task.

Clear the running event, set the stage block.

Todo

Do a coherence check between our local file and the Terminal’s data.

Parameters

value – ignored

l_param(value)[source]

Change a task parameter mid-run

Warning

Not Implemented

Parameters

value

l_cal_port(value)[source]

Initiate the calibrate_port() routine.

Parameters

value (dict) – Dictionary of values defining the port calibration to be run, including - port - which port to calibrate - n_clicks - how many openings should be performed - open_dur - how long the valve should be open - iti - ‘inter-trial interval`, or how long should we wait between valve openings.

calibrate_port(port_name, n_clicks, open_dur, iti)[source]

Run port calibration routine

Open a hardware.gpio.Solenoid repeatedly, measure volume of water dispersed, compute lookup table mapping valve open times to volume.

Continuously sends progress of test with CAL_PROGRESS messages

Parameters
  • port_name (str) – Port name as specified in prefs

  • n_clicks (int) – number of times the valve should be opened

  • open_dur (int, float) – how long the valve should be opened for in ms

  • iti (int, float) – how long we should sleep() between openings

l_cal_result(value)[source]

Save the results of a port calibration

l_bandwidth(value)[source]

Send messages with a poissonian process according to the settings in value

calibration_curve(path=None, calibration=None)[source]

# compute curve to compute duration from desired volume

Parameters
  • calibration

  • path – If present, use calibration file specified, otherwise use default.

init_pigpio()[source]
init_audio()[source]

Initialize an audio server depending on the value of prefs.AUDIOSERVER

blank_LEDs()[source]

If any ‘LEDS’ are defined in prefs.HARDWARE , instantiate them, set their color to [0,0,0], and then release them.

open_file()[source]

Setup a table to store data locally.

Opens prefs.DATADIR/local.h5, creates a group for the current subject, a new table for the current day.

Returns

(tables.File, tables.Table, tables.tableextension.Row): The file, table, and row for the local data table

run_task(task_class, task_params)[source]

Called in a new thread, run the task.

Opens a file with open_file() , then continually calls task.stages.next to process stages.

Sends data back to the terminal between every stage.

Waits for the task to clear stage_block between stages.