From fd370d250086ba1fcacbfec5c7387003931cb546 Mon Sep 17 00:00:00 2001 From: iefomit Date: Tue, 31 Mar 2026 19:21:13 -0700 Subject: [PATCH] phase change timer --- src/main/java/frc/robot/RobotContainer.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index cb80978..21c9411 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -11,6 +11,7 @@ import com.pathplanner.lib.commands.PathPlannerAuto; import edu.wpi.first.math.geometry.Pose3d; import edu.wpi.first.wpilibj.DriverStation; +import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.PS5Controller; import edu.wpi.first.wpilibj.RobotController; import edu.wpi.first.wpilibj.livewindow.LiveWindow; @@ -78,6 +79,10 @@ public class RobotContainer { // Auto Command selection private final SendableChooser autoChooser = new SendableChooser<>(); + // custom match timer + private final Timer matchTimer = new Timer(); + private boolean hasBeenEnabled = false; + /** * The container for the robot. Contains subsystems, OI devices, and commands. *

@@ -325,11 +330,21 @@ public class RobotContainer { /** Updates SmartDashboard values that need to be refreshed every loop */ public void periodic() { + // update custom timer (counts before phase change) + if (!hasBeenEnabled) { + if (DriverStation.isAutonomousEnabled() || DriverStation.isTeleopEnabled()) { + matchTimer.reset(); + matchTimer.start(); + hasBeenEnabled = true; + } + } + // update match timer double matchTime = DriverStation.getMatchTime(); if (matchTime > 0) { SmartDashboard.putNumber("Match Time", matchTime); } + SmartDashboard.putNumber("Phase Change Time", matchTimer.get()); SmartDashboard.putString("Alliance", DriverStation.getAlliance().toString()); } } -- 2.39.5