modify RunFlyWheel and RunFlyWheelContinuous commands
[3501/2017steamworks] / src / org / usfirst / frc / team3501 / robot / commands / shooter / RunFlyWheelContinuous.java
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 import org.usfirst.frc.team3501.robot.utils.PIDController;
6
7 import edu.wpi.first.wpilibj.command.Command;
8
9 /**
10 * This command runs the fly wheel continuously when OI button managing fly
11 * wheel is pressed. The command will run the fly wheel motor until the button
12 * triggering it is released.
13 *
14 * Should only be run from the operator interface.
15 *
16 * pre-condition: This command must be run by a button in OI, with
17 * button.whileHeld(...).
18 *
19 * @author Shaina
20 */
21 public class RunFlyWheelContinuous extends Command {
22 private Shooter shooter = Robot.getShooter();
23
24 private PIDController wheelController;
25 private double wheelP;
26 private double wheelI;
27 private double wheelD;
28 private double target;
29
30 public RunFlyWheelContinuous() {
31 // Use requires() here to declare subsystem dependencies
32 // eg. requires(chassis);
33 requires(shooter);
34
35 this.wheelP = this.shooter.wheelP;
36 this.wheelI = this.shooter.wheelI;
37 this.wheelD = this.shooter.wheelD;
38 this.wheelController = new PIDController(this.wheelP, this.wheelI,
39 this.wheelD);
40 this.wheelController.setDoneRange(0.5);
41 this.wheelController.setMaxOutput(1.0);
42 this.wheelController.setMinDoneCycles(3);
43 this.target = this.shooter.CURRENT_SHOOTING_SPEED;
44 }
45
46 // Called just before this Command runs the first time
47 protected void initialize() {
48 this.wheelController.setSetPoint(this.target);
49 }
50
51 // Called repeatedly when this Command is scheduled to run
52 protected void execute() {
53 double shooterSpeed = this.wheelController
54 .calcPID(this.shooter.getShooterSpeed());
55
56 this.shooter.setFlyWheelMotorVal(shooterSpeed);
57 }
58
59 // Make this return true when this Command no longer needs to run execute()
60 protected boolean isFinished() {
61 return false;
62 }
63
64 // Called once after isFinished returns true
65 protected void end() {
66 this.shooter.stopFlyWheel();
67 }
68
69 // Called when another command which requires one or more of the same
70 // subsystems is scheduled to run
71 protected void interrupted() {
72 end();
73 }
74 }