Skip to content

Commit

Permalink
Preemptively avoid NaN errors
Browse files Browse the repository at this point in the history
Hopefully this was the issue with brownout limits
  • Loading branch information
ky28059 committed Feb 26, 2022
1 parent 5f2c634 commit 38440de
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/java/frc/robot/brownout/PowerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public PowerController(GRTSubsystem... subsystems) {
*/
public void calculateLimits() {
double totalDraw = PDH.getTotalCurrent();
if (totalDraw == 0) return;
calculateLimits(totalSustainableCurrent, totalDraw, Set.of(subsystems));
}

Expand All @@ -42,6 +41,12 @@ public void calculateLimits() {
* @param remaining The remaining (non-scaled) subsystems.
*/
private void calculateLimits(double totalCurrent, double totalDraw, Set<GRTSubsystem> remaining) {
// If the total draw is 0, avoid `NaN` by setting all remaining subsystems to their minimums
if (totalDraw == 0) {
remaining.forEach(subsystem -> subsystem.setCurrentLimit(subsystem.getMinCurrent()));
return;
}

// Calculate the "ideal ratio" from the total drawn current
double idealRatio = totalCurrent / totalDraw;

Expand Down

0 comments on commit 38440de

Please sign in to comment.