Add code for testing hall effect
[3501/2017steamworks] / src / org / usfirst / frc / team3501 / robot / utils / HallEffectSensor.java
1 package org.usfirst.frc.team3501.robot.utils;
2
3 import edu.wpi.first.wpilibj.Counter;
4
5 public class HallEffectSensor {
6 private Counter counter;
7
8 public HallEffectSensor(int port, int bufferLength) {
9 counter = new Counter(port);
10 counter.setSamplesToAverage(bufferLength);
11 }
12
13 /**
14 * Returns rotations per second(buffered) of hall effect sensor counter
15 *
16 * @return rotations per second of hall effect counter
17 */
18 public double getRPS() {
19 return 1.0 / counter.getPeriod();
20 }
21
22 /**
23 * Get the period of the most recent count.
24 *
25 * @return period of latest count in seconds
26 */
27 public double getCounterPeriod() {
28 System.out.println("Counter count: " + counter.get());
29 return counter.getPeriod();
30 }
31
32 /**
33 * Returns rotations per minute(buffered) of hall effect sensor counter
34 *
35 * @return rotations per minute of hall effect sensor
36 */
37 public double getRPM() {
38 return this.getRPS() * 60;
39 }
40
41 }