diff --git a/.gitignore b/.gitignore index 5528d4f6..30e1060b 100644 --- a/.gitignore +++ b/.gitignore @@ -176,3 +176,19 @@ logs/ # Folder that has CTRE Phoenix Sim device config storage ctre_sim/ + +# START: Setup gversion + +# Tell git to ignore the generated file: src/main/java/frc/robot/BuildConstants.java +# We generally don't want to commit/track changes to files that are auto-generated during the build process + +src/main/java/frc/robot/BuildConstants.java +# END: Setup gversion + +# START: Setup AdvantageKit + +# Tell git to ignore the generated files ending with: .wpilog +# Most wpilog files are useful only during development/debugging. One exception is logs captured during an actual competition/match. It may be useful to save them for post-match analysis to debug/understand what happened + +*.wpilog +# END: Setup AdvantageKit diff --git a/build.gradle b/build.gradle index a4b93fed..8f67b5a0 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ plugins { id "java" id "edu.wpi.first.GradleRIO" version "2024.1.1" id "com.diffplug.spotless" version "6.23.3" + id "com.peterabeles.gversion" version "1.10.2" } java { @@ -160,3 +161,45 @@ if (!('spotlessCheck' in gradle.startParameter.taskNames)) { spotlessMiscCheck.enabled = false } // END: Setup spotless + +// START: Setup gversion +project.compileJava.dependsOn(createVersionFile) +gversion { + srcDir = "src/main/java/" + classPackage = "frc.robot" + className = "BuildConstants" + dateFormat = "yyyy-MM-dd HH:mm:ss z" + timeZone = "America/New_York" // Use preferred time zone + indent = " " +} +// END: Setup gversion + +// START: Setup AdvantageKit +repositories { + maven { + url = uri("https://maven.pkg.github.com/Mechanical-Advantage/AdvantageKit") + credentials { + username = "Mechanical-Advantage-Bot" + password = "\u0067\u0068\u0070\u005f\u006e\u0056\u0051\u006a\u0055\u004f\u004c\u0061\u0079\u0066\u006e\u0078\u006e\u0037\u0051\u0049\u0054\u0042\u0032\u004c\u004a\u006d\u0055\u0070\u0073\u0031\u006d\u0037\u004c\u005a\u0030\u0076\u0062\u0070\u0063\u0051" + } + } + mavenLocal() +} + +configurations.all { + exclude group: "edu.wpi.first.wpilibj" +} + +task(checkAkitInstall, dependsOn: "classes", type: JavaExec) { + mainClass = "org.littletonrobotics.junction.CheckInstall" + classpath = sourceSets.main.runtimeClasspath +} +compileJava.finalizedBy checkAkitInstall + +dependencies { + // ... + def akitJson = new groovy.json.JsonSlurper().parseText(new File(projectDir.getAbsolutePath() + "/vendordeps/AdvantageKit.json").text) + annotationProcessor "org.littletonrobotics.akit.junction:junction-autolog:$akitJson.version" +} + +// END: Setup AdvantageKit \ No newline at end of file diff --git a/src/main/java/frc/robot/Robot.java b/src/main/java/frc/robot/Robot.java index b68462c8..dc2d64fc 100644 --- a/src/main/java/frc/robot/Robot.java +++ b/src/main/java/frc/robot/Robot.java @@ -4,17 +4,71 @@ package frc.robot; -import edu.wpi.first.wpilibj.TimedRobot; + import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.CommandScheduler; - -public class Robot extends TimedRobot { +// START: Setup AdvantageKit +import org.littletonrobotics.junction.LoggedRobot; +import org.littletonrobotics.junction.Logger; +import org.littletonrobotics.junction.networktables.NT4Publisher; +import org.littletonrobotics.junction.wpilog.WPILOGWriter; +// END: Setup AdvantageKit +public class Robot extends LoggedRobot { private Command m_autonomousCommand; private RobotContainer m_robotContainer; @Override public void robotInit() { + // START: Setup AdvantageKit + + // Record build metadata generated by gversion + Logger.recordMetadata("ProjectName", BuildConstants.MAVEN_NAME); + Logger.recordMetadata("BuildDate", BuildConstants.BUILD_DATE); + Logger.recordMetadata("GitSHA", BuildConstants.GIT_SHA); + Logger.recordMetadata("GitDate", BuildConstants.GIT_DATE); + Logger.recordMetadata("GitBranch", BuildConstants.GIT_BRANCH); + switch (BuildConstants.DIRTY) { + case 0: + Logger.recordMetadata("GitDirty", "All changes committed"); + break; + case 1: + Logger.recordMetadata("GitDirty", "Uncomitted changes"); + break; + default: + Logger.recordMetadata("GitDirty", "Unknown"); + break; + } + + /* Initialize AdvantageKit Logging */ + // Set up data receivers & replay source + + //We will add support for replay mode later + /*if (Constants.AdvantageKit.REPLAY_MODE) { + // Running in replay mode + setUseTiming(false); // Run as fast as possible + String logPath = + LogFileUtil + .findReplayLog(); // Pull the replay log from AdvantageScope (or prompt the user) + Logger.setReplaySource(new WPILOGReader(logPath)); // Read replay log + Logger.addDataReceiver( + new WPILOGWriter( + LogFileUtil.addPathSuffix(logPath, "_sim"))); // Save outputs to a new log + } else {*/ + if (isReal()) { + // Running on real robot + Logger.addDataReceiver(new WPILOGWriter("/media/sda1/")); // Log to a USB stick + Logger.addDataReceiver(new NT4Publisher()); // Publish data to NetworkTables + } else { + // Running in simulation + Logger.addDataReceiver(new WPILOGWriter("")); + Logger.addDataReceiver(new NT4Publisher()); + } + //} + + Logger.start(); // Start logging! No more data receivers, replay sources, or metadata values may + // be added. + // END: Setup AdvantageKit m_robotContainer = new RobotContainer(); } diff --git a/vendordeps/AdvantageKit.json b/vendordeps/AdvantageKit.json new file mode 100644 index 00000000..cca06ae6 --- /dev/null +++ b/vendordeps/AdvantageKit.json @@ -0,0 +1,42 @@ +{ + "fileName": "AdvantageKit.json", + "name": "AdvantageKit", + "version": "3.0.0", + "uuid": "d820cc26-74e3-11ec-90d6-0242ac120003", + "frcYear": "2024", + "mavenUrls": [], + "jsonUrl": "https://github.com/Mechanical-Advantage/AdvantageKit/releases/latest/download/AdvantageKit.json", + "javaDependencies": [ + { + "groupId": "org.littletonrobotics.akit.junction", + "artifactId": "wpilib-shim", + "version": "3.0.0" + }, + { + "groupId": "org.littletonrobotics.akit.junction", + "artifactId": "junction-core", + "version": "3.0.0" + }, + { + "groupId": "org.littletonrobotics.akit.conduit", + "artifactId": "conduit-api", + "version": "3.0.0" + } + ], + "jniDependencies": [ + { + "groupId": "org.littletonrobotics.akit.conduit", + "artifactId": "conduit-wpilibio", + "version": "3.0.0", + "skipInvalidPlatforms": false, + "isJar": false, + "validPlatforms": [ + "linuxathena", + "windowsx86-64", + "linuxx86-64", + "osxuniversal" + ] + } + ], + "cppDependencies": [] +} \ No newline at end of file