Brownout Guard
Disclaimer: WIP and untested on 2026 hardware; tune voltage thresholds and limits on your robot. Custom code built on WPILib APIs (not official WPILib sample).
Purpose: Prevent brownouts during bursts (fuel hoard/burst, climbs) by scaling outputs when voltage drops.
Code (Java/WPILib helper)
public class BrownoutGuard {
private final double lowVoltage;
private final double scale;
private final Timer timer = new Timer();
private boolean inGuard = false;
public BrownoutGuard(double lowVoltage, double scale, double minHoldSec) {
this.lowVoltage = lowVoltage;
this.scale = scale;
timer.reset(); timer.start();
}
public double guard(double requested) {
double v = RobotController.getBatteryVoltage();
if (v < lowVoltage) {
inGuard = true;
timer.reset();
}
if (inGuard && timer.get() > 0.5) { // hold guard for 0.5s minimum
inGuard = false;
}
return inGuard ? requested * scale : requested;
}
}
Usage
BrownoutGuard driveGuard = new BrownoutGuard(10.5, 0.7, 0.5);
// In drive code:
double scaled = driveGuard.guard(requestedPercent);
driveMotor.set(scaled);
Add current limits (example TalonFX)
SupplyCurrentLimitConfiguration limit =
new SupplyCurrentLimitConfiguration(true, 40.0, 50.0, 0.1);
talon.configSupplyCurrentLimit(limit);
How to test
- On blocks: slam joysticks; watch voltage; confirm scale kicks in near 10.5 V.
- Burn-in: log voltage/current; verify fewer brownouts with guard enabled.
Pitfalls
- Don’t set
lowVoltagetoo high or you’ll feel sluggish all match. - Keep the guard window short; long scaling hurts responsiveness.