Commit | Line | Data |
---|---|---|
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. | |
f675bae4 | 10 | * |
e2c4d3a5 | 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 | |
f675bae4 HD |
20 | * value. The threshold is a specific value, representing the outputted |
21 | * voltage of the phototransistor. This value will be somewhere within the | |
22 | * range [0, 4095] Find the value by testing and finding an average value for | |
23 | * which the ball is present when the output is greater, and absent when the | |
24 | * output is less. | |
e2c4d3a5 | 25 | */ |
26 | public Photogate() { | |
27 | super(0); | |
e2c4d3a5 | 28 | } |
29 | ||
30 | /*** | |
f675bae4 HD |
31 | * @return whether the ball is present or not USE TO DECIDE WHEN OUTTAKE NEEDS |
32 | * TO HAPPEN FOR BALL TO BE SECURE | |
e2c4d3a5 | 33 | */ |
34 | public boolean isBallPresent() { | |
53b6c82d | 35 | if (this.getVoltage() > threshold) { |
36 | ballState = true; | |
e2c4d3a5 | 37 | return true; |
53b6c82d | 38 | } else |
39 | ballState = false; | |
40 | return false; | |
41 | ||
42 | } | |
e2c4d3a5 | 43 | |
53b6c82d | 44 | public static boolean ballState() { |
45 | return ballState; | |
e2c4d3a5 | 46 | } |
47 | ||
48 | /*** | |
49 | * @param threshold | |
50 | * (range [0, 4095]) | |
51 | */ | |
52 | public void setThreshold(int threshold) { | |
53 | this.threshold = threshold; | |
54 | } | |
55 | } |