add precondition and Timeout to Expel and Intake commands
[3501/stronghold-2016] / src / org / usfirst / frc / team3501 / robot / commands / IntakeBall.java
index c90a08017d5bf010855c45de20aa0f3ced0989a9..87902d3925cdd1c00269f55db5aa4145ffa8148d 100644 (file)
@@ -8,7 +8,8 @@ import edu.wpi.first.wpilibj.command.Command;
  * This command will take a boulder into the robot if there is not a boulder
  * present inside already.
  *
- * pre-condition: A boulder is not present inside the robot.
+ * pre-condition: Intake arm must be at correct height and a boulder is not
+ * present inside the robot.
  *
  * post-condition: A boulder is taken in from the field outside of the robot
  * into the robot.
@@ -18,6 +19,7 @@ import edu.wpi.first.wpilibj.command.Command;
  */
 
 public class IntakeBall extends Command {
+  private final int TIMEOUT_AMOUNT = 5;
 
   public IntakeBall() {
     requires(Robot.intakeArm);
@@ -25,6 +27,7 @@ public class IntakeBall extends Command {
 
   @Override
   protected void initialize() {
+    this.setTimeout(TIMEOUT_AMOUNT);
     if (!Robot.photogate.isBallPresent())
       Robot.intakeArm.intakeBall();
 
@@ -37,7 +40,7 @@ public class IntakeBall extends Command {
 
   @Override
   protected boolean isFinished() {
-    return Robot.photogate.isBallPresent();
+    return (this.isTimedOut() || Robot.photogate.isBallPresent());
   }
 
   @Override