| 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 | * Reverses the intake until the button triggering this command is released |
| 10 | * |
| 11 | * pre-condition: This command must be run by a button in OI with |
| 12 | * button.whileHeld(...). |
| 13 | */ |
| 14 | public class ReverseIntakeContinuous extends Command { |
| 15 | private Intake intake = Robot.getIntake(); |
| 16 | |
| 17 | private double previousMotorValue = 0; |
| 18 | private double targetMotorValue = intake.REVERSE_SPEED; |
| 19 | |
| 20 | public ReverseIntakeContinuous() { |
| 21 | requires(intake); |
| 22 | } |
| 23 | |
| 24 | // Called just before this Command runs the first time |
| 25 | @Override |
| 26 | protected void initialize() { |
| 27 | } |
| 28 | |
| 29 | // Called repeatedly when this Command is scheduled to run |
| 30 | @Override |
| 31 | protected void execute() { |
| 32 | double motorValue = (6 * previousMotorValue + targetMotorValue) / 7; |
| 33 | previousMotorValue = motorValue; |
| 34 | intake.setSpeed(motorValue); |
| 35 | } |
| 36 | |
| 37 | // Make this return true when this Command no longer needs to run execute() |
| 38 | @Override |
| 39 | protected boolean isFinished() { |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | // Called once after isFinished returns true |
| 44 | @Override |
| 45 | protected void end() { |
| 46 | intake.stopIntake(); |
| 47 | } |
| 48 | |
| 49 | // Called when another command which requires one or more of the same |
| 50 | // subsystems is scheduled to run |
| 51 | @Override |
| 52 | protected void interrupted() { |
| 53 | end(); |
| 54 | } |
| 55 | } |