--- /dev/null
+package org.usfirst.frc.team3501.robot.subsystems;
+
+public class HallEffectBuffer {
+ int length;
+ int index = 0;
+ double[] bufferVals;
+
+ public HallEffectBuffer(int length) {
+ this.length = length;
+ bufferVals = new double[length];
+ }
+
+ public void add(double val) {
+ bufferVals[index++] = val;
+ if (index >= bufferVals.length) {
+ index = 0;
+ }
+ }
+
+ public double getAverage() {
+ double total = 0;
+ for (int i = 0; i < bufferVals.length; i++) {
+ total += bufferVals[i];
+ }
+ return total / bufferVals.length;
+ }
+}
--- /dev/null
+package org.usfirst.frc.team3501.robot.subsystems;
+
+import edu.wpi.first.wpilibj.Counter;
+
+public class HallEffectSensor {
+ Counter counter;
+ HallEffectBuffer speeds;
+
+ public HallEffectSensor(Counter counter, int bufferLength) {
+ this.counter = counter;
+ speeds = new HallEffectBuffer(bufferLength);
+ }
+
+ public double getBufferedSpeed() {
+ speeds.add(this.getRPM());
+ return speeds.getAverage();
+ }
+
+ public double getRPS() {
+ return 1 / counter.getPeriod();
+ }
+
+ public double getRPM() {
+ return this.getRPS() * 60;
+ }
+
+}