Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new logger system #27

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
*.class

# Log file
logs/
*.log

# BlueJ files
Expand Down
15 changes: 0 additions & 15 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
110 changes: 108 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,109 @@
# RA22_RobotCode
# RA22_RobotCode Logger Documentation

Red Alert's 2022 Robot Code
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

Welcome to the docs for the Red Alert Robotics 2022 Robot Code Logger System.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length


## Usage
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length


### Create the Loggable
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

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*.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lists should be surrounded by blank lines


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered list item prefix

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered list item prefix

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lists should be surrounded by blank lines

```java
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

package frc.robot.logging

public class LoggableTest implements Loggable {

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing spaces

}
```
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

<br>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline HTML


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered list item prefix

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.**
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered list item prefix

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lists should be surrounded by blank lines

```java
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

package frc.robot.logging

public class LoggableTest implements Loggable {
@Override
public void logHeaders(Logger logger) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing spaces


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing spaces

}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing spaces


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing spaces

@Override
public void logData(Logger logger) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing spaces


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing spaces

}
}
```
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

<br>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline HTML


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered list item prefix

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered list item prefix

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lists should be surrounded by blank lines

```java
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

package frc.robot.logging

public class LoggableTest implements Loggable {
@Override
public void logHeaders(Logger logger) {
logger.addHeader("first_name");
logger.addHeader("last_name");
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing spaces


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing spaces

@Override
public void logData(Logger logger) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing spaces


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing spaces

}
}
```
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

<br>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline HTML


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered list item prefix

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered list item prefix

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lists should be surrounded by blank lines

```java
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

package frc.robot.logging

public class LoggableTest implements Loggable {
@Override
public void logHeaders(Logger logger) {
logger.addHeader("first_name");
logger.addHeader("last_name");
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing spaces


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing spaces

@Override
public void logData(Logger logger) {
logger.addData("first_name", "Jeff")
logger.addData("last_name", "Bezos")
}
}
```
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

<br>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline HTML


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered list item prefix


### 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.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lists should be surrounded by blank lines


2. Import *LoggableTest.java*.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered list item prefix

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lists should be surrounded by blank lines

```java
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

import frc.robot.logging.LoggableTest;
```
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

<br>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline HTML


3. Go to the top of the `Robot` class and create a new *LoggableTest* object.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered list item prefix

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lists should be surrounded by blank lines

```java
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

LoggableTest loggableTest;
```
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

<br>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline HTML


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered list item prefix

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lists should be surrounded by blank lines

```java
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

loggableTest = new LoggableTest();
```
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

<br>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline HTML


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()`.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered list item prefix

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lists should be surrounded by blank lines

```java
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

logger.addLoggable(loggableTest);
```
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

<br>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline HTML


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered list item prefix

8 changes: 8 additions & 0 deletions simgui.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
36 changes: 18 additions & 18 deletions src/main/java/frc/robot/Climber.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/frc/robot/ClimberGates.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
15 changes: 8 additions & 7 deletions src/main/java/frc/robot/ClimberSensors.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
32 changes: 16 additions & 16 deletions src/main/java/frc/robot/DriveModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class DriveModule implements Loggable {

private final double VELOCITY_COEFFICIENT = 600 / 2048;
// private final double VELOCITY_COEFFICIENT = 600 / 2048;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block of commented-out lines of code should be removed.


private TalonFX main;
private TalonFX sub;
Expand All @@ -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
*/
Expand Down Expand Up @@ -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());
}
}
6 changes: 2 additions & 4 deletions src/main/java/frc/robot/Drivetrain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'}' at column 41 should be alone on a line.

}
Loading