Set up UI between Spyder and Nucleo to collect and plot data. More...
Functions | |
def | PC_FrontEnd.sendChar (last_key) |
Sends a string through serial to Nucleo. More... | |
def | PC_FrontEnd.kb_cb (key) |
Callback function inside keyboard module. More... | |
def | PC_FrontEnd.writeToCSV (data, filename) |
Strip and split the data into a csv file from the Nucleo. More... | |
def | PC_FrontEnd.plotData (csvFileName, col1, col2, y1label, y2label, plotTitle, fileName, Kp, Ki, J) |
Plot the position and speed data from the encoders. More... | |
def | PC_FrontEnd.sampleCSV (refCSV, ctrlPeriod, filename) |
Sample the reference data at a lower resolution. More... | |
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 according to a specific function, and when prompted or timed out, will send the data back to Spyder to be plotted. See source code here: https://bitbucket.org/MatthewFrostCP/me305_bblabs/src/master/Lab_Final/PC_FrontEnd.py
def 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 PC_FrontEnd.plotData | ( | csvFileName, | |
col1, | |||
col2, | |||
y1label, | |||
y2label, | |||
plotTitle, | |||
fileName, | |||
Kp, | |||
Ki, | |||
J | |||
) |
Plot the position and speed data from the encoders.
The subplot feature within matlibplot will be utilized to visualize the position and speed of the motors along with the reference data to see the difference in position and speed at all points in time.
csvFileName | Specifies the file to grab the data from. |
col1 | Speciifes which column of data to plot on the x axis. |
col2 | Speciifes which column of data to plot on the y axis. |
y1label | Specifies the vertical label for the first subplot. |
y2label | Specifies the vertical label for the second subplot. |
plotTitle | Specifies a plot title for the figure. |
fileName | Specifies the name of what to save the figure to. |
Kp | The proportional gain used in testing that is currently being plotted. |
Ki | The integral gain used in testing that is currently being plotted. |
J | The error metric of the tracking precision currently being plotted. |
def PC_FrontEnd.sampleCSV | ( | refCSV, | |
ctrlPeriod, | |||
filename | |||
) |
Sample the reference data at a lower resolution.
Since the data cannot be loaded entirely onto the Nucleo for memory reasons, it must be sampled at a specific rate. This allows for the high-resolution data to be reduced to a more reasonable resolution, as specified by the ctrlPeriod.
refCSV | Filename for the reference csv file of data. |
ctrlPeriod | The frequency that the data should be sampled. |
filename | The specific file to save the data to. |
def 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 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. |