elephant_vending_machine.libraries.vending_machine module

Abstraction of physical “elephant vending machine”

This module allows for display of images, control of LEDs, and detecting motion sensor input on the machine.

class elephant_vending_machine.libraries.vending_machine.SensorGrouping(address, screen_identifier, config)[source]

Bases: object

Provides an abstraction of the devices controlled by Raspberry Pis.

Pi’s will have an LED strip and a screen. This class will provide utilities for interacting with individual LED strips and screens.

Parameters
  • address (int) – The local IP address of the Pi controlling the SensorGrouping

  • config (dict) – A dictionary with configuration values, should contain REMOTE_LED_SCRIPT_DIRECTORY, a string representing the absolute path to the directory on the remote pis where the LED scripts are stored, and REMOTE_IMAGE_DIRECTORY, a string representing the absolute path to where stimuli images are stored on the remote pis. In the event these values are not passed in, defaults will be assigned as a fallback.

led_color_with_time(red, green, blue, display_time)[source]

Displays the color specified by the given RGB values for time milliseconds.

Parameters
  • red (int) – A number in the range 0-255 specifying how much red should be in the RGB color display.

  • green (int) – A number in the range 0-255 specifying how much green should be in the RGB color display.

  • blue (int) – A number in the range 0-255 specifying how much blue should be in the RGB color display.

  • display_time (int) – The number of milliseconds that LEDs should display the color before returning to an “off” state.

class elephant_vending_machine.libraries.vending_machine.VendingMachine(addresses, config=None)[source]

Bases: object

Provides an abstraction of the physical ‘vending machine’.

This class provides an abstraction of the overall machine, exposing SensorGrouping attributes for control of individual groupings of screen/sensor/LED strip.

Parameters
  • addresses (list) – A list of local IP addresses of the Raspberry Pis

  • config (dict) – A dictionary with configuration values, should contain REMOTE_LED_SCRIPT_DIRECTORY: a string representing the absolute path to the directory on the remote pis where the LED scripts are stored, REMOTE_IMAGE_DIRECTORY: a string representing the absolute path to where stimuli images are stored on the remote pis

static dispense_treat(index)[source]

Sends post request to dispense treat in corresponding tray

Parameters

index – index (from 1 to 3) of the tray to be opened

display_images(images)[source]

Displays images on remote hosts via ssh

Parameters

images – images to be displayed on the screens

signal_sender = ''
ssh_all_hosts(command)[source]

Sends given command to remote hosts via ssh

Parameters

command – command to be sent over ssh

wait_for_input(groups, timeout)[source]

Waits for signal from the monitor pis. If no signal is received by the specified time to wait, returns with a result to indicate this.

Parameters
  • groups (list[SensorGrouping]) – The SensorGroupings which should be monitored for input.

  • timeout (int) – The amount of time in seconds to wait for input before timing out and returning ‘timeout’ (measured in milliseconds).

Returns

A string with value ‘left’, ‘middle’, ‘right’, or ‘timeout’, indicating the selection or lack thereof.

Return type

String

elephant_vending_machine.libraries.vending_machine.get_current_time_milliseconds()[source]

Timeouts will be handled in milliseconds. This method will return the time elapsed since the CPU recieved power in nanoseconds, and thus is only useful for measuring relative time intervals, it is not adjusted for the absolute time.