Skip to content

Commit

Permalink
changed the way faults are logged by doglog and added doglog fault lo…
Browse files Browse the repository at this point in the history
…gging in self check faults
  • Loading branch information
PGgit08 committed Nov 24, 2024
1 parent e233a86 commit 8df60be
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/main/java/frc/lib/AdvancedSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ protected final void addFault(String description, FaultType faultType) {

Fault fault = new Fault(description, faultType);

DogLog.logFault(fault.toString());

_faults.add(fault);
_faultsTable.set(_faults);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/frc/lib/CTREUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public static boolean attempt(Supplier<StatusCode> action, String deviceName) {

// successful attempt
if (statusCode.isOK()) {
FaultLogger.report(deviceName + ": Config Apply Successful.", FaultType.INFO);
FaultLogger.report(deviceName + " - Config Apply Successful.", FaultType.INFO);
return false;
}

// failed attempt
else {
FaultLogger.report(
deviceName + ": Config Apply Failed - " + statusCode.getDescription(), FaultType.ERROR);
deviceName + " - Config Apply Failed - " + statusCode.getDescription(), FaultType.ERROR);
return true;
}
}
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/frc/lib/FaultLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static void update() {
newFaults.clear();

// log to doglog as well
activeFaults.forEach(f -> DogLog.logFault(f.description()));
activeFaults.forEach(f -> DogLog.logFault(f.toString()));

totalFaults.addAll(activeFaults);

Expand Down Expand Up @@ -164,22 +164,22 @@ public static void register(TalonFX talonFX) {
String name = CTREUtil.getName(talonFX);

register(
() -> talonFX.getFault_Hardware().getValue(), name + ": Hardware Fault.", FaultType.ERROR);
() -> talonFX.getFault_Hardware().getValue(), name + "- Hardware Fault.", FaultType.ERROR);
register(
() -> talonFX.getFault_BootDuringEnable().getValue(),
name + ": Boot While Enabling.",
name + "- Boot While Enabling.",
FaultType.WARNING);
register(
() -> talonFX.getFault_DeviceTemp().getValue(),
name + ": Device Temperature Too High.",
name + "- Device Temperature Too High.",
FaultType.WARNING);
register(
() -> talonFX.getFault_ProcTemp().getValue(),
name + ": Processor Temp Too High.",
name + "- Processor Temp Too High.",
FaultType.WARNING);
register(
() -> talonFX.getFault_Undervoltage().getValue(),
name + ": Voltage Too Low, Check For Brownouts.",
name + "- Voltage Too Low, Check For Brownouts.",
FaultType.WARNING);
}

Expand All @@ -192,18 +192,18 @@ public static void register(CANcoder cancoder) {
String name = CTREUtil.getName(cancoder);

register(
() -> cancoder.getFault_Hardware().getValue(), name + ": Hardware Fault.", FaultType.ERROR);
() -> cancoder.getFault_Hardware().getValue(), name + "- Hardware Fault.", FaultType.ERROR);
register(
() -> cancoder.getFault_BadMagnet().getValue(),
name + ": Bad Magnet Signal.",
name + "- Bad Magnet Signal.",
FaultType.ERROR);
register(
() -> cancoder.getFault_BootDuringEnable().getValue(),
name + ": Boot While Enabling.",
name + "- Boot While Enabling.",
FaultType.WARNING);
register(
() -> cancoder.getFault_Undervoltage().getValue(),
name + ": Voltage Too Low, Check For Brownouts.",
name + "- Voltage Too Low, Check For Brownouts.",
FaultType.WARNING);
}

Expand All @@ -216,14 +216,14 @@ public static void register(Pigeon2 pigeon) {
String name = CTREUtil.getName(pigeon);

register(
() -> pigeon.getFault_Hardware().getValue(), name + ": Hardware Fault.", FaultType.ERROR);
() -> pigeon.getFault_Hardware().getValue(), name + "- Hardware Fault.", FaultType.ERROR);
register(
() -> pigeon.getFault_BootDuringEnable().getValue(),
name + ": Boot While Enabling.",
name + "- Boot While Enabling.",
FaultType.WARNING);
register(
() -> pigeon.getFault_Undervoltage().getValue(),
name + ": Voltage Too Low, Check For Brownouts.",
name + "- Voltage Too Low, Check For Brownouts.",
FaultType.WARNING);
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/frc/lib/FaultsTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public final boolean equals(Object other) {

return false;
}

@Override
public final String toString() {
return "Fault - " + description + ", Type - " + type.toString();
}
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/frc/robot/subsystems/Swerve.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ private final void addFault(String description, FaultType faultType) {

Fault fault = new Fault(description, faultType);

DogLog.logFault(fault.toString());

_faults.add(fault);
_faultsTable.set(_faults);
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/frc/lib/CTREUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ public void attempt() {
assert FaultLogger.totalFaults()
.contains(
new Fault(
name + ": Config Apply Failed - " + StatusCode.ConfigFailed.getDescription(),
name + " - Config Apply Failed - " + StatusCode.ConfigFailed.getDescription(),
FaultType.ERROR));

assert FaultLogger.totalFaults()
.contains(new Fault(name + ": Config Apply Successful.", FaultType.INFO));
.contains(new Fault(name + " - Config Apply Successful.", FaultType.INFO));
}
}

0 comments on commit 8df60be

Please sign in to comment.