268b0048 |
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 | return counter.getPeriod(); |
29 | } |
30 | |
31 | /** |
32 | * Returns rotations per minute(buffered) of hall effect sensor counter |
33 | * |
34 | * @return rotations per minute of hall effect sensor |
35 | */ |
36 | public double getRPM() { |
37 | return this.getRPS() * 60; |
38 | } |
39 | |
40 | } |