diff --git a/src/main/java/frc/robot/BuildConstants.java b/src/main/java/frc/robot/BuildConstants.java index 30a569c..7aadd99 100644 --- a/src/main/java/frc/robot/BuildConstants.java +++ b/src/main/java/frc/robot/BuildConstants.java @@ -1,17 +1,19 @@ package frc.robot; -/** Automatically generated file containing build version information. */ +/** + * Automatically generated file containing build version information. + */ public final class BuildConstants { public static final String MAVEN_GROUP = ""; - public static final String MAVEN_NAME = "4829-BaseRobotCode-1"; + public static final String MAVEN_NAME = "4829-BaseRobotCode"; public static final String VERSION = "unspecified"; - public static final int GIT_REVISION = 32; - public static final String GIT_SHA = "71a47d311fd066ba3b76be8d09eff3e03b893cd8"; - public static final String GIT_DATE = "2024-10-28 22:21:12 EDT"; - public static final String GIT_BRANCH = "docs"; - public static final String BUILD_DATE = "2024-10-29 16:56:45 EDT"; - public static final long BUILD_UNIX_TIME = 1730235405242L; + public static final int GIT_REVISION = 8; + public static final String GIT_SHA = "52fbf88798bd786d25dffff6b4769182ad9ea51c"; + public static final String GIT_DATE = "2024-10-29 17:58:37 EDT"; + public static final String GIT_BRANCH = "main"; + public static final String BUILD_DATE = "2024-11-05 07:52:13 EST"; + public static final long BUILD_UNIX_TIME = 1730811133569L; public static final int DIRTY = 0; - private BuildConstants() {} + private BuildConstants(){} } diff --git a/src/test/java/RobotTest.java b/src/test/java/RobotTest.java new file mode 100644 index 0000000..66a29b7 --- /dev/null +++ b/src/test/java/RobotTest.java @@ -0,0 +1,94 @@ +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +// import com.igknighters.commands.autos.Autos; +// import com.igknighters.constants.ConstValues; +// import com.igknighters.constants.RobotSetup; +// import com.igknighters.constants.RobotSetup.RobotID; +// import com.igknighters.util.RobotExtension.Robo; +import com.pathplanner.lib.commands.PathPlannerAuto; + +import edu.wpi.first.hal.AllianceStationID; +import edu.wpi.first.hal.HAL; +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.simulation.DriverStationSim; +import edu.wpi.first.wpilibj2.command.CommandScheduler; +import edu.wpi.first.wpilibj2.command.ProxyCommand; + +public class RobotTest { + + @BeforeEach + protected void startSim() { + GlobalState.setUnitTest(true); + assert HAL.initialize(500, 0); + } + + @AfterEach + protected void teardownSim() { + HAL.exitMain(); + HAL.shutdown(); + GlobalState.restoreDefaultState(); + var cmdScheduler = CommandScheduler.getInstance(); + cmdScheduler.cancelAll(); + cmdScheduler.getActiveButtonLoop().clear(); + cmdScheduler.getDefaultButtonLoop().clear(); + cmdScheduler.clearComposedCommands(); + cmdScheduler.unregisterAllSubsystems(); + } + + @Test + public void testRobotSetup() { + for (RobotID id : RobotID.values()) { + if (id == RobotID.Unlabeled) { + continue; + } + + RobotSetup.testOverrideRobotID(id); + + com.igknighters.ConstantHelper.applyRoboConst(ConstValues.class); + + new RobotContainer(); + + CommandScheduler.getInstance().getActiveButtonLoop().clear(); + CommandScheduler.getInstance().getDefaultButtonLoop().clear(); + + System.gc(); + } + } + + @Test + public void testAuto(@Robo Robot robot) { + RobotSetup.testOverrideRobotID(RobotID.SIM_CRASH); + Pose2d desiredEndPose = new Pose2d( + new Translation2d(3.0, 7.0), + new Rotation2d()); + + DriverStationSim.setAllianceStationId(AllianceStationID.Blue1); + + // meters + final double translationTolerance = 0.2; + + Autos.setAutoOverrideTest(new ProxyCommand(() -> new PathPlannerAuto("1 Meter Auto"))); + DriverStationSim.setAutonomous(true); + DriverStationSim.setEnabled(true); + + robot.withAutonomousPeriodicTest(robo -> { + boolean isFinished = GlobalState.getLocalizedPose() + .getTranslation() + .getDistance(desiredEndPose.getTranslation()) < translationTolerance; + + if (isFinished) { + robo.finishUnitTestRobot(); + } else if (robo.getElapsedTime() > 2.5) { + throw new RuntimeException( + "Auto took to long, ended at " + + GlobalState.getLocalizedPose().toString()); + } + }); + + robot.runTest(3); + } +} \ No newline at end of file