Usage Guide - Team4414/CSVLogger GitHub Wiki
Welcome to CSVLogger!
This program is a basic utility to help manage periodic logging to the filesystem in the form of a .CSV file.
Here's how to use it:
- Prepare the class to log values from:
- Extend the Loggable class into a class you need to log from.
- Implement the
collectData()
method in this class.- Have this method return an array of Log objects. The first parameter in the constructor is the data "key", or the header to that particular entry in the CSV file. The second parameter is simply the variable of type 'Object' that you wish to log.
Here's an example:
public class Drivetrain extends Loggable {
private double lVel = 0;
private double rVel = 0;
private double xPos = 0;
private double yPos = 0;
//do drivetrain stuff
@Override
protected void LogObject[] collectData(){
return new LogObject[]{
new LogObject("Left Velocity", lVel),
new LogObject("Right Velocity", rVel),
new LogObject("X Position", xPos),
new LogObject("Y Position", yPos)
}
}
}
-
Call the
.log()
method on the class. When the method is called, the variables specified above incollectData()
will be polled and added to a running list (behind the scenes). In other words, every time you call the.log()
method, a "snapshot" of the variables specified above will be collected. -
Whenever you want to publish this running list of "snapshots" to the filesystem, simply call on the static
logCSV()
method in the CSVLogger class.- The first parameter to the
logCSV()
method is a String that represents the name of the saved file- If the file already exists, the file will be overwritten
- If not, the file will be created
- In addition to the file name, you can also provide a filepath to where the file is intended to be saved
- Again, if the subdirectories in said file path do not exist, they will be created
- The second parameter is a
Log
object to be logged- To get this Object from a
Loggable
class, simple call the.get()
method on the class. - It is important to note that this
.get()
method simply copies the file for logging, the originalLog
is not affected/flushed. Any changes to the newLog
object will obviously not transfer to the original runningLog
of theLoggable
class
- To get this Object from a
- The first parameter to the
Here's an example of steps 2 & 3:
public class Robot extends IterativeRobot{
Drivetrain drivetrain;
public Robot{
drivetrain = new Drivetrain();
}
@Override
protected void teleopPeriodic(){
drivetrain.log();
//on every call of this method the variables in the previous example will be collected and stored
}
@Override
protected void disabledInit(){
CSVLogger.logCSV("subsystemLogs/DrivetrainLog", drivetrain.get());
//on every call of this method, the running log will be copied and saved to the folder "subsystemLogs"
//as the file "DrivetrainLog.csv"
}