]> git.taranathan.com Git - FRC2026.git/commitdiff
EMA breaker
authorWesley28w <wesleycwong@gmail.com>
Sat, 18 Apr 2026 15:29:55 +0000 (08:29 -0700)
committerWesley28w <wesleycwong@gmail.com>
Sat, 18 Apr 2026 15:29:55 +0000 (08:29 -0700)
src/main/java/frc/robot/subsystems/Breaker/Breaker.java [deleted file]
src/main/java/frc/robot/subsystems/Breaker/EMABreaker.java [new file with mode: 0644]

diff --git a/src/main/java/frc/robot/subsystems/Breaker/Breaker.java b/src/main/java/frc/robot/subsystems/Breaker/Breaker.java
deleted file mode 100644 (file)
index cf175ab..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-package frc.robot.subsystems.Breaker;
-
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import edu.wpi.first.wpilibj.PowerDistribution;
-import edu.wpi.first.wpilibj2.command.SubsystemBase;
-import frc.robot.constants.Constants;
-
-public class Breaker extends SubsystemBase {
-
-    private static class Current {
-        double alpha; // how much of the error we correct per loop
-        double average = 0;
-        double threshold;
-    }
-
-    PowerDistribution pDis = new PowerDistribution();
-
-    private List<Current> filters = new ArrayList<>(); // contains currents with their alphas and thresholds
-
-    public Breaker() {
-        for (Map.Entry<Double, Double> entry : BreakerConstants.THRESHOLDS.entrySet()) {
-            double tau = entry.getKey(); // sec
-            double threshold = entry.getValue(); // A
-
-            Current w = new Current(); // create a filter for the threshold
-            w.threshold = threshold;
-            w.alpha = 1 - Math.exp(-Constants.LOOP_TIME / tau); // 1 - e^(-0.02/1) = 0.0198, 1 - e^(-0.02/2) = 0.00995 
-
-            filters.add(w);
-        }
-    }
-
-    @Override
-    public void periodic() {
-        double current = getCurrentFromPowerDistribution();
-        for (Current f : filters) {
-            // new avg = old avg + fractionAlpha * difference
-            f.average += f.alpha * (current - f.average);
-        }
-    }
-
-    public double getCurrentFromPowerDistribution() {
-        return pDis.getTotalCurrent(); // not using .getCurrent() and then an arguement for the port you can get just one port
-    }
-
-    public boolean isOverCurrent() {
-        for (Current f : filters) {
-            if (f.average > f.threshold) {
-                return true; // uh oh
-            }
-        }
-        return false;
-    }
-}
diff --git a/src/main/java/frc/robot/subsystems/Breaker/EMABreaker.java b/src/main/java/frc/robot/subsystems/Breaker/EMABreaker.java
new file mode 100644 (file)
index 0000000..244888c
--- /dev/null
@@ -0,0 +1,58 @@
+package frc.robot.subsystems.Breaker;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import edu.wpi.first.wpilibj.PowerDistribution;
+import edu.wpi.first.wpilibj2.command.SubsystemBase;
+import frc.robot.constants.Constants;
+
+public class EMABreaker extends SubsystemBase {
+
+    private static class Current {
+        double alpha; // how much of the error we correct per loop
+        double average = 0;
+        double threshold;
+    }
+
+    PowerDistribution pDis = new PowerDistribution();
+
+    private List<Current> filters = new ArrayList<>(); // contains currents with their alphas and thresholds
+
+    public EMABreaker() {
+        for (Map.Entry<Double, Double> entry : BreakerConstants.THRESHOLDS.entrySet()) {
+            double tau = entry.getKey(); // sec
+            double threshold = entry.getValue(); // A
+
+            Current w = new Current(); // create a filter for the threshold
+            w.threshold = threshold;
+            w.alpha = 1 - Math.exp(-Constants.LOOP_TIME / tau); // 1 - e^(-0.02/1) = 0.0198, 1 - e^(-0.02/2) = 0.00995 
+
+            filters.add(w);
+        }
+    }
+
+    @Override
+    public void periodic() {
+        double current = getCurrentFromPowerDistribution();
+        for (Current f : filters) {
+            // new avg = old avg + fractionAlpha * difference
+            f.average += f.alpha * (current - f.average);
+        }
+    }
+
+    public double getCurrentFromPowerDistribution() {
+        return pDis.getTotalCurrent(); // not using .getCurrent() and then an arguement for the port you can get just one port
+    }
+
+    public boolean isOverCurrent() {
+        for (Current f : filters) {
+            if (f.average > f.threshold) {
+                return true; // uh oh
+            }
+        }
+        return false;
+    }
+}