diff --git a/.gitignore b/.gitignore
index d79c45b..6dbecad 100644
--- a/.gitignore
+++ b/.gitignore
@@ -40,6 +40,7 @@
*.class
# Log file
+logs/
*.log
# BlueJ files
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 2dc4958..94f2d9b 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -28,24 +28,9 @@
"java.test.defaultConfig": "WPIlibUnitTests",
"java.completion.importOrder": ["", "javax", "java", "#"],
"java.format.enabled": true,
- "java.editor.formatOnSave": true,
"java.format.settings.url": ".vscode/eclipse-java-google-style.xml",
"[java]": {
"editor.tabSize": 4,
"editor.detectIndentation": false
},
- "cSpell.words": [
- "Atclause",
- "checkstyle",
- "DEADBAND",
- "deadbands",
- "javadoc",
- "loggables",
- "lvuser",
- "markdownlint",
- "photogate",
- "puppycrawl"
- ],
- "java.checkstyle.configuration": "${workspaceFolder}/checkstyle.xml",
- "java.checkstyle.version": "8.39"
}
diff --git a/README.md b/README.md
index 510a574..0f76093 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,109 @@
-# RA22_RobotCode
+# RA22_RobotCode Logger Documentation
-Red Alert's 2022 Robot Code
+Welcome to the docs for the Red Alert Robotics 2022 Robot Code Logger System.
+
+DISCLAIMER: This document assumes you know how Java works. If not, it is strongly recommended that you learn Java before utilizing the logger, or ask somebody who does know Java.
+
+## Usage
+To show how to use the logger system, this document will demonstrate the creation of a `Loggable` object and how to register it in the log file.
+
+### Create the Loggable
+1. Go to ***/src/main/java/frc/robot/logging*** and create a new Java file. The naming system used for the loggables are like this: *Loggable*, followed immediately by the name of the system being logged. For demonstrations purposes, let's call it *LoggableTest.java*.
+
+2. Inside this file, create a new class. You'll also need to have it implement *Loggable.java*. This contains the methods needed to accumulate data to send to the log file. No import will be needed, as *Loggable.java* is in the same file as our *LoggableTest* class.
+```java
+package frc.robot.logging
+
+public class LoggableTest implements Loggable {
+
+}
+```
+
+
+3. Next you'll need to implement the methods from *Loggable.java*. The first method is `logHeaders()`, which is for logging the type of data. It is called only when the robot starts. The second method is `logData()`. This is called approximately 30 times a second. **Make sure to have the `@Override` decorator above both methods.**
+```java
+package frc.robot.logging
+
+public class LoggableTest implements Loggable {
+ @Override
+ public void logHeaders(Logger logger) {
+
+ }
+
+ @Override
+ public void logData(Logger logger) {
+
+ }
+}
+```
+
+
+4. In the `logHeaders()` method, we will have two headers: *first_name*, and *last_name*. So, we need to use the `logger` parameter to access the necessary method to add these headers.
+```java
+package frc.robot.logging
+
+public class LoggableTest implements Loggable {
+ @Override
+ public void logHeaders(Logger logger) {
+ logger.addHeader("first_name");
+ logger.addHeader("last_name");
+ }
+
+ @Override
+ public void logData(Logger logger) {
+
+ }
+}
+```
+
+
+5. Now let's add our data. Under `logData()`, use the `logger` parameter to access the needed methods. Make sure to specify the header you want the data to go under. Don't worry about converting the data to `string` type. The logger does that automatically.
+```java
+package frc.robot.logging
+
+public class LoggableTest implements Loggable {
+ @Override
+ public void logHeaders(Logger logger) {
+ logger.addHeader("first_name");
+ logger.addHeader("last_name");
+ }
+
+ @Override
+ public void logData(Logger logger) {
+ logger.addData("first_name", "Jeff")
+ logger.addData("last_name", "Bezos")
+ }
+}
+```
+
+
+6. There you go! Our *Loggable* object has been created. Don't think that you can't add other things as well. Constructors, other methods, those won't get in the way (except, of course, if you name other methods the same name). As long as your class has `logHeaders()` and `logData()`, you're good.
+
+### Registering the Loggable
+1. Go to the main *Robot.java* file in ***/src/main/java/frc/robot***. This is where all of the robot code is.
+
+2. Import *LoggableTest.java*.
+```java
+import frc.robot.logging.LoggableTest;
+```
+
+
+3. Go to the top of the `Robot` class and create a new *LoggableTest* object.
+```java
+LoggableTest loggableTest;
+```
+
+
+4. Now go into the `robotInit()` method and create the new instance. This is what the logger will register. If there's a constructor, make sure to give the necessary values.
+```java
+loggableTest = new LoggableTest();
+```
+
+
+5. Go to the bottom of the `robotInit()` method and use the `logger.addLoggable()` method to register `loggableTest` (This is assuming that the *Loggable* is a standalone system. If this is part of another system, then make sure to add it to whatever if-statements belong to that system, if any.) This will allow the logger to call `logHeaders()` and `logData()`.
+```java
+logger.addLoggable(loggableTest);
+```
+
+
+6. You are now all set! You've added the *LoggableTest* object to the logger, so now, when you start the robot, the log file should contain the info being logged by your *Loggable* object.
diff --git a/simgui.json b/simgui.json
index 486afab..65bbcba 100644
--- a/simgui.json
+++ b/simgui.json
@@ -31,6 +31,14 @@
"NTProvider": {
"types": {
"/FMSInfo": "FMSInfo",
+ "/LiveWindow/Ungrouped/DigitalInput[10]": "Digital Input",
+ "/LiveWindow/Ungrouped/DigitalInput[11]": "Digital Input",
+ "/LiveWindow/Ungrouped/DigitalInput[12]": "Digital Input",
+ "/LiveWindow/Ungrouped/DigitalInput[13]": "Digital Input",
+ "/LiveWindow/Ungrouped/DigitalInput[6]": "Digital Input",
+ "/LiveWindow/Ungrouped/DigitalInput[7]": "Digital Input",
+ "/LiveWindow/Ungrouped/DigitalInput[8]": "Digital Input",
+ "/LiveWindow/Ungrouped/DigitalInput[9]": "Digital Input",
"/LiveWindow/Ungrouped/navX-Sensor[4]": "Gyro"
},
"windows": {
diff --git a/src/main/java/frc/robot/Climber.java b/src/main/java/frc/robot/Climber.java
index a667f11..874f085 100644
--- a/src/main/java/frc/robot/Climber.java
+++ b/src/main/java/frc/robot/Climber.java
@@ -424,37 +424,37 @@ public void checkMotorState() {
}
@Override
- public void setupLogging(Logger logger) {
- this.timer.setupLogging(logger);
+ public void logHeaders(Logger logger) {
+ this.timer.logHeaders(logger);
// logger.addLoggable(this.leftFilter);
// logger.addLoggable(this.rightFilter);
// this.leftFilter.setupLogging(logger);
// this.rightFilter.setupLogging(logger);
- logger.addAttribute("Climber/Left/Current");
- logger.addAttribute("Climber/Right/Current");
+ logger.addHeader("Climber/Left/Current");
+ logger.addHeader("Climber/Right/Current");
- logger.addAttribute("Climber/Speed");
- logger.addAttribute("Climber/Position");
+ logger.addHeader("Climber/Speed");
+ logger.addHeader("Climber/Position");
- logger.addAttribute("Climber/State/Name");
- logger.addAttribute("Climber/State/Id");
- logger.addAttribute("Climber/State/Ordinal");
+ logger.addHeader("Climber/State/Name");
+ logger.addHeader("Climber/State/Id");
+ logger.addHeader("Climber/State/Ordinal");
}
@Override
- public void log(Logger logger) {
- this.timer.log(logger);
- logger.log("Climber/Left/Current", getLeftCurrent());
- logger.log("Climber/Right/Current", getRightCurrent());
+ public void logData(Logger logger) {
+ this.timer.logData(logger);
+ logger.addData("Climber/Left/Current", getLeftCurrent());
+ logger.addData("Climber/Right/Current", getRightCurrent());
- logger.log("Climber/Speed", getSpeed());
- logger.log("Climber/Position", climbingMotor.getSelectedSensorPosition());
+ logger.addData("Climber/Speed", getSpeed());
+ logger.addData("Climber/Position", climbingMotor.getSelectedSensorPosition());
- logger.log("Climber/State/Name", this.currentClimberState.name);
- logger.log("Climber/State/Id", this.currentClimberState.id);
- logger.log("Climber/State/Ordinal", this.currentClimberState.ordinal());
+ logger.addData("Climber/State/Name", this.currentClimberState.name);
+ logger.addData("Climber/State/Id", this.currentClimberState.id);
+ logger.addData("Climber/State/Ordinal", this.currentClimberState.ordinal());
}
public boolean getClimberSolenoidAState() {
diff --git a/src/main/java/frc/robot/ClimberGates.java b/src/main/java/frc/robot/ClimberGates.java
index ec244a8..41f75c3 100644
--- a/src/main/java/frc/robot/ClimberGates.java
+++ b/src/main/java/frc/robot/ClimberGates.java
@@ -35,16 +35,18 @@ public boolean getC() {
}
@Override
- public void setupLogging(Logger logger) {
- logger.log("GateA", this.getA());
- logger.log("GateB1", this.getB1());
- logger.log("GateB2", this.getB2());
- logger.log("GateC", this.getC());
+ public void logHeaders(Logger logger) {
+ logger.addHeader("GateA");
+ logger.addHeader("GateB1");
+ logger.addHeader("GateB2");
+ logger.addHeader("GateC");
}
@Override
- public void log(Logger logger) {
- // TODO Auto-generated method stub
-
+ public void logData(Logger logger) {
+ logger.addData("GateA", this.getA());
+ logger.addData("GateB1", this.getB1());
+ logger.addData("GateB2", this.getB2());
+ logger.addData("GateC", this.getC());
}
}
diff --git a/src/main/java/frc/robot/ClimberSensors.java b/src/main/java/frc/robot/ClimberSensors.java
index 00f085d..ec842ff 100644
--- a/src/main/java/frc/robot/ClimberSensors.java
+++ b/src/main/java/frc/robot/ClimberSensors.java
@@ -29,15 +29,16 @@ public boolean getC() {
}
@Override
- public void setupLogging(Logger logger) {
- logger.log("TouchA", this.getA());
- logger.log("TouchB", this.getB());
- logger.log("TouchC", this.getC());
+ public void logHeaders(Logger logger) {
+ logger.addHeader("TouchA");
+ logger.addHeader("TouchB");
+ logger.addHeader("TouchC");
}
@Override
- public void log(Logger logger) {
- // TODO Auto-generated method stub
-
+ public void logData(Logger logger) {
+ logger.addData("TouchA", this.getA());
+ logger.addData("TouchB", this.getB());
+ logger.addData("TouchC", this.getC());
}
}
diff --git a/src/main/java/frc/robot/DriveModule.java b/src/main/java/frc/robot/DriveModule.java
index a422020..b65f193 100644
--- a/src/main/java/frc/robot/DriveModule.java
+++ b/src/main/java/frc/robot/DriveModule.java
@@ -10,7 +10,7 @@
public class DriveModule implements Loggable {
- private final double VELOCITY_COEFFICIENT = 600 / 2048;
+ // private final double VELOCITY_COEFFICIENT = 600 / 2048;
private TalonFX main;
private TalonFX sub;
@@ -24,7 +24,7 @@ public class DriveModule implements Loggable {
/**
* Constructor.
*
- * @param moduleName Name of the attribute to log speed
+ * @param moduleName Name of the attribute to addData speed
* @param mainID CAN id of the main TalonFX
* @param subID CAN id of the sub TalonFX
*/
@@ -127,22 +127,22 @@ public double getAverageCurrent() {
}
@Override
- public void setupLogging(Logger logger) {
- logger.addAttribute(this.moduleName + "/MotorPower");
- logger.addAttribute(this.moduleName + "/Distance");
- logger.addAttribute(this.moduleName + "/EncoderRate");
- logger.addAttribute(this.moduleName + "/MotorVelocity");
- logger.addAttribute(this.moduleName + "/MotorCurrent");
- logger.addAttribute(this.moduleName + "/MotorAverageCurrent");
+ public void logHeaders(Logger logger) {
+ logger.addHeader(this.moduleName + "/MotorPower");
+ logger.addHeader(this.moduleName + "/Distance");
+ logger.addHeader(this.moduleName + "/EncoderRate");
+ logger.addHeader(this.moduleName + "/MotorVelocity");
+ logger.addHeader(this.moduleName + "/MotorCurrent");
+ logger.addHeader(this.moduleName + "/MotorAverageCurrent");
}
@Override
- public void log(Logger logger) {
- logger.log(this.moduleName + "/MotorPower", power);
- logger.log(this.moduleName + "/Distance", this.encoder.getDistance());
- logger.log(this.moduleName + "/EncoderRate", this.encoder.getRate());
- logger.log(this.moduleName + "/MotorVelocity", getSpeed());
- logger.log(this.moduleName + "/MotorCurrent", getCurrent());
- logger.log(this.moduleName + "/MotorAverageCurrent", getAverageCurrent());
+ public void logData(Logger logger) {
+ logger.addData(this.moduleName + "/MotorPower", power);
+ logger.addData(this.moduleName + "/Distance", this.encoder.getDistance());
+ logger.addData(this.moduleName + "/EncoderRate", this.encoder.getRate());
+ logger.addData(this.moduleName + "/MotorVelocity", getSpeed());
+ logger.addData(this.moduleName + "/MotorCurrent", getCurrent());
+ logger.addData(this.moduleName + "/MotorAverageCurrent", getAverageCurrent());
}
}
diff --git a/src/main/java/frc/robot/Drivetrain.java b/src/main/java/frc/robot/Drivetrain.java
index e284eb3..c1e2d3a 100644
--- a/src/main/java/frc/robot/Drivetrain.java
+++ b/src/main/java/frc/robot/Drivetrain.java
@@ -119,13 +119,11 @@ public void checkGears() {
}
@Override
- public void setupLogging(Logger logger) {
+ public void logHeaders(Logger logger) {
// logger.addLoggable(left);
// logger.addLoggable(right);
}
@Override
- public void log(Logger logger) {
- // TODO Auto-generated method stub
- }
+ public void logData(Logger logger) {}
}
diff --git a/src/main/java/frc/robot/Robot.java b/src/main/java/frc/robot/Robot.java
index 83ff985..6a74003 100644
--- a/src/main/java/frc/robot/Robot.java
+++ b/src/main/java/frc/robot/Robot.java
@@ -11,10 +11,12 @@
import frc.robot.Climber.MotorStates;
import frc.robot.logging.LoggableCompressor;
import frc.robot.logging.LoggableController;
-import frc.robot.logging.LoggableGyro;
import frc.robot.logging.LoggablePowerDistribution;
import frc.robot.logging.LoggableTimer;
import frc.robot.logging.Logger;
+import java.io.IOException;
+import java.util.Timer;
+import java.util.TimerTask;
/**
* The VM is configured to automatically run this class, and to call the functions corresponding to
@@ -23,8 +25,9 @@
* project.
*/
public class Robot extends TimedRobot {
-
Logger logger;
+ Timer runTimer;
+
LoggableTimer timer;
Drivetrain drive;
@@ -62,12 +65,17 @@ public double deadband(double in) {
@Override
public void robotInit() {
logger = new Logger();
- timer = new LoggableTimer();
- logger.addLoggable(timer);
- // gyro = new LoggableGyro();
+ runTimer = new Timer();
+ timer = new LoggableTimer("Timer");
pdp = new LoggablePowerDistribution(1, ModuleType.kRev);
+ try {
+ logger.createLog();
+ } catch (IOException io) {
+ io.printStackTrace();
+ }
+
driver = new LoggableController("Driver", 0);
operator = new LoggableController("Operator", 1);
@@ -79,13 +87,9 @@ public void robotInit() {
Solenoid climberSolenoidB2 = new Solenoid(PneumaticsModuleType.REVPH, 4);
Solenoid climberSolenoidC = new Solenoid(PneumaticsModuleType.REVPH, 5);
- // ClimberSensors climberSensors = new ClimberSensors(0, 1, 2, 3, 4, 5);
ClimberGates climberGates = new ClimberGates(6, 7, 8, 9, 10, 11, 12, 13);
climber = new Climber(9, 10, climberSolenoidA, climberSolenoidB1, climberSolenoidB2,
- climberSolenoidC, climberGates);// ,gyro, climberSensors);
-
- // logger.addLoggable(climberSensors);
- logger.addLoggable(climber);
+ climberSolenoidC, climberGates);
} else {
System.out.println("Climber initialization disabled.");
}
@@ -99,19 +103,40 @@ public void robotInit() {
rightModule.setEncoder(0, 1, true);
drive = new Drivetrain(leftModule, rightModule, 6);
-
- logger.addLoggable(drive);
} else {
System.out.println("Drivetrain initialization disabled.");
}
System.out.print("Initializing compressor...");
compressor = new LoggableCompressor(PneumaticsModuleType.REVPH);
- System.out.println("done");
+ logger.addLoggable(pdp);
+ logger.addLoggable(climber);
+ logger.addLoggable(drive);
+ logger.addLoggable(timer);
logger.addLoggable(driver);
logger.addLoggable(operator);
logger.addLoggable(compressor);
+
+ logger.collectHeaders();
+ try {
+ logger.writeData("Initiation");
+ } catch (IOException io) {
+ io.printStackTrace();
+ }
+
+ System.out.println("Starting logger...");
+ runTimer.schedule(new TimerTask() {
+ @Override
+ public void run() {
+ logger.collectData();
+ try {
+ logger.writeData(null);
+ } catch (IOException io) {
+ io.printStackTrace();
+ }
+ }
+ }, 0, 33);
}
@Override
@@ -123,19 +148,31 @@ public void robotPeriodic() {
@Override
public void autonomousInit() {
- resetLogging();
+ try {
+ logger.writeData("Autonomous");
+ logger.writeHeaders();
+ } catch (IOException io) {
+ io.printStackTrace();
+ }
+
+ resetTimer();
}
@Override
public void autonomousPeriodic() {
// Robot code goes here
- logger.log();
- logger.writeLine();
}
@Override
public void teleopInit() {
- resetLogging();
+ try {
+ logger.writeData("TeleOp");
+ logger.writeHeaders();
+ } catch (IOException io) {
+ io.printStackTrace();
+ }
+
+ resetTimer();
}
@Override
@@ -179,26 +216,36 @@ public void teleopPeriodic() {
}
// TODO: Enable this when we're ready to test the climber
}
-
- logger.log();
- logger.writeLine();
}
@Override
public void disabledInit() {
- logger.close();
+ try {
+ logger.writeData("Disabled");
+ logger.writeHeaders();
+ } catch (IOException io) {
+ io.printStackTrace();
+ }
+
timer.stop();
+ resetTimer();
}
@Override
public void disabledPeriodic() {
// Robot code goes here
- // logger.log();
}
@Override
public void testInit() {
- resetLogging();
+ try {
+ logger.writeData("Testmode");
+ logger.writeHeaders();
+ } catch (IOException io) {
+ io.printStackTrace();
+ }
+
+ resetTimer();
}
@Override
@@ -209,15 +256,9 @@ public void testPeriodic() {
// climber.setPower(operator.getRightY()); // Deadband
// climber.checkClimbingState();
// }
-
- logger.log();
- logger.writeLine();
}
- private void resetLogging() {
- logger.open();
- logger.setup();
-
+ private void resetTimer() {
timer.reset();
timer.start();
}
diff --git a/src/main/java/frc/robot/config/Config.java b/src/main/java/frc/robot/config/Config.java
index f824a67..c16c5a8 100644
--- a/src/main/java/frc/robot/config/Config.java
+++ b/src/main/java/frc/robot/config/Config.java
@@ -56,7 +56,7 @@ public static class DoubleItem implements ConfigItem {
public boolean testCorrectType(String input) {
try {
value = Double.parseDouble(input);
- } catch (NumberFormatException e) {
+ } catch (NumberFormatException numberformat) {
return false;
}
return true;
@@ -146,7 +146,7 @@ boolean parse(String filename) {
Scanner infile;
try {
infile = new Scanner(new File(filename));
- } catch (FileNotFoundException e) {
+ } catch (FileNotFoundException filenotfound) {
return false;
}
diff --git a/src/main/java/frc/robot/logging/Loggable.java b/src/main/java/frc/robot/logging/Loggable.java
index 6b92266..783a934 100644
--- a/src/main/java/frc/robot/logging/Loggable.java
+++ b/src/main/java/frc/robot/logging/Loggable.java
@@ -1,18 +1,13 @@
package frc.robot.logging;
-/** A class for a loggable subsystem. */
public interface Loggable {
- /**
- * Sets up all the keys in the given Logger object.
- *
- * @param logger Logger class to setup keys in
- */
- public abstract void setupLogging(Logger logger);
+ /**
+ * Logs all the headers provided by the Loggable object.
+ */
+ public abstract void logHeaders(Logger logger);
- /**
- * Logs data in the given Logger object.
- *
- * @param logger Logger class to log data to
- */
- public abstract void log(Logger logger);
-}
+ /**
+ * Logs all the data provided by the Loggable object.
+ */
+ public abstract void logData(Logger logger);
+}
\ No newline at end of file
diff --git a/src/main/java/frc/robot/logging/LoggableCompressor.java b/src/main/java/frc/robot/logging/LoggableCompressor.java
index e60328b..f02b4d1 100644
--- a/src/main/java/frc/robot/logging/LoggableCompressor.java
+++ b/src/main/java/frc/robot/logging/LoggableCompressor.java
@@ -13,12 +13,12 @@ public LoggableCompressor(PneumaticsModuleType moduleType) {
}
@Override
- public void setupLogging(Logger logger) {
- logger.addAttribute("PH/pressure");
+ public void logHeaders(Logger logger) {
+ logger.addHeader("PH/pressure");
}
@Override
- public void log(Logger logger) {
- logger.log("PH/pressure", this.getPressure());
+ public void logData(Logger logger) {
+ logger.addData("PH/pressure", this.getPressure());
}
}
diff --git a/src/main/java/frc/robot/logging/LoggableController.java b/src/main/java/frc/robot/logging/LoggableController.java
index b877bab..16f5a08 100644
--- a/src/main/java/frc/robot/logging/LoggableController.java
+++ b/src/main/java/frc/robot/logging/LoggableController.java
@@ -14,22 +14,22 @@ public LoggableController(String name, int port) {
/**
* Sets up logging for the controller.
*/
- public void setupLogging(Logger logger) {
- logger.addAttribute(name + "/LeftX");
- logger.addAttribute(name + "/LeftY");
- logger.addAttribute(name + "/RightX");
- logger.addAttribute(name + "/RightY");
+ public void logHeaders(Logger logger) {
+ logger.addHeader(name + "/LeftX");
+ logger.addHeader(name + "/LeftY");
+ logger.addHeader(name + "/RightX");
+ logger.addHeader(name + "/RightY");
}
@Override
/**
* Logs the controller's values.
*/
- public void log(Logger logger) {
- logger.log(name + "/LeftX", this.getLeftX());
- logger.log(name + "/LeftY", this.getLeftY());
- logger.log(name + "/RightX", this.getRightX());
- logger.log(name + "/RightY", this.getRightY());
+ public void logData(Logger logger) {
+ logger.addData(name + "/LeftX", this.getLeftX());
+ logger.addData(name + "/LeftY", this.getLeftY());
+ logger.addData(name + "/RightX", this.getRightX());
+ logger.addData(name + "/RightY", this.getRightY());
}
}
diff --git a/src/main/java/frc/robot/logging/LoggableFirstOrderFilter.java b/src/main/java/frc/robot/logging/LoggableFirstOrderFilter.java
index 6a05119..4d2ce90 100644
--- a/src/main/java/frc/robot/logging/LoggableFirstOrderFilter.java
+++ b/src/main/java/frc/robot/logging/LoggableFirstOrderFilter.java
@@ -28,12 +28,12 @@ public double get() {
}
@Override
- public void setupLogging(Logger logger) {
- logger.addAttribute(this.name + "/Average");
+ public void logHeaders(Logger logger) {
+ logger.addHeader(this.name + "/Average");
}
@Override
- public void log(Logger logger) {
- logger.log(this.name + "/Average", get());
+ public void logData(Logger logger) {
+ logger.addData(this.name + "/Average", get());
}
}
diff --git a/src/main/java/frc/robot/logging/LoggableGyro.java b/src/main/java/frc/robot/logging/LoggableGyro.java
index bb7083d..5eec2dc 100644
--- a/src/main/java/frc/robot/logging/LoggableGyro.java
+++ b/src/main/java/frc/robot/logging/LoggableGyro.java
@@ -8,28 +8,28 @@ public LoggableGyro() {
}
@Override
- public void setupLogging(Logger logger) {
- logger.addAttribute("AHRS/velocityX");
- logger.addAttribute("AHRS/yaw");
- logger.addAttribute("AHRS/accelerationX");
- logger.addAttribute("AHRS/velocityY");
- logger.addAttribute("AHRS/pitch");
- logger.addAttribute("AHRS/accelerationY");
- logger.addAttribute("AHRS/velocityZ");
- logger.addAttribute("AHRS/roll");
- logger.addAttribute("AHRS/accelerationZ");
+ public void logHeaders(Logger logger) {
+ logger.addHeader("AHRS/velocityX");
+ logger.addHeader("AHRS/yaw");
+ logger.addHeader("AHRS/accelerationX");
+ logger.addHeader("AHRS/velocityY");
+ logger.addHeader("AHRS/pitch");
+ logger.addHeader("AHRS/accelerationY");
+ logger.addHeader("AHRS/velocityZ");
+ logger.addHeader("AHRS/roll");
+ logger.addHeader("AHRS/accelerationZ");
}
@Override
- public void log(Logger logger) {
- logger.log("AHRS/velocityX", this.getVelocityX());
- logger.log("AHRS/yaw", this.getYaw());
- logger.log("AHRS/accelerationX", this.getWorldLinearAccelX());
- logger.log("AHRS/velocityY", this.getVelocityY());
- logger.log("AHRS/pitch", this.getPitch());
- logger.log("AHRS/accelerationY", this.getWorldLinearAccelY());
- logger.log("AHRS/velocityZ", this.getVelocityZ());
- logger.log("AHRS/roll", this.getRoll());
- logger.log("AHRS/accelerationZ", this.getWorldLinearAccelZ());
+ public void logData(Logger logger) {
+ logger.addData("AHRS/velocityX", this.getVelocityX());
+ logger.addData("AHRS/yaw", this.getYaw());
+ logger.addData("AHRS/accelerationX", this.getWorldLinearAccelX());
+ logger.addData("AHRS/velocityY", this.getVelocityY());
+ logger.addData("AHRS/pitch", this.getPitch());
+ logger.addData("AHRS/accelerationY", this.getWorldLinearAccelY());
+ logger.addData("AHRS/velocityZ", this.getVelocityZ());
+ logger.addData("AHRS/roll", this.getRoll());
+ logger.addData("AHRS/accelerationZ", this.getWorldLinearAccelZ());
}
}
diff --git a/src/main/java/frc/robot/logging/LoggablePowerDistribution.java b/src/main/java/frc/robot/logging/LoggablePowerDistribution.java
index cde1a5f..cf93c02 100644
--- a/src/main/java/frc/robot/logging/LoggablePowerDistribution.java
+++ b/src/main/java/frc/robot/logging/LoggablePowerDistribution.java
@@ -12,13 +12,13 @@ public LoggablePowerDistribution(int module, ModuleType moduleType) {
}
@Override
- public void setupLogging(Logger logger) {
- logger.addAttribute("PDH/voltage");
+ public void logHeaders(Logger logger) {
+ logger.addHeader("PDH/voltage");
}
@Override
- public void log(Logger logger) {
- logger.log("PDH/voltage", this.getVoltage());
+ public void logData(Logger logger) {
+ logger.addData("PDH/voltage", this.getVoltage());
}
}
diff --git a/src/main/java/frc/robot/logging/LoggableTimer.java b/src/main/java/frc/robot/logging/LoggableTimer.java
index 3e6c128..b5e8004 100644
--- a/src/main/java/frc/robot/logging/LoggableTimer.java
+++ b/src/main/java/frc/robot/logging/LoggableTimer.java
@@ -5,22 +5,17 @@
public class LoggableTimer extends Timer implements Loggable {
String name;
- public LoggableTimer() {
- this("Time");
- }
-
public LoggableTimer(String name) {
this.name = name;
}
@Override
- public void setupLogging(Logger logger) {
- logger.addAttribute(this.name);
+ public void logHeaders(Logger logger) {
+ logger.addHeader(this.name);
}
@Override
- public void log(Logger logger) {
- logger.log(this.name, this.get());
+ public void logData(Logger logger) {
+ logger.addData(this.name, this.get());
}
-
}
diff --git a/src/main/java/frc/robot/logging/Logger.java b/src/main/java/frc/robot/logging/Logger.java
index 8df492b..e3f359a 100644
--- a/src/main/java/frc/robot/logging/Logger.java
+++ b/src/main/java/frc/robot/logging/Logger.java
@@ -1,275 +1,147 @@
package frc.robot.logging;
-import edu.wpi.first.networktables.NetworkTable;
-import edu.wpi.first.networktables.NetworkTableInstance;
-
-import java.io.BufferedWriter;
-import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.Files;
import java.io.FileWriter;
+import java.io.BufferedWriter;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.Calendar;
-import java.util.LinkedHashMap;
-import java.util.List;
+import java.util.HashMap;
+import java.util.ArrayList;
import java.util.Map;
-/** Manages NetworkTable and file logging. */
public class Logger {
- private String filename;
- private BufferedWriter log = null;
- private Map fields;
- private List loggables;
- private NetworkTable table;
-
- public Logger() {
- fields = new LinkedHashMap();
- loggables = new ArrayList<>();
- table = NetworkTableInstance.getDefault().getTable("logging");
- for (String s : table.getKeys()) {
- table.delete(s);
- }
- }
-
- /**
- * Opens a file with the name being the current date and time to log to.
- *
- * @return Whether opening the file succeeded
- */
- public boolean open() {
+ private BufferedWriter logger;
+ public Map logData;
+ private ArrayList loggables;
+ private String logName;
+
+ public Logger() {
+ logData = new HashMap();
+ loggables = new ArrayList();
+ }
+
+ /**
+ * Creates a new log file.
+ *
+ * @throws IOException
+ */
+ public void createLog() throws IOException {
Calendar calendar = Calendar.getInstance();
- String dir = "/home/lvuser/logs";
- new File(dir).mkdirs();
- if (new File("/media/sda").exists()) {
- dir = "/media/sda";
- }
- String name = dir + "/log-" + calendar.get(Calendar.YEAR) + "-"
- + calendar.get(Calendar.MONTH) + "-" + calendar.get(Calendar.DAY_OF_MONTH) + "_"
- + calendar.get(Calendar.HOUR_OF_DAY) + "-" + calendar.get(Calendar.MINUTE) + "-"
- + calendar.get(Calendar.SECOND) + ".csv";
-
- System.out.printf("Logging to file: '%s'%n", new File(name).getAbsolutePath());
- return this.open(name);
- }
-
- /**
- * Opens a file to log to.
- *
- * @param filepath Path of the file to open
- * @return Whether opening the file succeeded
- */
- public boolean open(String filepath) {
- this.filename = filepath;
- try {
- log = new BufferedWriter(new FileWriter(filepath));
- } catch (IOException e) {
- return false;
- }
- return true;
- }
-
- /**
- * Closes the current log file.
- *
- * @return Whether closing the file succeeded
- */
- public boolean close() {
- if (log != null) {
- try {
- log.close();
- } catch (IOException e) {
- e.printStackTrace();
- return false;
- }
- return true;
- }
- return false;
- }
-
- /**
- * Resets the current log file.
- *
- * @return true
- */
- public boolean reset() {
- close();
- open(this.filename);
- writeAttributes();
- return true;
- }
-
- /**
- * Checks to see if the logger already has a specific key.
- *
- * @param name Key to check
- * @return Whether the key already exists
- */
- public boolean hasAttribute(String name) {
- return fields.containsKey(name);
- }
-
- /**
- * Adds an attribute to the logger.
- *
- * @param field
- * @return
- */
- public boolean addAttribute(String field) {
- if (hasAttribute(field)) {
- // TODO: Output warning
- return false; // We already have this attribute
- }
-
- fields.put(field, "");
-
- return true;
- }
-
- /**
- * Sets up all currently registered Loggables, along with writing the header to the file.
- */
- public void setup() {
- this.setupLoggables();
- this.writeAttributes();
- }
-
- /**
- * Logs data to the Logger.
- *
- * @param field Key being logged
- * @param data Number data to log
- * @return Whether the operation succeeded
- */
- public boolean log(String field, double data) {
- if (!hasAttribute(field)) {
- return false;
- }
- table.getEntry(field).setDouble(data);
- fields.put(field, Double.toString(data));
- return true;
- }
-
- /**
- * Logs data to the Logger
- *
- * @param field key being logged
- * @param data String data to log
- * @return whether the operation succeeded
- */
- public boolean log(String field, String data) {
- if (!hasAttribute(field)) {
- return false;
- }
-
- table.getEntry(field).setString(data);
- fields.put(field, data);
- return true;
- }
-
- /**
- * Logs data to the Logger
- *
- * @param field key being logged
- * @param data to log
- * @return whether the operation succeeded
- */
- public boolean log(String field, Object data) {
- if (!hasAttribute(field)) {
- return false;
- }
-
- table.getEntry(field).setValue(data);
- fields.put(field, data.toString());
- return true;
- }
-
- /**
- * Writes the headers to the file.
- *
- * @return Whether the operation succeeded
- */
- public boolean writeAttributes() {
- try {
- for (Map.Entry e : fields.entrySet()) {
- log.write(e.getKey() + ',');
+ String dir = (System.getProperty("os.name").equals("Linux")) ? "./src/main/java/frc/robot/logging/logs/" : "\\home\\lvuser\\logs\\";
+ Path path = Paths.get(
+ dir + calendar.get(Calendar.YEAR) + "-" +
+ (calendar.get(Calendar.MONTH) + 1) + "-" +
+ calendar.get(Calendar.DAY_OF_MONTH) + "-" +
+ calendar.get(Calendar.HOUR_OF_DAY) + "-" +
+ calendar.get(Calendar.MINUTE) + "-" +
+ calendar.get(Calendar.SECOND) + ".csv"
+ );
+
+ logName = Files.createFile(path).toString();
+ logger = new BufferedWriter(new FileWriter(logName, true));
+ }
+
+ /**
+ * Creates a header that data can be attributed to.
+ *
+ * @param header The name of the header being created.
+ */
+ public void addHeader(String header) {
+ if (logData.containsKey(header)) {
+ System.err.println("The header \"" + header + "\" already exists.");
+ }
+ else {
+ logData.put(header, null);
+ }
+ }
+
+ /**
+ * Adds data under the specified header.
+ *
+ * @param header The header that the data will be attributed to.
+ * @param data The data being logged.
+ */
+ public void addData(String header, Object data) {
+ if (!logData.containsKey(header)) {
+ System.err.println("The header \"" + header + "\" does not exist.");
+ }
+ else {
+ logData.put(header, data.toString());
+ }
+ }
+
+ /**
+ * Writes the created headers to the log file.
+ *
+ * @throws IOException
+ */
+ public void writeHeaders() throws IOException {
+ for (String header: logData.keySet()) {
+ logger.write(header + ",");
+ }
+
+ logger.newLine();
+ logger.close();
+ logger = new BufferedWriter(new FileWriter(logName, true));
+ }
+
+ /**
+ * Writes the accumulated data to the log file.
+ *
+ * @throws IOException
+ */
+ public void writeData(String stage) throws IOException {
+ if (stage == null) {
+ for (Map.Entry data: logData.entrySet()) {
+ logger.write(data.getValue() + ",");
+ logData.put(data.getKey(), null);
}
- log.write("\n");
- log.flush();
- } catch (IOException e1) {
- e1.printStackTrace();
- return false;
}
- return true;
- }
-
- /**
- * Writes the current values to the file.
- *
- * @return Whether the operation succeeded
- */
- public boolean writeLine() {
- try {
- for (Map.Entry e : fields.entrySet()) {
- log.write(e.getValue() + ',');
- }
- log.write("\n");
- } catch (IOException e) {
- return false;
- }
- return true;
- }
-
- /**
- * Normalizes the name of a key.
- *
- * @param str key name to normalize
- * @return normalized key name
- */
- String normalize(String str) {
- return str.toLowerCase();
- }
-
- /**
- * Registers a Loggable with the Logger.
- *
- * @param log loggable to register
- */
- public void addLoggable(Loggable log) {
- if (log != null) {
- loggables.add(log);
- } else {
- System.err.println("A null loggable was passed to the logger!");
- System.err.println(
- "Make sure you are declaring your loggables before you run 'setupLoggables()!");
- var stackTrace = Thread.currentThread().getStackTrace();
- for (StackTraceElement stackTraceLine : stackTrace) {
- System.err.println(stackTraceLine);
+ else {
+ String output = "========================================= Current Stage: " + stage + " =========================================";
+
+ logger.newLine();
+ for (int i = 0; i < output.length(); i++) {
+ logger.write("=");
}
- }
- }
-
- /**
- * Calls the setupLogging method of all currently registered Loggables.
- */
- public void setupLoggables() {
- for (Loggable l : loggables) {
- if (l != null) {
- l.setupLogging(this);
- } else {
- // Silently ignore null loggables
+ logger.newLine(); logger.write(output); logger.newLine();
+ for (int i = 0; i < output.length(); i++) {
+ logger.write("=");
}
+ logger.newLine();
}
- }
- /**
- * Calls the log method of all currently registered Loggables.
- */
- public void log() {
- for (Loggable l : loggables) {
- if (l != null) {
- l.log(this);
- } else {
- // Silently ignore null loggables
- }
- }
- }
-}
+ logger.newLine();
+ logger.close();
+ logger = new BufferedWriter(new FileWriter(logName, true));
+ }
+
+ /**
+ * Creates a new Loggable object.
+ *
+ * @param loggable The Loggable object to be registered.
+ */
+ public void addLoggable(Loggable loggable) {
+ loggables.add(loggable);
+ }
+
+ /**
+ * Goes through every registered Loggable and calls the "logHeaders()" method.
+ */
+ public void collectHeaders() {
+ for (Loggable loggable: loggables) {
+ loggable.logHeaders(this);
+ }
+ }
+
+ /**
+ * Goes through every registered Loggable and calls the "logData()" method.
+ */
+ public void collectData() {
+ for (Loggable loggable: loggables) {
+ loggable.logData(this);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/config/ConfigTest.java b/src/test/java/config/ConfigTest.java
index 1c79ed4..f3e97fd 100644
--- a/src/test/java/config/ConfigTest.java
+++ b/src/test/java/config/ConfigTest.java
@@ -97,7 +97,7 @@ public void noConfigTest() {
public String getTestFileUrl() {
try {
return getClass().getResource("test_config.txt").toURI().getPath();
- } catch (Exception e) {
+ } catch (Exception exception) {
return "";
}
}
diff --git a/vendordeps/photonlib.json b/vendordeps/photonlib.json
new file mode 100644
index 0000000..8fdf301
--- /dev/null
+++ b/vendordeps/photonlib.json
@@ -0,0 +1,41 @@
+{
+ "fileName": "photonlib.json",
+ "name": "photonlib",
+ "version": "v2023.1.2",
+ "uuid": "515fe07e-bfc6-11fa-b3de-0242ac130004 ",
+ "mavenUrls": [
+ "https://maven.photonvision.org/repository/internal",
+ "https://maven.photonvision.org/repository/snapshots"
+ ],
+ "jsonUrl": "https://maven.photonvision.org/repository/internal/org/photonvision/PhotonLib-json/1.0/PhotonLib-json-1.0.json",
+ "jniDependencies": [],
+ "cppDependencies": [
+ {
+ "groupId": "org.photonvision",
+ "artifactId": "PhotonLib-cpp",
+ "version": "v2023.1.2",
+ "libName": "Photon",
+ "headerClassifier": "headers",
+ "sharedLibrary": true,
+ "skipInvalidPlatforms": true,
+ "binaryPlatforms": [
+ "windowsx86-64",
+ "linuxathena",
+ "linuxx86-64",
+ "osxuniversal"
+ ]
+ }
+ ],
+ "javaDependencies": [
+ {
+ "groupId": "org.photonvision",
+ "artifactId": "PhotonLib-java",
+ "version": "v2023.1.2"
+ },
+ {
+ "groupId": "org.photonvision",
+ "artifactId": "PhotonTargeting-java",
+ "version": "v2023.1.2"
+ }
+ ]
+}
\ No newline at end of file