Edit getAverage() to calculate average over the bufferVals array length
[3501/2017steamworks] / src / org / usfirst / frc / team3501 / robot / subsystems / HallEffectBuffer.java
index 88161568f6a990a7fe32cab210f1b247f22310ca..2e56ed00684f9d2b875d6a80f2e67994cdd46a3b 100644 (file)
@@ -2,12 +2,13 @@ package org.usfirst.frc.team3501.robot.subsystems;
 
 public class HallEffectBuffer {
   int length;
-  int index = 0;
+  int index;
   double[] bufferVals;
 
   public HallEffectBuffer(int length) {
     this.length = length;
     bufferVals = new double[length];
+    index = 0;
   }
 
   public void add(double val) {
@@ -27,6 +28,6 @@ public class HallEffectBuffer {
     for (int i = 0; i < index; i++) {
       total += bufferVals[i];
     }
-    return total / index + 1;
+    return total / bufferVals.length;
   }
 }