Change getAverage() method Shaina/shooter
authorshainachen <shaina.sierra@gmail.com>
Fri, 3 Feb 2017 05:15:50 +0000 (21:15 -0800)
committershainachen <shaina.sierra@gmail.com>
Fri, 3 Feb 2017 05:15:50 +0000 (21:15 -0800)
src/org/usfirst/frc/team3501/robot/subsystems/HallEffectBuffer.java

index 8d420dd3955c7a8c8fe53f92baac36dfcb76aee3..59cc1017c004ca1d362cc17c4418fea7d90e344f 100644 (file)
@@ -3,7 +3,7 @@ package org.usfirst.frc.team3501.robot.subsystems;
 /**
  * This command calculates the average of a set of rpm from the HallEffectSensor
  * class
- * 
+ *
  * @author shaina
  *
  */
@@ -32,9 +32,14 @@ public class HallEffectBuffer {
    */
   public double getAverage() {
     double total = 0;
+    int zeros = 0;
     for (int i = 0; i < index; i++) {
+      if (bufferVals[i] == 0)
+        zeros++;
       total += bufferVals[i];
     }
+    if (zeros != bufferVals.length)
+      return total / (bufferVals.length - zeros);
     return total / bufferVals.length;
   }
 }