]> git.taranathan.com Git - FRC2026.git/commitdiff
not optimized
authorWesley28w <wesleycwong@gmail.com>
Sat, 18 Apr 2026 00:19:34 +0000 (17:19 -0700)
committerWesley28w <wesleycwong@gmail.com>
Sat, 18 Apr 2026 00:19:34 +0000 (17:19 -0700)
src/main/java/frc/robot/subsystems/Breaker/Breaker.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
new file mode 100644 (file)
index 0000000..7f7af64
--- /dev/null
@@ -0,0 +1,37 @@
+package frc.robot.subsystems.Breaker;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import edu.wpi.first.wpilibj.PowerDistribution;
+import edu.wpi.first.wpilibj2.command.SubsystemBase;
+
+public class Breaker extends SubsystemBase {
+    PowerDistribution pDis = new PowerDistribution();
+    List<Double> currents = new ArrayList<>();
+
+    public Breaker() {
+        currents.clear();
+    }
+    
+    @Override
+    public void periodic() {
+        currents.add(getCurrentFromPowerDistribution());
+    }
+
+    public double average(double secondsBackward) {
+        // there is a log for every 20ms and thus 50 indexes for each second
+        int totalIndexes = (int) secondsBackward * 50;
+        List<Double> trimmedCurrents = currents.subList(currents.size()-totalIndexes, currents.size());
+        double sum = 0;
+        for (double index : trimmedCurrents) {
+            sum += index;
+        }
+        
+        return sum/trimmedCurrents.size();
+    }
+
+    public double getCurrentFromPowerDistribution() {
+        return pDis.getTotalCurrent(); // not using .getCurrent() and then an arguement for the port you can get just one port
+    }
+}