| 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 | * |
| 10 | * Starts running the intake for a specific period of time that the user inputs. |
| 11 | * |
| 12 | * @author Meeta |
| 13 | */ |
| 14 | public class RunIntake extends Command { |
| 15 | private double timeToMove; |
| 16 | public Timer timer; |
| 17 | |
| 18 | /** |
| 19 | * |
| 20 | * @param timeToMove |
| 21 | */ |
| 22 | public RunIntake(double timeToMove) { |
| 23 | requires(Robot.getIntake()); |
| 24 | timer = new Timer(); |
| 25 | this.timeToMove = timeToMove; |
| 26 | } |
| 27 | |
| 28 | @Override |
| 29 | protected boolean isFinished() { |
| 30 | return timer.get() >= timeToMove; |
| 31 | } |
| 32 | |
| 33 | // Called just before this Command runs the first time |
| 34 | @Override |
| 35 | protected void initialize() { |
| 36 | timer.start(); |
| 37 | } |
| 38 | |
| 39 | // Called repeatedly when this Command is scheduled to run |
| 40 | @Override |
| 41 | protected void execute() { |
| 42 | Robot.getIntake().runIntake(); |
| 43 | } |
| 44 | |
| 45 | // Called once after isFinished returns true |
| 46 | @Override |
| 47 | protected void end() { |
| 48 | timer.stop(); |
| 49 | Robot.getIntake().stopIntake(); |
| 50 | } |
| 51 | |
| 52 | // Called when another command which requires one or more of the same |
| 53 | // subsystems is scheduled to run |
| 54 | @Override |
| 55 | protected void interrupted() { |
| 56 | end(); |
| 57 | } |
| 58 | } |