pilot
Classes:
|
Drives the Raspberry Pi |
- class Pilot(splash=True, warn_defaults=True)[source]
Bases:
autopilot.agents.base.Agent
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
name (str) – The name used to identify ourselves in
networking
task (
tasks.Task
) – The currently instantiated taskrunning (
threading.Event
) – Flag used to control task running statestage_block (
threading.Event
) – Flag given to a task to signal when task stages finishfile_block (
threading.Event
) – Flag used to wait for file transfersstate (str) – ‘RUNNING’, ‘STOPPING’, ‘IDLE’ - signals what this pilot is up to
pulls (list) – list of
Pull
objects to keep pins pulled up or downserver – Either a
pyo_server()
orJackClient
, sound server.node (
networking.Net_Node
) – Our Net_Node we use to communicate with our main networking objectnetworking (
networking.Pilot_Station
) – Our networking object to communicate with the outside worldip (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.
Attributes:
mp.Event to signal when process is quitting
Methods:
get_ip
()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.
l_start
(value)Start running a task.
l_stop
(value)Stop the task.
l_param
(value)Change a task parameter mid-run
l_cal_port
(value)Initiate the
calibrate_port()
routine.calibrate_port
(port_name, n_clicks, ...)Run port calibration routine
l_cal_result
(value)Save the results of a port calibration
l_bandwidth
(value)Send messages with a poissonian process according to the settings in value
l_stream_video
(value)Start or stop video streaming
calibration_curve
([path, calibration])# compute curve to compute duration from desired volume
Initialize an audio server depending on the value of prefs.get('AUDIOSERVER')
If any 'LEDS' are defined in prefs.get('HARDWARE') , instantiate them, set their color to [0,0,0], and then release them.
Setup a table to store data locally.
run_task
(task_class, task_params)Called in a new thread, run the task.
- server = None
- logger = None
- running = None
- stage_block = None
- file_block = None
- quitting = None
mp.Event to signal when process is quitting
- networking = None
- node = None
- 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
autopilot.get_task()
, 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_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_bandwidth(value)[source]
Send messages with a poissonian process according to the settings in value
- l_stream_video(value)[source]
Start or stop video streaming
- Parameters
value (dict) –
a dictionary of the form:
{ 'starting': bool, # whether we're starting (True) or stopping 'camera': str, # the camera to start/stop, of form 'group.camera_id' 'stream_to': node id that the camera should send to }
- 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_audio()[source]
Initialize an audio server depending on the value of prefs.get(‘AUDIOSERVER’)
‘pyo’ =
pyoserver.pyo_server()
‘jack’ =
jackclient.JackClient
- blank_LEDs()[source]
If any ‘LEDS’ are defined in prefs.get(‘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.get(‘DATADIR’)/local.h5, creates a group for the current subject, a new table for the current day.
Todo
This needs to be unified with a general file constructor abstracted from
Subject
so it doesn’t reimplement file creation!!- Returns
(
tables.File
,tables.Table
,tables.tableextension.Row
): The file, table, and row for the local data table