X-Git-Url: http://challenge-bot.com/repos/?a=blobdiff_plain;ds=sidebyside;f=src%2Forg%2Fusfirst%2Ffrc%2Fteam3501%2Frobot%2Futils%2FHallEffectSensor.java;fp=src%2Forg%2Fusfirst%2Ffrc%2Fteam3501%2Frobot%2Futils%2FHallEffectSensor.java;h=384dc025e936f22dceab27ee00b70388dabb7799;hb=268b004857f2e73159cccfc18edeff7ad33dfe78;hp=0000000000000000000000000000000000000000;hpb=9e91dcb88316fdb4a1915c9d164b5e753a1ba89d;p=3501%2F2017steamworks 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 index 0000000..384dc02 --- /dev/null +++ b/src/org/usfirst/frc/team3501/robot/utils/HallEffectSensor.java @@ -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; + } + +}