diff --git a/src/main/java/frc/robot/Robot.java b/src/main/java/frc/robot/Robot.java index 45ca9d5..2af5bc3 100644 --- a/src/main/java/frc/robot/Robot.java +++ b/src/main/java/frc/robot/Robot.java @@ -12,6 +12,14 @@ import frc.robot.LimelightHelpers.PoseEstimate; public class Robot extends TimedRobot { + + private static final double kLowBatteryVoltage = 11.8; + private static final double kLowBatteryDisabledTime = 1.5; //seconds + + private final Timer batteryTimer = new Timer(); + private boolean lowBatteryAlert = false; + + private Command m_autonomousCommand; private final RobotContainer m_container = new RobotContainer(); @@ -124,6 +132,8 @@ public void robotInit() { DriverStation.silenceJoystickConnectionWarning(true); } + batteryTimer.start(); + } @Override @@ -164,6 +174,19 @@ public void robotPeriodic() { } */ } + + if(DriverStation.isEnabled()){ + batteryTimer.reset(); + } + double batteryVoltage = RobotController.getBatteryVoltage(); + + if(batteryVoltage<= kLowBatteryVoltage && batteryTimer.hasElapsed(kLowBatteryDisabledTime)){ + lowBatteryAlert = true; + } else { + lowBatteryAlert = false; + } + + SmartDashboard.putBoolean("LowBattery", lowBatteryAlert); } @Override @@ -221,4 +244,4 @@ public void simulationPeriodic() { // If you have physics simulation, put it here // For now: do nothing fast } -} \ No newline at end of file +}