class autopilot.core.pilot.autopilot[source]

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

  • PINS - 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

  • 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:

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

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

logger = None
log_handler = None
log_formatter = None
server = None
running = None
stage_block = None
file_block = None
networking = None
node = None

Start logging to a timestamped file in prefs.LOGDIR


Get our IP


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


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


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

Stop the task.

Clear the running event, set the stage block.


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

Parameters:value – ignored

Change a task parameter mid-run


Not Implemented

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

Save the results of a port calibration


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:path – If present, use calibration file specified, otherwise use default.

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


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


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

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.