e2c4d3a5 |
1 | package org.usfirst.frc.team3501.robot.commands.intakearm; |
93cba28f |
2 | |
e2c4d3a5 |
3 | import edu.wpi.first.wpilibj.AnalogInput; |
4 | |
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 | */ |
13 | public class Photogate extends AnalogInput { |
14 | |
15 | private double threshold = 1.8; |
53b6c82d |
16 | static boolean ballState; |
e2c4d3a5 |
17 | |
18 | /*** |
19 | * The constructor inputs the channel of the transistor and the threshold |
20 | * value. |
21 | * The threshold is a specific value, representing the outputted voltage of |
22 | * the phototransistor. This value will be somewhere within the range [0, |
23 | * 4095] Find the value by testing and finding an average value for which the |
24 | * ball is present when the output is greater, and absent when the output is |
25 | * less. |
26 | */ |
27 | public Photogate() { |
28 | super(0); |
29 | this.threshold = threshold; |
53b6c82d |
30 | |
e2c4d3a5 |
31 | } |
32 | |
33 | /*** |
34 | * @return whether the ball is present or not |
35 | * USE TO DECIDE WHEN OUTTAKE NEEDS TO HAPPEN FOR BALL TO BE SECURE |
36 | */ |
37 | public boolean isBallPresent() { |
53b6c82d |
38 | if (this.getVoltage() > threshold) { |
39 | ballState = true; |
e2c4d3a5 |
40 | return true; |
53b6c82d |
41 | } else |
42 | ballState = false; |
43 | return false; |
44 | |
45 | } |
e2c4d3a5 |
46 | |
53b6c82d |
47 | public static boolean ballState() { |
48 | return ballState; |
e2c4d3a5 |
49 | } |
50 | |
51 | /*** |
52 | * @param threshold |
53 | * (range [0, 4095]) |
54 | */ |
55 | public void setThreshold(int threshold) { |
56 | this.threshold = threshold; |
57 | } |
58 | } |