From 274b66817fdbb8e14efd063203ec4e91c08d09f2 Mon Sep 17 00:00:00 2001 From: Garrett Summerfield Date: Mon, 26 Feb 2024 14:36:56 -0600 Subject: [PATCH 1/4] Fix logfile null crash, add Git warning to driver station Fixed an issue that where if an AdvantageKit logfile was not provided or was null during the robot simulation startup there would be a simulator crash. This is now fixed. Added Git warnings to the driver station. This will notify the driver if there are currently uncommitted changes on the robot as well as if the robot is currently not on the "main" branch. This will show up as errors as we are treating these warnings as errors. --- src/main/java/frc/robot/Robot.java | 11 ++++---- src/main/java/frc/robot/RobotContainer.java | 29 +++++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/main/java/frc/robot/Robot.java b/src/main/java/frc/robot/Robot.java index 7475f9f..1fc3f6d 100644 --- a/src/main/java/frc/robot/Robot.java +++ b/src/main/java/frc/robot/Robot.java @@ -76,14 +76,15 @@ public void robotInit() { LoggedPowerDistribution.getInstance(HardwareConstants.REV_PDH_ID, ModuleType.kRev); Logger.registerURCL(URCL.startExternal()); } else { - setUseTiming(false); // Run as fast as possible - String logPath = LogFileUtil.findReplayLog(); - if (logPath != null) { + setUseTiming(false); + try { + String logPath = LogFileUtil.findReplayLog(); Logger.setReplaySource(new WPILOGReader(logPath)); - } else { + Logger.addDataReceiver(new WPILOGWriter(LogFileUtil.addPathSuffix(logPath, "_sim"))); + } catch (Exception e) { + e.printStackTrace(); Logger.addDataReceiver(new NT4Publisher()); } - Logger.addDataReceiver(new WPILOGWriter(LogFileUtil.addPathSuffix(logPath, "_sim"))); } // Start logging diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index efc0c2b..6ff26c0 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -8,6 +8,7 @@ import edu.wpi.first.math.geometry.Pose2d; import edu.wpi.first.math.geometry.Rotation2d; import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.wpilibj.DriverStation; import edu.wpi.first.wpilibj.Filesystem; import edu.wpi.first.wpilibj.XboxController; import edu.wpi.first.wpilibj2.command.Command; @@ -103,6 +104,34 @@ public RobotContainer() { () -> driverXbox.getRawAxis(2)); drivebase.setDefaultCommand(closedAbsoluteDriveAdv); + + // Checks if the git repo is dirty or if the branch is not main and output warnings as errors. + if (BuildConstants.DIRTY != 0) { + 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 commit the changes, run `git add .` to stage the changes, then run `git commit -m \"\"` 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.", + 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); + } + 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); + DriverStation.reportError( + "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); + } } /** From e66e694abcea013848bf87615f244316391f007f Mon Sep 17 00:00:00 2001 From: Garrett Summerfield Date: Fri, 8 Mar 2024 23:54:44 -0600 Subject: [PATCH 2/4] Add CTRE logging, log writer Added logging for CTRE devices such as CANcoders. Added a log writer that will log to a USB drive plugged into the RIO. --- src/main/java/frc/robot/Robot.java | 24 ++++++++++++--------- src/main/java/frc/robot/RobotContainer.java | 16 +++++++------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/main/java/frc/robot/Robot.java b/src/main/java/frc/robot/Robot.java index 1fc3f6d..87669a6 100644 --- a/src/main/java/frc/robot/Robot.java +++ b/src/main/java/frc/robot/Robot.java @@ -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; @@ -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; @@ -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(); + } } } diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 6ff26c0..35da33b 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -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 \"\"` to commit the changes.", + "To commit the changes, run `git add .` to stage the changes, then run `git commit -m \"\"` 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); } } From 18bfb6e67b16218aa606cfa98d9507f0de237fa8 Mon Sep 17 00:00:00 2001 From: garrettsummerfi3ld Date: Sat, 9 Mar 2024 06:01:27 +0000 Subject: [PATCH 3/4] [Spotless] Apply formatting --- src/main/java/frc/robot/RobotContainer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 9302cd4..31252ac 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -135,7 +135,7 @@ public RobotContainer() { false); DriverStation.reportError("Wait for the pull request to be reviewed and merged", false); } - + drivebase.setDefaultCommand(driveFieldOrientedDirectAngle); } From e0afacb479b8adadbe313f42fda0175f8470a372 Mon Sep 17 00:00:00 2001 From: Garrett Summerfield Date: Sat, 9 Mar 2024 12:06:53 -0600 Subject: [PATCH 4/4] Add event branch warnings "Event" branches are now logged for driver input as well as logging events. --- src/main/java/frc/robot/RobotContainer.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 31252ac..111f31f 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -134,6 +134,20 @@ public RobotContainer() { "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); + } else if (BuildConstants.GIT_BRANCH.contains("event")) { + DriverStation.reportWarning( + "You are currently on an `event` branch. After an event, please merge your changes to main as the event progresses or after the event is over", + false); + DriverStation.reportWarning( + "With event branches, changes made on the fly here should be committed before each build/deploy to the robot", + false); + DriverStation.reportWarning( + "If you are done with the event, please merge and delete the event branch", false); + DriverStation.reportWarning( + "If you are not done with the event, please keep the event branch and continue working on it", + false); + DriverStation.reportWarning( + "If you are not sure, please ask your team leader or mentor for help", false); } drivebase.setDefaultCommand(driveFieldOrientedDirectAngle);