Skip to content
This repository has been archived by the owner on Feb 1, 2025. It is now read-only.

Commit

Permalink
Add CTRE logging, log writer
Browse files Browse the repository at this point in the history
Added logging for CTRE devices such as CANcoders.

Added a log writer that will log to a USB drive plugged into the RIO.
  • Loading branch information
garrettsummerfi3ld committed Mar 9, 2024
1 parent 274b668 commit e66e694
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
24 changes: 14 additions & 10 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package frc.robot;

import com.ctre.phoenix6.SignalLogger;
import edu.wpi.first.wpilibj.Filesystem;
import edu.wpi.first.wpilibj.PowerDistribution.ModuleType;
import edu.wpi.first.wpilibj.Timer;
Expand All @@ -12,6 +13,7 @@
import frc.robot.Constants.HardwareConstants;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import org.littletonrobotics.junction.LogFileUtil;
import org.littletonrobotics.junction.LoggedRobot;
import org.littletonrobotics.junction.Logger;
Expand Down Expand Up @@ -71,19 +73,21 @@ public void robotInit() {
break;
}

Logger.addDataReceiver(new NT4Publisher());
if (isReal()) {
Logger.addDataReceiver(new NT4Publisher());
LoggedPowerDistribution.getInstance(HardwareConstants.REV_PDH_ID, ModuleType.kRev);
Logger.registerURCL(URCL.startExternal());
} else {
setUseTiming(false);
try {
String logPath = LogFileUtil.findReplayLog();
Logger.setReplaySource(new WPILOGReader(logPath));
Logger.addDataReceiver(new WPILOGWriter(LogFileUtil.addPathSuffix(logPath, "_sim")));
} catch (Exception e) {
e.printStackTrace();
Logger.addDataReceiver(new NT4Publisher());
if (Paths.get("/U").getParent() != null) {
Logger.addDataReceiver(new WPILOGWriter());
SignalLogger.start();
} else {
setUseTiming(false);
try {
String logPath = LogFileUtil.findReplayLog();
Logger.setReplaySource(new WPILOGReader(logPath));
} catch (Exception e) {
e.printStackTrace();
}
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,27 +110,27 @@ public RobotContainer() {
DriverStation.reportError(
"WARNING! THERE ARE CHANGES THAT CURRENTLY IS NOT COMMITTED! PLEASE COMMIT THOSE CHANGES TO GIT/GITHUB OR REVERT THOSE CHANGES!",
false);
DriverStation.reportError("To see the changes, run `git status` in the terminal.", false);
DriverStation.reportError("To see the changes, run `git status` in the terminal", false);
DriverStation.reportError(
"To commit the changes, run `git add .` to stage the changes, then run `git commit -m \"<commit message>\"` to commit the changes.",
"To commit the changes, run `git add .` to stage the changes, then run `git commit -m \"<commit message>\"` to commit the changes",
false);
DriverStation.reportError(
"To revert the changes, run `git reset --hard` to revert the changes. This will permanently delete those changes.",
"To revert the changes, run `git reset --hard` to revert the changes. This will permanently delete those changes",
false);
DriverStation.reportError(
"You can also open the GitHub Desktop application to perform these actions.", false);
DriverStation.reportError("Remember to push your changes after committing.", false);
"You can also open the GitHub Desktop application to perform these actions", false);
DriverStation.reportError("Remember to push your changes after committing", false);
}
if (!BuildConstants.GIT_BRANCH.equals("main")) {
DriverStation.reportError(
"WARNING! YOU ARE NOT ON THE MAIN BRANCH! PLEASE MERGE YOUR CHANGES TO MAIN OR REVERT THOSE CHANGES!",
false);
DriverStation.reportError(
"To see the current branch, run `git branch` in the terminal.", false);
"To see the current branch, run `git branch` in the terminal", false);
DriverStation.reportError(
"To merge your changes to main, push your changes to GitHub and go to the GitHub repository and create a pull request.",
"To merge your changes to main, push your changes to GitHub and go to the GitHub repository and create a pull request",
false);
DriverStation.reportError("Wait for the pull request to be reviewed and merged.", false);
DriverStation.reportError("Wait for the pull request to be reviewed and merged", false);
}
}

Expand Down

0 comments on commit e66e694

Please sign in to comment.