CALPOLY MECHATRONICS
Documentation for all Mechatronics Labs
csvResampler.py File Reference

a script to convert between .csv files and python List objects, and resample time based .csv files at a different frequency. More...

Functions

def csvResampler.resampleCSV (file, newFile, timeCol=0, timeStep=0.1)
 Resample a time based .csv file at a different frequency. More...
 
def csvResampler.writeCSV (file, data)
 A method to write a nested List object to a .csv file. More...
 
def csvResampler.readCSV (file)
 A method to load a .csv into a nested List object. More...
 
def csvResampler.searchInterp (data, target, searchCol=0)
 A method to search a nestested List object for a given value using interpolation. More...
 
def csvResampler.linInterp (x, x1, y1, x2, y2)
 A method to linearly interpolate between two points. More...
 

Variables

 csvResampler.file = open('reference.csv')
 
 csvResampler.newFile = open('rescaledReference.csv', 'w')
 
 csvResampler.timeStep
 

Detailed Description

a script to convert between .csv files and python List objects, and resample time based .csv files at a different frequency.

This script is used to create downsampled .csv reference motion profiles to be read by the controller task running on the Nucleo, controller.Controller. This script does not run in sequence with any of the other nucleo or user interface tasks, and is designed only for pre-processing the reference profile data before copying to the Nucleo.

Although this script was only used to downsample one very specific reference profile, it is designed to be general, and can up or downsample any .csv file with at least one ordered time column and any number of rows and columns using linear interpolation. Link to source code: https://bitbucket.org/ebriefer/me305_lab/src/master/Final%20Project/csvResampler.py

Author
Eliot Briefer

Function Documentation

◆ linInterp()

def csvResampler.linInterp (   x,
  x1,
  y1,
  x2,
  y2 
)

A method to linearly interpolate between two points.

Parameters
xThe target x value.
x1The x value of point 1.
y1The y value of point 1.
x2The x value of point 2.
y2The y value of point 2.
Returns
the linearly interpolated y value at x.

◆ readCSV()

def csvResampler.readCSV (   file)

A method to load a .csv into a nested List object.

Parameters
fileThe file object to read from.
Returns
A nested List object containing the data from the .csv file.

◆ resampleCSV()

def csvResampler.resampleCSV (   file,
  newFile,
  timeCol = 0,
  timeStep = 0.1 
)

Resample a time based .csv file at a different frequency.

Parameters
fileThe File object to read from, should be a .csv file.
newFileThe File object to write resampled data to.
timeColThe column in file that contains times.
timeStepThe new time step to sample the data at.

◆ searchInterp()

def csvResampler.searchInterp (   data,
  target,
  searchCol = 0 
)

A method to search a nestested List object for a given value using interpolation.

Parameters
dataThe nested List object to search through. Format should be [[row1], [row2],...].
targetThe target value to search for.
searchColThe column of the nested List to search in.
Returns
the linearly interpolated row list at the target value.

◆ writeCSV()

def csvResampler.writeCSV (   file,
  data 
)

A method to write a nested List object to a .csv file.

Parameters
fileThe File object to write to.
dataThe nested list to convert to a .csv file.