Matthew's Portfolio
PC_FrontEnd.py File Reference

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...
 

Variables

 PC_FrontEnd.ser = serial.Serial(port='COM5', baudrate=115273, timeout=1)
 Set up serial communication through serial command.
 
bool PC_FrontEnd.introMessage = True
 keeps track of if the intro message should be displayed
 
 PC_FrontEnd.last_key = None
 holds the value of the current keyboard letter
 
string PC_FrontEnd.refCSV = "reference.csv"
 File name of reference data.
 
string PC_FrontEnd.sampledRefCSV = "sampledRefCSV.csv"
 File name of sampled reference data.
 
string PC_FrontEnd.csvFileNameTotal = "LabFinalData.csv"
 File name of the exported data.
 
string PC_FrontEnd.pdfFileNameEnc1 = "Enc1Plot.pdf"
 File name fo Encoder 1.
 
string PC_FrontEnd.pdfFileNameEnc2 = "Enc2Plot.pdf"
 File name fo Encoder 2.
 
string PC_FrontEnd.yLabelEnc1Position = 'Encoder 1 Position'
 Vertical axis label for Encoder 1 Position.
 
string PC_FrontEnd.yLabelEnc2Position = 'Encoder 2 Position'
 Vertical axis label for Encoder 1 Speed.
 
string PC_FrontEnd.yLabelMot1Speed = 'Motor 1 Speed'
 Vertical axis label for Encoder 2 Position.
 
string PC_FrontEnd.yLabelMot2Speed = 'Motor 2 Speed'
 Vertical axis label for Encoder 2 Speed.
 
string PC_FrontEnd.titleEnc1Data = 'Encoder 1 Data'
 Title of Encoder 1 plot.
 
string PC_FrontEnd.titleEnc2Data = 'Encoder 2 Data'
 Title of Encoder 2 plot.
 
list PC_FrontEnd.Keys = ["s","g","p","d","z","m","v","b","P","D","Z","M","V","B"]
 list the specific keys used in the front end
 
 PC_FrontEnd.callback
 
int PC_FrontEnd.frontEndState = 0
 Small FSM state variable within the front end.
 
 PC_FrontEnd.dataFromNucleo = None
 The outputted data from the serial port.
 
int PC_FrontEnd.Kp = 0
 Kp value used in the controller driver.
 
int PC_FrontEnd.Ki = 0
 Kp value used in the controller driver.
 
int PC_FrontEnd.J1 = 0
 J metric for Encoder 1.
 
int PC_FrontEnd.J2 = 0
 J metric for Encoder 2.
 
 PC_FrontEnd.Jvalues = dataFromNucleo[1:]
 The J metrics from the controller task.
 

Detailed Description

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


Figure 1. Task Diagram for Front End


Author
Matthew Frost
Date
Originally created on 02/18/21
Last modified on 03/17/21

Function Documentation

◆ kb_cb()

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.

Parameters
keyThe key that was pressed to trigger the callback function.

◆ plotData()

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.

Parameters
csvFileNameSpecifies the file to grab the data from.
col1Speciifes which column of data to plot on the x axis.
col2Speciifes which column of data to plot on the y axis.
y1labelSpecifies the vertical label for the first subplot.
y2labelSpecifies the vertical label for the second subplot.
plotTitleSpecifies a plot title for the figure.
fileNameSpecifies the name of what to save the figure to.
KpThe proportional gain used in testing that is currently being plotted.
KiThe integral gain used in testing that is currently being plotted.
JThe error metric of the tracking precision currently being plotted.

◆ sampleCSV()

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.

Parameters
refCSVFilename for the reference csv file of data.
ctrlPeriodThe frequency that the data should be sampled.
filenameThe specific file to save the data to.

◆ sendChar()

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.

Parameters
last_keyThe current key that was pressed.

◆ writeToCSV()

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.

Parameters
dataThe data from the serial port that needs to be saved into the CSV.
filenameThe specific file to save the data to.