| 1 | package org.usfirst.frc.team3501.robot.commands.intake; |
| 2 | |
| 3 | import org.usfirst.frc.team3501.robot.Robot; |
| 4 | |
| 5 | import edu.wpi.first.wpilibj.Timer; |
| 6 | import edu.wpi.first.wpilibj.command.Command; |
| 7 | |
| 8 | /** |
| 9 | * Reverses the intake roller for a specified amount of time in seconds |
| 10 | * |
| 11 | * parameters: time to run intake |
| 12 | */ |
| 13 | public class ReverseIntake extends Command { |
| 14 | private double timeToMove; |
| 15 | public Timer timer; |
| 16 | |
| 17 | public ReverseIntake(double timeToMove) { |
| 18 | requires(Robot.getIntake()); |
| 19 | timer = new Timer(); |
| 20 | this.timeToMove = timeToMove; |
| 21 | } |
| 22 | |
| 23 | // Called just before this Command runs the first time |
| 24 | @Override |
| 25 | protected void initialize() { |
| 26 | timer.start(); |
| 27 | } |
| 28 | |
| 29 | // Called repeatedly when this Command is scheduled to run |
| 30 | @Override |
| 31 | protected void execute() { |
| 32 | Robot.getIntake().runReverseIntake(); |
| 33 | } |
| 34 | |
| 35 | // Make this return true when this Command no longer needs to run execute() |
| 36 | @Override |
| 37 | protected boolean isFinished() { |
| 38 | return timer.get() >= timeToMove; |
| 39 | } |
| 40 | |
| 41 | // Called once after isFinished returns true |
| 42 | @Override |
| 43 | protected void end() { |
| 44 | Robot.getIntake().stopIntake(); |
| 45 | } |
| 46 | |
| 47 | // Called when another command which requires one or more of the same |
| 48 | // subsystems is scheduled to run |
| 49 | @Override |
| 50 | protected void interrupted() { |
| 51 | end(); |
| 52 | } |
| 53 | } |