Add object photogate to robot.java and add a todo comment to photogate subsystem.
authorniyatisriram <niyatisriram@gmail.com>
Wed, 10 Feb 2016 03:30:27 +0000 (19:30 -0800)
committerLauren Meier <meier.lauren@gmail.com>
Sat, 13 Feb 2016 22:39:37 +0000 (14:39 -0800)
src/org/usfirst/frc/team3501/robot/Robot.java
src/org/usfirst/frc/team3501/robot/subsystems/Photogate.java [new file with mode: 0644]

index 0aad2a670a5b60c7e76d0fd051b78be9afdb6e38..08e2b283d288926c946cab280a4e986030605c03 100644 (file)
@@ -4,6 +4,7 @@ import org.usfirst.frc.team3501.robot.Constants.Defense;
 import org.usfirst.frc.team3501.robot.subsystems.DefenseArm;
 import org.usfirst.frc.team3501.robot.subsystems.DriveTrain;
 import org.usfirst.frc.team3501.robot.subsystems.IntakeArm;
+import org.usfirst.frc.team3501.robot.subsystems.Photogate;
 import org.usfirst.frc.team3501.robot.subsystems.Scaler;
 import org.usfirst.frc.team3501.robot.subsystems.Shooter;
 
@@ -23,6 +24,8 @@ public class Robot extends IterativeRobot {
   public static IntakeArm intakeArm;
   public static DefenseArm defenseArm;
 
+  public static Photogate photogate;
+
   // Sendable Choosers send a drop down menu to the Smart Dashboard.
   SendableChooser positionChooser;
   SendableChooser positionOneDefense, positionTwoDefense, positionThreeDefense,
diff --git a/src/org/usfirst/frc/team3501/robot/subsystems/Photogate.java b/src/org/usfirst/frc/team3501/robot/subsystems/Photogate.java
new file mode 100644 (file)
index 0000000..33f7b15
--- /dev/null
@@ -0,0 +1,52 @@
+package org.usfirst.frc.team3501.robot.subsystems;
+
+import edu.wpi.first.wpilibj.AnalogInput;
+
+// TODO: Change certain reactions based on testing, ie what value(s) return true
+// and what value(s) return false.
+
+/***
+ * The photogate is a pair of IR LED and phototransistor sensor that uses a
+ * reflective method to sense the presence of the boulder within the robot's
+ * shooting chamber. This class specifically checks for the ball's presence
+ * using a threshold of voltages outputted from the phototransistor.
+ *
+ * @author niyatisriram
+ */
+public class Photogate extends AnalogInput {
+
+  private double threshold;
+
+  /***
+   * The constructor inputs the channel of the transistor and the threshold
+   * value.
+   * The threshold is a specific value, representing the outputted voltage of
+   * the phototransistor. This value will be somewhere within the range [0,
+   * 4095] Find the value by testing and finding an average value for which the
+   * ball is present when the output is greater, and absent when the output is
+   * less.
+   */
+  public Photogate(int channel, int threshold) {
+    super(channel);
+    this.threshold = threshold;
+  }
+
+  /***
+   * @return whether the ball is present or not
+   */
+  public boolean isBallPresent() {
+    if (this.getValue() > threshold)
+      return true;
+    else
+      return false;
+
+  }
+
+  /***
+   * @param threshold
+   *          (range [0, 4095]
+   */
+  public void setThreshold(int threshold) {
+    this.threshold = threshold;
+  }
+}