From 3ba92311275e51c824db70f812884f1fd5d7d28c Mon Sep 17 00:00:00 2001 From: Team 199 Driver Station Computer <35879629+DriverStationComputer@users.noreply.github.com> Date: Tue, 10 Mar 2026 16:24:30 -0700 Subject: [PATCH 1/5] SmartDashboard hub activity checks and timers --- .../org/carlmontrobotics/RobotContainer.java | 96 ++++++++++++++++++- 1 file changed, 94 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/carlmontrobotics/RobotContainer.java b/src/main/java/org/carlmontrobotics/RobotContainer.java index 4c5a3d0..fe54726 100644 --- a/src/main/java/org/carlmontrobotics/RobotContainer.java +++ b/src/main/java/org/carlmontrobotics/RobotContainer.java @@ -19,13 +19,18 @@ import java.util.ArrayList; import java.util.List; +import java.util.Optional; import edu.wpi.first.math.MathUtil; import edu.wpi.first.math.geometry.Pose2d; import edu.wpi.first.math.geometry.Rotation2d; import edu.wpi.first.math.geometry.Transform2d; import edu.wpi.first.math.util.Units; +import edu.wpi.first.util.sendable.Sendable; +import edu.wpi.first.util.sendable.SendableBuilder; import edu.wpi.first.wpilibj.DriverStation; +import edu.wpi.first.wpilibj.DriverStation.Alliance; + import java.util.function.BooleanSupplier; import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine; @@ -72,7 +77,7 @@ -public class RobotContainer { +public class RobotContainer implements Sendable { public final GenericHID driverController = new GenericHID(Driver.port); public final XboxController driverRumble = new XboxController(Driver.port); //For rumbling the controller @@ -88,10 +93,12 @@ public class RobotContainer { private SendableChooser autoChooser = new SendableChooser<>(); public boolean alignOverride = true; public boolean autoScoring = true; - public static int intakeCounter; public RobotContainer() { + + + //#region AutoRegistration RegisterAutoCommands(); autoChooser = AutoBuilder.buildAutoChooser(); @@ -160,6 +167,91 @@ private void setDefaultCommands() { public Command getAutonomousCommand() { return Commands.print("No autonomous command configured"); } +public boolean isHubActive() { + Optional alliance = DriverStation.getAlliance(); + // If we have no alliance, we cannot be enabled, therefore no hub. + if (alliance.isEmpty()) { + return false; + } + // Hub is always enabled in autonomous. + if (DriverStation.isAutonomousEnabled()) { + return true; + } + // At this point, if we're not teleop enabled, there is no hub. + if (!DriverStation.isTeleopEnabled()) { + return false; + } + + // We're teleop enabled, compute. + double matchTime = DriverStation.getMatchTime(); + String gameData = DriverStation.getGameSpecificMessage(); + // If we have no game data, we cannot compute, assume hub is active, as its likely early in teleop. + if (gameData.isEmpty()) { + return true; + } + boolean redInactiveFirst = false; + switch (gameData.charAt(0)) { + case 'R' -> redInactiveFirst = true; + case 'B' -> redInactiveFirst = false; + default -> { + // If we have invalid game data, assume hub is active. + return true; + } + } + + // Shift was is active for blue if red won auto, or red if blue won auto. + boolean shift1Active = switch (alliance.get()) { + case Red -> !redInactiveFirst; + case Blue -> redInactiveFirst; + }; + + if (matchTime > 130) { + // Transition shift, hub is active. + return true; + } else if (matchTime > 105) { + // Shift 1 + return shift1Active; + } else if (matchTime > 80) { + // Shift 2 + return !shift1Active; + } else if (matchTime > 55) { + // Shift 3 + return shift1Active; + } else if (matchTime > 30) { + // Shift 4 + return !shift1Active; + } else { + // End game, hub always active. + return true; + } +} + public double hubTimeLeft(){ //Gets time left until hub is active/inactive + double matchTime = DriverStation.getMatchTime(); + if (matchTime > 130) { + // Transition shift, hub is active. + return matchTime - 130; + } else if (matchTime > 105) { + // Shift 1 + return matchTime - 105; + } else if (matchTime > 80) { + // Shift 2 + return matchTime - 80; + } else if (matchTime > 55) { + // Shift 3 + return matchTime - 55; + } else if (matchTime > 30) { + // Shift 4 + return matchTime - 30; + } else { + // End game, hub always active. + return matchTime; + } + } + @Override + public void initSendable(SendableBuilder builder){ + builder.addBooleanProperty("Hub Active (T/F)", this::isHubActive, null); + builder.addDoubleProperty("Hub Time Left", this::hubTimeLeft, null); + } //#endregion //#region HelpfulMethods //TODO: integrate these methods into lib199 From 69838906524a3d2d74c4b080f6c828741675fad6 Mon Sep 17 00:00:00 2001 From: Daniel Tolkachov <107586975+Niosocket11@users.noreply.github.com> Date: Wed, 11 Mar 2026 21:19:50 -0700 Subject: [PATCH 2/5] Update src/main/java/org/carlmontrobotics/RobotContainer.java --- src/main/java/org/carlmontrobotics/RobotContainer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/carlmontrobotics/RobotContainer.java b/src/main/java/org/carlmontrobotics/RobotContainer.java index fe54726..7d807d5 100644 --- a/src/main/java/org/carlmontrobotics/RobotContainer.java +++ b/src/main/java/org/carlmontrobotics/RobotContainer.java @@ -179,7 +179,7 @@ public boolean isHubActive() { } // At this point, if we're not teleop enabled, there is no hub. if (!DriverStation.isTeleopEnabled()) { - return false; + return true; } // We're teleop enabled, compute. From 56f5f7778b99e7cda81f5c1703331105d6495acb Mon Sep 17 00:00:00 2001 From: Niosocket11 Date: Wed, 18 Mar 2026 12:45:32 -0700 Subject: [PATCH 3/5] fixed hub --- .../org/carlmontrobotics/RobotContainer.java | 217 ++++++++++++------ 1 file changed, 141 insertions(+), 76 deletions(-) diff --git a/src/main/java/org/carlmontrobotics/RobotContainer.java b/src/main/java/org/carlmontrobotics/RobotContainer.java index 7d807d5..52d688d 100644 --- a/src/main/java/org/carlmontrobotics/RobotContainer.java +++ b/src/main/java/org/carlmontrobotics/RobotContainer.java @@ -91,9 +91,10 @@ public class RobotContainer implements Sendable { private SendableChooser autoChooser = new SendableChooser<>(); - public boolean alignOverride = true; public boolean autoScoring = true; public static int intakeCounter; + private boolean assumeAutoWin = false; + private String gameData; public RobotContainer() { @@ -105,9 +106,7 @@ public RobotContainer() { SmartDashboard.putData("Auto Chooser", autoChooser); - SmartDashboard.putBoolean("AlignOverride", alignOverride); SmartDashboard.putBoolean("AutoScoring", autoScoring); - SmartDashboard.putBoolean("AlignOverride", true); //#endregion setDefaultCommands(); setBindingsDriver(); @@ -167,90 +166,156 @@ private void setDefaultCommands() { public Command getAutonomousCommand() { return Commands.print("No autonomous command configured"); } -public boolean isHubActive() { - Optional alliance = DriverStation.getAlliance(); - // If we have no alliance, we cannot be enabled, therefore no hub. - if (alliance.isEmpty()) { - return false; - } - // Hub is always enabled in autonomous. - if (DriverStation.isAutonomousEnabled()) { - return true; - } - // At this point, if we're not teleop enabled, there is no hub. - if (!DriverStation.isTeleopEnabled()) { - return true; - } - - // We're teleop enabled, compute. - double matchTime = DriverStation.getMatchTime(); - String gameData = DriverStation.getGameSpecificMessage(); - // If we have no game data, we cannot compute, assume hub is active, as its likely early in teleop. - if (gameData.isEmpty()) { - return true; - } - boolean redInactiveFirst = false; - switch (gameData.charAt(0)) { - case 'R' -> redInactiveFirst = true; - case 'B' -> redInactiveFirst = false; - default -> { - // If we have invalid game data, assume hub is active. + public boolean isHubActive() { + Optional alliance = DriverStation.getAlliance(); + // If we have no alliance, we cannot be enabled, therefore no hub. + if (alliance.isEmpty()) { + return false; + } + // Hub is always enabled in autonomous. + if (DriverStation.isAutonomousEnabled()) { return true; } - } + //Hub is technically on during disabled period + if (!DriverStation.isTeleopEnabled()) { + return true; + } + + // We're teleop enabled, compute. + double matchTime = DriverStation.getMatchTime(); + gameData = DriverStation.getGameSpecificMessage(); + boolean shift1Active; + // If we have no game data, we cannot compute, assume hub is active, as its likely early in teleop. + if (gameData.isEmpty()) { + shift1Active = !assumeAutoWin; + } + else { + boolean redInactiveFirst = false; + switch (gameData.charAt(0)) { + case 'R' -> { + redInactiveFirst = true; + // Shift was is active for blue if red won auto, or red if blue won auto. + shift1Active = switch (alliance.get()) { + case Red -> !redInactiveFirst; + case Blue -> redInactiveFirst; + }; + } + case 'B' -> { + redInactiveFirst = false; + // Shift was is active for blue if red won auto, or red if blue won auto. + shift1Active = switch (alliance.get()) { + case Red -> !redInactiveFirst; + case Blue -> redInactiveFirst; + }; + } + default -> { + // If we have invalid game data, assume hub is active. + shift1Active = !assumeAutoWin; + } + } + } - // Shift was is active for blue if red won auto, or red if blue won auto. - boolean shift1Active = switch (alliance.get()) { - case Red -> !redInactiveFirst; - case Blue -> redInactiveFirst; - }; - - if (matchTime > 130) { - // Transition shift, hub is active. - return true; - } else if (matchTime > 105) { - // Shift 1 - return shift1Active; - } else if (matchTime > 80) { - // Shift 2 - return !shift1Active; - } else if (matchTime > 55) { - // Shift 3 - return shift1Active; - } else if (matchTime > 30) { - // Shift 4 - return !shift1Active; - } else { - // End game, hub always active. - return true; + if (matchTime > 130) { + // Transition shift, hub is active. + return true; + } + else if (matchTime > 105) { + // Shift 1 + return shift1Active; + } + else if (matchTime > 80) { + // Shift 2 + return !shift1Active; + } + else if (matchTime > 55) { + // Shift 3 + return shift1Active; + } + else if (matchTime > 30) { + // Shift 4 + return !shift1Active; + } + else { + // End game, hub always active. + return true; + } } -} public double hubTimeLeft(){ //Gets time left until hub is active/inactive double matchTime = DriverStation.getMatchTime(); + Optional alliance = DriverStation.getAlliance(); + if (DriverStation.isAutonomous()) { + return assumeAutoWin ? matchTime + 10 : matchTime + 35; + } + gameData = DriverStation.getGameSpecificMessage(); + boolean shift1Active; + // If we have no game data, we cannot compute, assume hub is active, as its likely early in teleop. + if (gameData.isEmpty()) { + shift1Active = !assumeAutoWin; + } + else { + boolean redInactiveFirst = false; + switch (gameData.charAt(0)) { + case 'R' -> { + redInactiveFirst = true; + // Shift was is active for blue if red won auto, or red if blue won auto. + shift1Active = switch (alliance.get()) { + case Red -> !redInactiveFirst; + case Blue -> redInactiveFirst; + }; + } + case 'B' -> { + redInactiveFirst = false; + // Shift was is active for blue if red won auto, or red if blue won auto. + shift1Active = switch (alliance.get()) { + case Red -> !redInactiveFirst; + case Blue -> redInactiveFirst; + }; + } + default -> { + // If we have invalid game data, assume hub is active. + shift1Active = !assumeAutoWin; + } + } + } if (matchTime > 130) { - // Transition shift, hub is active. - return matchTime - 130; - } else if (matchTime > 105) { - // Shift 1 - return matchTime - 105; - } else if (matchTime > 80) { - // Shift 2 - return matchTime - 80; - } else if (matchTime > 55) { - // Shift 3 - return matchTime - 55; - } else if (matchTime > 30) { - // Shift 4 - return matchTime - 30; - } else { - // End game, hub always active. - return matchTime; + // Transition shift, hub is active. + return shift1Active ? matchTime - 105 : matchTime - 130; + } + else if (matchTime > 105) { + // Shift 1 + return matchTime - 105; + } + else if (matchTime > 80) { + // Shift 2 + return matchTime - 80; + } + else if (matchTime > 55) { + // Shift 3 + return matchTime - 55; + } + else if (matchTime > 30) { + // Shift 4 + return shift1Active ? matchTime - 30 : matchTime; + } + else { + // End game, hub always active. + return matchTime; + } + } + + public boolean getAssumeAutoWin() { + return assumeAutoWin; } + + public void setAssumeAutoWin(boolean assumption) { + assumeAutoWin = assumption; } + @Override public void initSendable(SendableBuilder builder){ - builder.addBooleanProperty("Hub Active (T/F)", this::isHubActive, null); - builder.addDoubleProperty("Hub Time Left", this::hubTimeLeft, null); + builder.addBooleanProperty("Hub Active (T/F)", this::isHubActive, null); + builder.addDoubleProperty("Hub Time Left", this::hubTimeLeft, null); + builder.addBooleanProperty("Assume Won Auto", this::getAssumeAutoWin, this::setAssumeAutoWin); } //#endregion //#region HelpfulMethods From 6567521e5a3ed5ab88f048d5af6e86f608959090 Mon Sep 17 00:00:00 2001 From: Niosocket11 Date: Wed, 18 Mar 2026 15:13:17 -0700 Subject: [PATCH 4/5] Fully ready and sim tested --- .../org/carlmontrobotics/RobotContainer.java | 51 +++++++++++++++++-- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/carlmontrobotics/RobotContainer.java b/src/main/java/org/carlmontrobotics/RobotContainer.java index 52d688d..a1ed3bb 100644 --- a/src/main/java/org/carlmontrobotics/RobotContainer.java +++ b/src/main/java/org/carlmontrobotics/RobotContainer.java @@ -101,16 +101,20 @@ public RobotContainer() { //#region AutoRegistration - RegisterAutoCommands(); + //RegisterAutoCommands(); + // + // + + autoChooser = AutoBuilder.buildAutoChooser(); SmartDashboard.putData("Auto Chooser", autoChooser); SmartDashboard.putBoolean("AutoScoring", autoScoring); //#endregion - setDefaultCommands(); - setBindingsDriver(); - setBindingsManipulator(); + // setDefaultCommands(); + // setBindingsDriver(); + // setBindingsManipulator(); SmartDashboard.putBoolean("Baby Mode", Config.CONFIG.isBabyMode()); // SmartDashboard.putData("Rotate Command",new RotateToTag(drivetrain, limelight)); @@ -118,6 +122,7 @@ public RobotContainer() { SmartDashboard.putString("Location", DriverStation.getLocation().toString()); SmartDashboard.putBoolean("Connected to FMS?", DriverStation.isFMSAttached()); SmartDashboard.putString("Station", DriverStation.getAlliance().toString() + " " + DriverStation.getLocation().toString()); + SmartDashboard.putData("Hub", this); } @@ -243,6 +248,9 @@ else if (matchTime > 30) { public double hubTimeLeft(){ //Gets time left until hub is active/inactive double matchTime = DriverStation.getMatchTime(); Optional alliance = DriverStation.getAlliance(); + if (alliance.isEmpty()) { + return -1; + } if (DriverStation.isAutonomous()) { return assumeAutoWin ? matchTime + 10 : matchTime + 35; } @@ -311,11 +319,46 @@ public void setAssumeAutoWin(boolean assumption) { assumeAutoWin = assumption; } + private int shiftNumber() { + if (DriverStation.isAutonomous()) { + return 0; + } + if (DriverStation.isTeleop()) { + double matchTime = DriverStation.getMatchTime(); + if (matchTime > 130) { + // Transition shift + return 0; + } + else if (matchTime > 105) { + // Shift 1 + return 1; + } + else if (matchTime > 80) { + // Shift 2 + return 2; + } + else if (matchTime > 55) { + // Shift 3 + return 3; + } + else if (matchTime > 30) { + // Shift 4 + return 4; + } + else { + // End game + return 5; + } + } + return 0; + } + @Override public void initSendable(SendableBuilder builder){ builder.addBooleanProperty("Hub Active (T/F)", this::isHubActive, null); builder.addDoubleProperty("Hub Time Left", this::hubTimeLeft, null); builder.addBooleanProperty("Assume Won Auto", this::getAssumeAutoWin, this::setAssumeAutoWin); + builder.addDoubleProperty("Active shift", this::shiftNumber, null); } //#endregion //#region HelpfulMethods From 6aef36be286c1e70c965e1c8d966c4df860fb2ad Mon Sep 17 00:00:00 2001 From: Niosocket11 Date: Wed, 18 Mar 2026 15:16:04 -0700 Subject: [PATCH 5/5] forgor to uncomment --- src/main/java/org/carlmontrobotics/RobotContainer.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/carlmontrobotics/RobotContainer.java b/src/main/java/org/carlmontrobotics/RobotContainer.java index a1ed3bb..cf9defd 100644 --- a/src/main/java/org/carlmontrobotics/RobotContainer.java +++ b/src/main/java/org/carlmontrobotics/RobotContainer.java @@ -101,7 +101,7 @@ public RobotContainer() { //#region AutoRegistration - //RegisterAutoCommands(); + RegisterAutoCommands(); // // @@ -112,9 +112,9 @@ public RobotContainer() { SmartDashboard.putBoolean("AutoScoring", autoScoring); //#endregion - // setDefaultCommands(); - // setBindingsDriver(); - // setBindingsManipulator(); + setDefaultCommands(); + setBindingsDriver(); + setBindingsManipulator(); SmartDashboard.putBoolean("Baby Mode", Config.CONFIG.isBabyMode()); // SmartDashboard.putData("Rotate Command",new RotateToTag(drivetrain, limelight));