| 1 | package org.usfirst.frc.team3501.robot.commands.intake; |
| 2 | |
| 3 | import org.usfirst.frc.team3501.robot.Robot; |
| 4 | import org.usfirst.frc.team3501.robot.subsystems.Intake; |
| 5 | |
| 6 | import edu.wpi.first.wpilibj.command.Command; |
| 7 | |
| 8 | /*** |
| 9 | * |
| 10 | * Runs the intake continuously when button is pressed, and when button is not |
| 11 | * pressed does not run. |
| 12 | * |
| 13 | * Intended to be run inside a .whileHeld() call on a button in OI |
| 14 | * |
| 15 | * @author Meeta |
| 16 | * |
| 17 | */ |
| 18 | public class RunIntakeContinuous extends Command { |
| 19 | private Intake intake = Robot.getIntake(); |
| 20 | |
| 21 | private double previousMotorValue = 0; |
| 22 | private double targetMotorValue = intake.INTAKE_SPEED; |
| 23 | |
| 24 | public RunIntakeContinuous() { |
| 25 | requires(intake); |
| 26 | } |
| 27 | |
| 28 | @Override |
| 29 | protected boolean isFinished() { |
| 30 | return false; |
| 31 | } |
| 32 | |
| 33 | // Called just before this Command runs the first time |
| 34 | @Override |
| 35 | protected void initialize() { |
| 36 | } |
| 37 | |
| 38 | // Called repeatedly when this Command is scheduled to run |
| 39 | @Override |
| 40 | protected void execute() { |
| 41 | double motorValue = (6 * previousMotorValue + targetMotorValue) / 7; |
| 42 | previousMotorValue = motorValue; |
| 43 | intake.setSpeed(motorValue); |
| 44 | } |
| 45 | |
| 46 | // Called once after isFinished returns true |
| 47 | @Override |
| 48 | protected void end() { |
| 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 | |
| 59 | } |