From df2156deb6b93d4739599aec4d6c8e2536040825 Mon Sep 17 00:00:00 2001 From: EduardoBarreto3006 Date: Tue, 31 Mar 2026 15:42:01 -0400 Subject: [PATCH 1/7] [#498] Added the isHubActive() function and tested it in sim --- src/main/java/frc/util/AllianceHelpers.java | 58 +++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/main/java/frc/util/AllianceHelpers.java b/src/main/java/frc/util/AllianceHelpers.java index 3fac9488..48c4039e 100644 --- a/src/main/java/frc/util/AllianceHelpers.java +++ b/src/main/java/frc/util/AllianceHelpers.java @@ -1,6 +1,10 @@ package frc.util; +import java.util.Optional; + import edu.wpi.first.wpilibj.DriverStation; +import edu.wpi.first.wpilibj.DriverStation.Alliance; +import frc.util.shuffleboard.LightningShuffleboard; public class AllianceHelpers { @@ -17,4 +21,58 @@ public static boolean isBlueAlliance() { public static boolean isRedAlliance() { return !isBlueAlliance(); } + + public boolean isHubActive() { + // 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 one is active for blue if red won auto, or red if blue won auto. + boolean shift1Active = isBlueAlliance() ? redInactiveFirst : !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; + } + } } \ No newline at end of file From a0596243b7e6b20bc4796b73987d954a24c1d402 Mon Sep 17 00:00:00 2001 From: EduardoBarreto3006 Date: Tue, 31 Mar 2026 15:47:06 -0400 Subject: [PATCH 2/7] [#498] Removed unused imports --- src/main/java/frc/util/AllianceHelpers.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/frc/util/AllianceHelpers.java b/src/main/java/frc/util/AllianceHelpers.java index 48c4039e..bd94faa9 100644 --- a/src/main/java/frc/util/AllianceHelpers.java +++ b/src/main/java/frc/util/AllianceHelpers.java @@ -1,10 +1,6 @@ package frc.util; -import java.util.Optional; - import edu.wpi.first.wpilibj.DriverStation; -import edu.wpi.first.wpilibj.DriverStation.Alliance; -import frc.util.shuffleboard.LightningShuffleboard; public class AllianceHelpers { From cbab4e2543f50933a224bd14ca65e55e1f3ef8c4 Mon Sep 17 00:00:00 2001 From: EduardoBarreto3006 Date: Tue, 31 Mar 2026 16:03:55 -0400 Subject: [PATCH 3/7] haha --- src/main/java/frc/util/AllianceHelpers.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/frc/util/AllianceHelpers.java b/src/main/java/frc/util/AllianceHelpers.java index bd94faa9..16a44542 100644 --- a/src/main/java/frc/util/AllianceHelpers.java +++ b/src/main/java/frc/util/AllianceHelpers.java @@ -40,12 +40,10 @@ public boolean isHubActive() { 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; - } + case 'R': + redInactiveFirst = true; + case 'B': + redInactiveFirst = false; } // Shift one is active for blue if red won auto, or red if blue won auto. From de9760ce7e07a33af4d27ffdaaff5b172ebc9aba Mon Sep 17 00:00:00 2001 From: Advaith Date: Wed, 1 Apr 2026 19:21:44 -0400 Subject: [PATCH 4/7] [#511] Made a trigger that looks for the hub being active and the robot is in our alliance zone --- src/main/java/frc/robot/RobotContainer.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 40b8411d..7f366a88 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -10,6 +10,7 @@ import edu.wpi.first.math.VecBuilder; import edu.wpi.first.math.geometry.Translation2d; import static edu.wpi.first.units.Units.MetersPerSecond; +import static edu.wpi.first.units.Units.RotationsPerSecond; import edu.wpi.first.wpilibj.DriverStation; import edu.wpi.first.wpilibj.GenericHID; import edu.wpi.first.wpilibj.PowerDistribution; @@ -45,6 +46,7 @@ import frc.robot.subsystems.Telemetry; import frc.robot.subsystems.Turret; import frc.robot.subsystems.Turret.TurretConstants; +import frc.util.AllianceHelpers; import frc.util.leds.Color; import frc.util.leds.LEDBehaviorFactory; import frc.util.leds.LEDBooleanSupplier; @@ -69,6 +71,7 @@ public class RobotContainer { private final PhotonVision vision; private final Telemetry logger; private final Cannon cannon; + private final AllianceHelpers allianceHelper; private SendableChooser autoChooser = new SendableChooser<>(); @@ -89,6 +92,7 @@ public RobotContainer() { turret = new Turret(drivetrain); cannon = new Cannon(shooter, turret, hood, drivetrain, indexer); vision = new PhotonVision(drivetrain); + allianceHelper = new AllianceHelpers(); if (Robot.isSimulation()) { @@ -192,6 +196,7 @@ private void configureBindings() { new Trigger(copilot::getAButton).whileTrue(indexer.autoIndex(IndexerConstants.SPINDEXDER_POWER, IndexerConstants.TRANSFER_POWER)).onFalse(new InstantCommand(() -> indexer.stop())); new Trigger(copilot::getYButton).whileTrue(indexer.indexCommand(-0.5).withTimeout(0.1).andThen(indexer.indexCommand(1))); + new Trigger(() -> allianceHelper.isHubActive()).and(() -> drivetrain.isInZone()).whileTrue(shooter.shootCommand(RotationsPerSecond.of(41))); } private void configureNamedCommands() { From 613eeef905ceec1d350258c94833525955f45f25 Mon Sep 17 00:00:00 2001 From: Advaith Date: Wed, 1 Apr 2026 19:33:06 -0400 Subject: [PATCH 5/7] [#511] Uses the interpolation map instead of a set value fo 41 --- src/main/java/frc/robot/RobotContainer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 7f366a88..c6a2dc77 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -11,6 +11,7 @@ import edu.wpi.first.math.geometry.Translation2d; import static edu.wpi.first.units.Units.MetersPerSecond; import static edu.wpi.first.units.Units.RotationsPerSecond; +import static edu.wpi.first.units.Units.Inches; import edu.wpi.first.wpilibj.DriverStation; import edu.wpi.first.wpilibj.GenericHID; import edu.wpi.first.wpilibj.PowerDistribution; @@ -196,7 +197,7 @@ private void configureBindings() { new Trigger(copilot::getAButton).whileTrue(indexer.autoIndex(IndexerConstants.SPINDEXDER_POWER, IndexerConstants.TRANSFER_POWER)).onFalse(new InstantCommand(() -> indexer.stop())); new Trigger(copilot::getYButton).whileTrue(indexer.indexCommand(-0.5).withTimeout(0.1).andThen(indexer.indexCommand(1))); - new Trigger(() -> allianceHelper.isHubActive()).and(() -> drivetrain.isInZone()).whileTrue(shooter.shootCommand(RotationsPerSecond.of(41))); + new Trigger(() -> allianceHelper.isHubActive()).and(() -> drivetrain.isInZone()).whileTrue(shooter.shootCommand(ShooterConstants.VELOCITY_MAP.get(Inches.of(cannon.getShooterTranslation().getNorm())))); } private void configureNamedCommands() { From 6266368027c144544a09b79253f6b82cf0f13627 Mon Sep 17 00:00:00 2001 From: EduardoBarreto3006 Date: Wed, 1 Apr 2026 19:45:49 -0400 Subject: [PATCH 6/7] [#511] Fixed the trigger to get the target distance instead --- 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 c6a2dc77..d53c517a 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -197,7 +197,7 @@ private void configureBindings() { new Trigger(copilot::getAButton).whileTrue(indexer.autoIndex(IndexerConstants.SPINDEXDER_POWER, IndexerConstants.TRANSFER_POWER)).onFalse(new InstantCommand(() -> indexer.stop())); new Trigger(copilot::getYButton).whileTrue(indexer.indexCommand(-0.5).withTimeout(0.1).andThen(indexer.indexCommand(1))); - new Trigger(() -> allianceHelper.isHubActive()).and(() -> drivetrain.isInZone()).whileTrue(shooter.shootCommand(ShooterConstants.VELOCITY_MAP.get(Inches.of(cannon.getShooterTranslation().getNorm())))); + new Trigger(() -> allianceHelper.isHubActive()).and(() -> drivetrain.isInZone()).whileTrue(shooter.shootCommand(ShooterConstants.VELOCITY_MAP.get(cannon.getTargetDistance()))); } private void configureNamedCommands() { From 13bbb57408641aabd12f0291a87f40d214a883fd Mon Sep 17 00:00:00 2001 From: EduardoBarreto3006 Date: Thu, 2 Apr 2026 12:39:09 -0400 Subject: [PATCH 7/7] [#511] Created another very similar to isHubActive() that adds one second to each of the if clauses to start the shoot command 1 second before the hub is actually active. --- src/main/java/frc/robot/RobotContainer.java | 9 ++-- src/main/java/frc/util/AllianceHelpers.java | 55 ++++++++++++++++++++- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index d53c517a..c168a2a6 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -72,8 +72,7 @@ public class RobotContainer { private final PhotonVision vision; private final Telemetry logger; private final Cannon cannon; - private final AllianceHelpers allianceHelper; - + private SendableChooser autoChooser = new SendableChooser<>(); public RobotContainer() { @@ -92,9 +91,7 @@ public RobotContainer() { hood = new Hood(); turret = new Turret(drivetrain); cannon = new Cannon(shooter, turret, hood, drivetrain, indexer); - vision = new PhotonVision(drivetrain); - allianceHelper = new AllianceHelpers(); - + vision = new PhotonVision(drivetrain); if (Robot.isSimulation()) { new MapleSim(drivetrain, collector, indexer, turret, hood, shooter); @@ -197,7 +194,7 @@ private void configureBindings() { new Trigger(copilot::getAButton).whileTrue(indexer.autoIndex(IndexerConstants.SPINDEXDER_POWER, IndexerConstants.TRANSFER_POWER)).onFalse(new InstantCommand(() -> indexer.stop())); new Trigger(copilot::getYButton).whileTrue(indexer.indexCommand(-0.5).withTimeout(0.1).andThen(indexer.indexCommand(1))); - new Trigger(() -> allianceHelper.isHubActive()).and(() -> drivetrain.isInZone()).whileTrue(shooter.shootCommand(ShooterConstants.VELOCITY_MAP.get(cannon.getTargetDistance()))); + new Trigger(() -> AllianceHelpers.isHubAboutToBeActive()).and(() -> drivetrain.isInZone()).whileTrue(shooter.runShootCommand(() -> ShooterConstants.VELOCITY_MAP.get(cannon.getTargetDistance()))); } private void configureNamedCommands() { diff --git a/src/main/java/frc/util/AllianceHelpers.java b/src/main/java/frc/util/AllianceHelpers.java index 16a44542..4f8e95c9 100644 --- a/src/main/java/frc/util/AllianceHelpers.java +++ b/src/main/java/frc/util/AllianceHelpers.java @@ -1,6 +1,7 @@ package frc.util; import edu.wpi.first.wpilibj.DriverStation; +import edu.wpi.first.wpilibj.Timer; public class AllianceHelpers { @@ -18,7 +19,7 @@ public static boolean isRedAlliance() { return !isBlueAlliance(); } - public boolean isHubActive() { + public static boolean isHubActive() { // Hub is always enabled in autonomous. if (DriverStation.isAutonomousEnabled()) { return true; @@ -69,4 +70,56 @@ public boolean isHubActive() { return true; } } + + public static boolean isHubAboutToBeActive() { + // 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; + } + + // Shift one is active for blue if red won auto, or red if blue won auto. + boolean shift1Active = isBlueAlliance() ? redInactiveFirst : !redInactiveFirst; + + if (matchTime > 131) { + // Transition shift, hub is active. + return true; + } else if (matchTime > 106) { + // Shift 1 + return shift1Active; + } else if (matchTime > 81) { + // Shift 2 + return !shift1Active; + } else if (matchTime > 56) { + // Shift 3 + return shift1Active; + } else if (matchTime > 31) { + // Shift 4 + return !shift1Active; + } else { + // End game, hub always active. + return true; + } + } } \ No newline at end of file