Initialize photogate in shooter subsystem
[3501/stronghold-2016] / src / org / usfirst / frc / team3501 / robot / sensors / Photogate.java
CommitLineData
7670b3f4 1package org.usfirst.frc.team3501.robot.sensors;
23e5c98d 2
3import edu.wpi.first.wpilibj.AnalogInput;
4
23e5c98d 5/***
6 * The photogate is a pair of IR LED and phototransistor sensor that uses a
7 * reflective method to sense the presence of the boulder within the robot's
8 * shooting chamber. This class specifically checks for the ball's presence
9 * using a threshold of voltages outputted from the phototransistor.
10 *
11 * @author niyatisriram
12 */
13public class Photogate extends AnalogInput {
14
dc56d4f4 15 private double threshold = 1.8;
23e5c98d 16
17 /***
18 * The constructor inputs the channel of the transistor and the threshold
19 * value.
20 * The threshold is a specific value, representing the outputted voltage of
21 * the phototransistor. This value will be somewhere within the range [0,
22 * 4095] Find the value by testing and finding an average value for which the
23 * ball is present when the output is greater, and absent when the output is
24 * less.
25 */
26 public Photogate(int channel, int threshold) {
27 super(channel);
28 this.threshold = threshold;
29 }
30
31 /***
32 * @return whether the ball is present or not
33 */
34 public boolean isBallPresent() {
dc56d4f4 35 if (this.getVoltage() > threshold)
23e5c98d 36 return true;
37 else
38 return false;
39
40 }
41
42 /***
43 * @param threshold
49b6d711 44 * (range [0, 4095])
23e5c98d 45 */
46 public void setThreshold(int threshold) {
47 this.threshold = threshold;
48 }
49}