From e2c4d3a5b10fa513a4e4e654a756f2e84eda02d0 Mon Sep 17 00:00:00 2001 From: niyatisriram Date: Sat, 19 Mar 2016 18:20:12 -0700 Subject: [PATCH] more photogate incorporation edits --- src/org/usfirst/frc/team3501/robot/Robot.java | 5 +- .../robot/commands/intakearm/Photogate.java | 49 +++++++++++++++++++ .../robot/commands/intakearm/RunIntake.java | 2 + 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/org/usfirst/frc/team3501/robot/Robot.java b/src/org/usfirst/frc/team3501/robot/Robot.java index 5bc3c012..30926c7a 100644 --- a/src/org/usfirst/frc/team3501/robot/Robot.java +++ b/src/org/usfirst/frc/team3501/robot/Robot.java @@ -4,6 +4,7 @@ import org.usfirst.frc.team3501.robot.Constants.Auton; import org.usfirst.frc.team3501.robot.Constants.Defense; import org.usfirst.frc.team3501.robot.commands.auton.ChooseStrategy; import org.usfirst.frc.team3501.robot.commands.driving.SetLowGear; +import org.usfirst.frc.team3501.robot.commands.intakearm.Photogate; import org.usfirst.frc.team3501.robot.subsystems.DriveTrain; import org.usfirst.frc.team3501.robot.subsystems.IntakeArm; import org.usfirst.frc.team3501.robot.subsystems.Shooter; @@ -18,7 +19,7 @@ public class Robot extends IterativeRobot { public static DriveTrain driveTrain; public static Shooter shooter; public static IntakeArm intakeArm; - // public static Photogate photogate; + public static Photogate photogate; // Sendable Choosers send a drop down menu to the Smart Dashboard. SendableChooser positionChooser; @@ -32,7 +33,7 @@ public class Robot extends IterativeRobot { intakeArm = new IntakeArm(); oi = new OI(); - // photogate = new Photogate(); + photogate = new Photogate(); initializeSendableChoosers(); addPositionChooserOptions(); diff --git a/src/org/usfirst/frc/team3501/robot/commands/intakearm/Photogate.java b/src/org/usfirst/frc/team3501/robot/commands/intakearm/Photogate.java index 8b137891..9e6c2e8b 100644 --- a/src/org/usfirst/frc/team3501/robot/commands/intakearm/Photogate.java +++ b/src/org/usfirst/frc/team3501/robot/commands/intakearm/Photogate.java @@ -1 +1,50 @@ +package org.usfirst.frc.team3501.robot.commands.intakearm; +import edu.wpi.first.wpilibj.AnalogInput; + +/*** + * 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 = 1.8; + + /*** + * 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() { + super(0); + this.threshold = threshold; + } + + /*** + * @return whether the ball is present or not + * USE TO DECIDE WHEN OUTTAKE NEEDS TO HAPPEN FOR BALL TO BE SECURE + */ + public boolean isBallPresent() { + if (this.getVoltage() > threshold) + return true; + else + return false; + + } + + /*** + * @param threshold + * (range [0, 4095]) + */ + public void setThreshold(int threshold) { + this.threshold = threshold; + } +} diff --git a/src/org/usfirst/frc/team3501/robot/commands/intakearm/RunIntake.java b/src/org/usfirst/frc/team3501/robot/commands/intakearm/RunIntake.java index 000c68f9..7625d6ab 100644 --- a/src/org/usfirst/frc/team3501/robot/commands/intakearm/RunIntake.java +++ b/src/org/usfirst/frc/team3501/robot/commands/intakearm/RunIntake.java @@ -25,6 +25,8 @@ public class RunIntake extends Command { @Override protected void execute() { + // if Photogate.() { + Robot.intakeArm.outputBall(); } @Override -- 2.30.2