The script "processInput.py" takes input from a MyoWare Muscle Sensor through an Analog to Digital Converter (ADC) and sets servos or linear actuator according to the input recieved. The code runs on a Raspberry Pi (we are using a Pi 2 Model B)
A Google Drive folder with other files and documentation related to this project can be found here.
processInput.py
runs in an infinite loop after importing the necessary libraries and initializing variables and objects for the devices. The 5 most recent imput values are stored in a list, and each time the loop iterates and a value is taken, it is added to the list and the least recent input value is removed. The list is ordered least to greatest and the median value is used to set the position of the servo or linear actuator. The value is converted to a value to that is scaled to be in the range of the hardware. The values used to scale the input are stored in a text file that is generated by calibration.py.
from __future__ import division
Let the interpreter know to look for more modules.
import Adafruit_ADS1x15
Library for the ADC
import Adafruit_PCA9685
Library for Servo Hat
A list of libraries that had to be installed on the pi before use can be found here.
Input values from the Myoware sensor's EMG electrodes, after going through the ADC, vary from user to user. Usually, they are around 4000 relaxed and 24000 tensed. calibration.py
detects the user's average relaxed and tensed muscle values, and through an algorithm demonstrated in this Desmos graph, finds the values that the input must be scaled and shifted by to match the hardware's output. These values are saved to a equationValues.txt
and they are read by processInput.py
. calibration.py
also sets the mode ("linear actuator" or "servo" and sets the scale/offset and the min/max values accordingly.