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