Add Hall Effect Sensor code to test sensor
[3501/2017steamworks] / src / org / usfirst / frc / team3501 / robot / utils / HallEffectSensor.java
diff --git a/src/org/usfirst/frc/team3501/robot/utils/HallEffectSensor.java b/src/org/usfirst/frc/team3501/robot/utils/HallEffectSensor.java
new file mode 100644 (file)
index 0000000..384dc02
--- /dev/null
@@ -0,0 +1,40 @@
+package org.usfirst.frc.team3501.robot.utils;
+
+import edu.wpi.first.wpilibj.Counter;
+
+public class HallEffectSensor {
+  private Counter counter;
+
+  public HallEffectSensor(int port, int bufferLength) {
+    counter = new Counter(port);
+    counter.setSamplesToAverage(bufferLength);
+  }
+
+  /**
+   * Returns rotations per second(buffered) of hall effect sensor counter
+   * 
+   * @return rotations per second of hall effect counter
+   */
+  public double getRPS() {
+    return 1.0 / counter.getPeriod();
+  }
+
+  /**
+   * Get the period of the most recent count.
+   * 
+   * @return period of latest count in seconds
+   */
+  public double getCounterPeriod() {
+    return counter.getPeriod();
+  }
+
+  /**
+   * Returns rotations per minute(buffered) of hall effect sensor counter
+   * 
+   * @return rotations per minute of hall effect sensor
+   */
+  public double getRPM() {
+    return this.getRPS() * 60;
+  }
+
+}