Drives the Raspberry Pi
Coordinates the hardware and networking objects to run tasks.
Typically used with a connection to a
Terminalobject 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
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.
- name (str) – The name used to identify ourselves in
- task (
tasks.Task) – The currently instantiated task
- running (
threading.Event) – Flag used to control task running state
- stage_block (
threading.Event) – Flag given to a task to signal when task stages finish
- file_block (
threading.Event) – Flag used to wait for file transfers
- state (str) – ‘RUNNING’, ‘STOPPING’, ‘IDLE’ - signals what this pilot is up to
- pulls (list) – list of
Pullobjects to keep pins pulled up or down
- server – Either a
JackClient, sound server.
- node (
networking.Net_Node) – Our Net_Node we use to communicate with our main networking object
- networking (
networking.Pilot_Station) – Our networking object to communicate with the outside world
- ip (str) – Our IPv4 address
- listens (dict) – Dictionary mapping message keys to methods used to process them.
- logger (
logging.Logger) – Used to log messages and network events.
- log_handler (
logging.FileHandler) – Handler for logging
- log_formatter (
Formats log entries as:
"%(asctime)s %(levelname)s : %(message)s"
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.
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
Parameters: value –
calibrate_port(port_name, n_clicks, open_dur, iti)¶
Save the results of a port calibration
Send messages with a poissonian process according to the settings in value
# 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.
tables.tableextension.Row): The file, table, and row for the local data table