Skip to content

Commit d6ed458

Browse files
committed
Add low voltage warning for DT
1 parent d060276 commit d6ed458

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/main/java/frc/robot/Constants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public class Constants {
1212

1313
public static final double kLoopPeriodSecs = 0.02;
1414

15+
public static final double LOW_VOLTAGE_WARNING_THRESHOLD = 10.0;
16+
1517
public enum RobotMode {
1618
REAL,
1719
SIM,

src/main/java/frc/robot/Robot.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
package frc.robot;
1515

16+
import edu.wpi.first.math.filter.Debouncer;
17+
import edu.wpi.first.wpilibj.Alert;
1618
import edu.wpi.first.wpilibj.DriverStation;
1719
import edu.wpi.first.wpilibj.RobotController;
1820
import edu.wpi.first.wpilibj.Threads;
@@ -37,6 +39,10 @@ public class Robot extends LoggedRobot {
3739
private Command autonomousCommand;
3840
private final RobotContainer robotContainer;
3941

42+
private final Alert lowBatteryVoltageAlert =
43+
new Alert("Battery voltage is too low, change the battery", Alert.AlertType.kWarning);
44+
private final Debouncer batteryVoltageDebouncer = new Debouncer(0.5);
45+
4046
public Robot() {
4147
super(Constants.kLoopPeriodSecs);
4248

@@ -86,6 +92,11 @@ public void robotPeriodic() {
8692
// Run command scheduler
8793
CommandScheduler.getInstance().run();
8894

95+
// Update Battery Voltage Alert
96+
lowBatteryVoltageAlert.set(
97+
batteryVoltageDebouncer.calculate(
98+
RobotController.getBatteryVoltage() <= Constants.LOW_VOLTAGE_WARNING_THRESHOLD));
99+
89100
// Return to normal thread priority
90101
Threads.setCurrentThreadPriority(false, 10);
91102
}

0 commit comments

Comments
 (0)