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