Mechatronics
Documentation for ME 405 labs
Lab0x03

Files

file  Button.py
 Button class for detecting button actions.
 
file  main.py
 Contains the main finite state machine for Lab 0x03.
 
file  UI_front.py
 Contains the front-end User Interface for interacting with the Nucleo.
 

Classes

class  Button.Button
 A button class that reports precisely when it is pressed. More...
 
class  main.State
 A class to hold the current state of the FSM. More...
 

Functions

def main.generate (time_s, data)
 Generate a CSV entry to send to the front end of the format "time, counts".
 
def UI_front.main ()
 Run the frontend user interface for determining the time constant of the Nucleo's user button. More...
 
def UI_front.clean_data (raw_data)
 Reformat the raw data into a list of strings. More...
 
def UI_front.gen_csv (filename, data)
 Generate a .CSV file from the given data. More...
 
def UI_front.calc_time_constant (times, values)
 Calculate the time constant of a button rising edge. More...
 
def UI_front.gen_image (filename, data)
 Generate a plot of user button rising edge response. More...
 

Variables

 main.A0 = ADC(Pin.cpu.A0)
 Global A0 object for ADC counting.
 
string main.START_DATA_COLLECTION = "START_DATA_COLLECTION\n".encode("ascii")
 Define a constant for data collection start.
 
string main.STOP_DATA_COLLECTION = "STOP_DATA_COLLECTION\n".encode("ascii")
 Define a constant for data collection stop.
 
int main.BUFF_SIZE = 5000
 Define a constant buffer size (number of data points)
 
int main.SAMPLE_PERIOD = 10
 Define a constant period in microseconds (time between data points)
 
int main.LOWER_THRESHOLD = 10
 Any ADC reading below this is considered LOW.
 
int main.UPPER_THRESHOLD = 4000
 Any ADC reading below this is considered HIGH.
 
string UI_front.START_DATA_COLLECTION = "START_DATA_COLLECTION\n".encode("ascii")
 Define a constant for data collection start.
 
string UI_front.STOP_DATA_COLLECTION = "STOP_DATA_COLLECTION\n".encode("ascii")
 Define a constant for data collection stop.
 
bool UI_front.UI_DEBUG = True
 set a debug flag for extra messages and buffer space
 

Detailed Description

Function Documentation

◆ calc_time_constant()

def UI_front.calc_time_constant (   times,
  values 
)

Calculate the time constant of a button rising edge.

Parameters
timesA List of time stamps in seconds, must be the same length as values
valuesA List of values of ADC counts

◆ clean_data()

def UI_front.clean_data (   raw_data)

Reformat the raw data into a list of strings.

Convert raw data into a friendlier format for plotting.

No longer rejects malformed data points.

Parameters
raw_dataRaw data in the form of an array.array of bytes
raw_dataA List of raw data collected from the nucleo in the form of JSON dictionaries.
Returns
A dictionary of the complete response, made of equal-length lists. Units:
  • Distances [m]
  • Angles [rad]
  • Velocities [m/s]
  • Angular Velocities [rad/s]
  • Torques [N-m]

◆ gen_csv()

def UI_front.gen_csv (   filename,
  data 
)

Generate a .CSV file from the given data.

Parameters
filenameFilename to write the .CSV file into
dataData (a List of strings) to write to the CSV file

◆ gen_image()

def UI_front.gen_image (   filename,
  data 
)

Generate a plot of user button rising edge response.

Plots Time(s) vs. Voltage (ADC counts) and reports the Time Constant

Parameters
filenameThe name of the file to write plot to
dataA list of strings of the form "time,value" to be plotted

◆ main()

def UI_front.main ( )

Run the frontend user interface for determining the time constant of the Nucleo's user button.

Launches a terminal-based UI. If the user presses ‘G,’ the Nucleo should begin sampling data. When data collection is complete, the script generates both an image (using matplotlib) and a .CSV file of data (timestamps and data readings). The plot also reports the time constant of the rising edge. The environment variable ST_LINK must be set to the port that serial communication will be executed on.