Set up UI between Spyder and Nucleo to collect and plot data. More...
Functions | |
def | Lab0x03_PC_Frontend.sendChar (last_key) |
Sends a string through serial to Nucleo. More... | |
def | Lab0x03_PC_Frontend.kb_cb (key) |
Callback function inside keyboard module. More... | |
def | Lab0x03_PC_Frontend.writeToCSV (data, filename) |
Strip and split the data into a csv file from the Nucleo. More... | |
def | Lab0x03_PC_Frontend.clearFiles (fileNames) |
Method for deleting files. More... | |
def | Lab0x03_PC_Frontend.processData (originalCSV, newCSV) |
Method for post processing the data. More... | |
def | Lab0x03_PC_Frontend.getTimeConstant (csvInput, pngLinearization, pngFinal) |
Method for getting the time constant. More... | |
Variables | |
Lab0x03_PC_Frontend.ser = serial.Serial(port='COM3', baudrate=115200, timeout=1) | |
Set up serial communication through serial command. | |
bool | Lab0x03_PC_Frontend.introMessage = True |
keeps track of if the intro message should be displayed | |
Lab0x03_PC_Frontend.last_key = None | |
holds the value of the current keyboard letter | |
string | Lab0x03_PC_Frontend.pngInitial = "Lab0x03_allData.png" |
File name for initial plot. | |
string | Lab0x03_PC_Frontend.pngLog = "Lab0x03_logData.png" |
File name for data plotted on log axes. | |
string | Lab0x03_PC_Frontend.pngModified = "Lab0x03_finalPlot.png" |
File name for final plot. | |
string | Lab0x03_PC_Frontend.csvInitial = "Lab0x03_allData.csv" |
File name of the exported data. | |
string | Lab0x03_PC_Frontend.csvModified = "Lab0x03_modifiedData.csv" |
CSV that holds the shortened data. | |
bool | Lab0x03_PC_Frontend.debugFlag = False |
Debugging flag to hide certain print statements. | |
list | Lab0x03_PC_Frontend.callbackKeys = ["g"] |
list the specific keys used in the front end | |
Lab0x03_PC_Frontend.callback | |
Lab0x03_PC_Frontend.dataFromNucleo = None | |
The outputted data from the serial port. More... | |
Lab0x03_PC_Frontend.currentFromNucleo = dataFromNucleo | |
Non empty line from Nucleo serial communication. | |
def | Lab0x03_PC_Frontend.succesfulProcessing = processData(csvInitial,csvModified) |
Flag to show that the data could be successfully processed. | |
def | Lab0x03_PC_Frontend.currentTau = getTimeConstant(csvModified,pngLog,pngModified) |
The time constant gathered from the button's response. | |
Set up UI between Spyder and Nucleo to collect and plot data.
Use the serial port to send and receive data between Spyder console and Nucleo. Nucleo, when told to, will take data of the voltage corresponding to the voltage in the capacitor when the button is released. This should go from having a voltage of 0V to a voltage equal to the supplied voltage (in our case, 3.3V). When the Python script recognizes that a button has been pressed, it will save the data and find the time constant of the capacitor. This is done by post processing the data and allow the user to specify a range in which to compute the time constant. See source code here: https://bitbucket.org/ryanmclaug/matt_ryan_shared/src/master/Lab0x03/Lab0x03_PC_Frontend.py
def Lab0x03_PC_Frontend.clearFiles | ( | fileNames | ) |
Method for deleting files.
Since the csv writer is set to append to a certain file, the file to be written to must be removed each time the PC collects new data. If it was desired, this could be replaced by a method to rename the next file to write to a new file each time. For this, the os
module is used.
fileNames | is a list of strings containing the various files written each time the frontEnd is run |
def Lab0x03_PC_Frontend.getTimeConstant | ( | csvInput, | |
pngLinearization, | |||
pngFinal | |||
) |
Method for getting the time constant.
This method will display the plot for the user, where they can specify the range of time that has a good linear relation to it. This will then plot a line-of-best-fit to the data, where the inverse of the slope is the time constant. This method is much more accurate for numerical data than using the 63.2% of the data method, or finding the tangent line at the start of the data dn finding the time it intersects the steady state value.
csvInput | Input csv to plot data from |
pngLinearization | File name to save the log-axes plot to a png. |
pngFinal | File name for the final plot of voltage time-response. |
def Lab0x03_PC_Frontend.kb_cb | ( | key | ) |
Callback function inside keyboard module.
When keyboard is pressed, it automatically gets sent to the callback function to assign a variable the letter pressed.
key | The key that was pressed to trigger the callback function. |
def Lab0x03_PC_Frontend.processData | ( | originalCSV, | |
newCSV | |||
) |
Method for post processing the data.
Since the button was pressed over a range of 5000ms, but the data applicable is only about 2ms. Thus, the data has to be shortened to only display the relevant data.
originalCSV | The CSV file that contains the raw data. |
newCSV | The new CSV file that contains the shortened data. |
def Lab0x03_PC_Frontend.sendChar | ( | last_key | ) |
Sends a string through serial to Nucleo.
When keyboard is triggered, encode that letter and send it through serial to the Nucleo to read.
last_key | The current key that was pressed. |
def Lab0x03_PC_Frontend.writeToCSV | ( | data, | |
filename | |||
) |
Strip and split the data into a csv file from the Nucleo.
After data collection is finished, the data must be stripped and split in order to write to a csv file.
data | The data from the serial port that needs to be saved into the CSV. |
filename | The specific file to save the data to. |
Lab0x03_PC_Frontend.dataFromNucleo = None |
The outputted data from the serial port.
Most recent data from serial communciation between PC and Nucleo.