| 1 | package org.usfirst.frc.team3501.robot.commands.shooter; |
| 2 | |
| 3 | import org.usfirst.frc.team3501.robot.Constants; |
| 4 | import org.usfirst.frc.team3501.robot.Robot; |
| 5 | import org.usfirst.frc.team3501.robot.subsystems.Shooter; |
| 6 | |
| 7 | import edu.wpi.first.wpilibj.Timer; |
| 8 | import edu.wpi.first.wpilibj.command.Command; |
| 9 | |
| 10 | /** |
| 11 | * This command runs index wheel continuously when OI button managing index |
| 12 | * wheel is pressed. The command will run the index wheel motor until the button |
| 13 | * triggering it is released. |
| 14 | * |
| 15 | * Should only be run from the operator interface. |
| 16 | * |
| 17 | * pre-condition: This command must be run by a button in OI with |
| 18 | * button.whileHeld(...). |
| 19 | * |
| 20 | * @author Shaina |
| 21 | */ |
| 22 | public class RunIndexWheelContinuous extends Command { |
| 23 | private Shooter shooter = Robot.getShooter(); |
| 24 | private Timer t = new Timer(); |
| 25 | |
| 26 | /** |
| 27 | * See JavaDoc comment in class for details |
| 28 | */ |
| 29 | public RunIndexWheelContinuous() { |
| 30 | requires(shooter); |
| 31 | } |
| 32 | |
| 33 | @Override |
| 34 | protected void initialize() { |
| 35 | t.reset(); |
| 36 | } |
| 37 | |
| 38 | @Override |
| 39 | protected void execute() { |
| 40 | if (t.get() % 1 == 0) { |
| 41 | if (Shooter.getShooter().getPistonValue() == Constants.Shooter.LOW_GEAR) { |
| 42 | Shooter.getShooter().setHighGear(); |
| 43 | } else { |
| 44 | Shooter.getShooter().setLowGear(); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | double shooterSpeed = shooter.getShooterRPM(); |
| 49 | double targetShooterSpeed = shooter.getTargetShootingSpeed(); |
| 50 | double threshold = shooter.getRPMThreshold(); |
| 51 | if (Math.abs(shooterSpeed - targetShooterSpeed) <= threshold) |
| 52 | shooter.runIndexWheel(); |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | protected void end() { |
| 57 | shooter.stopIndexWheel(); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | protected void interrupted() { |
| 62 | end(); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | protected boolean isFinished() { |
| 67 | return false; |
| 68 | } |
| 69 | |
| 70 | } |