make code for pid fly wheel control
[3501/2017steamworks] / src / org / usfirst / frc / team3501 / robot / commands / shooter / StartUpFlyWheel.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 *
11 */
12 public class StartUpFlyWheel extends Command {
13 private Shooter shooter = Robot.getShooter();
14 private double maxTimeOut;
15
16 private PIDController wheelController;
17 private double wheelP;
18 private double wheelI;
19 private double wheelD;
20 private double motorVal;
21 private double target;
22
23 public StartUpFlyWheel(double speed, double maxTimeOut) {
24 // Use requires() here to declare subsystem dependencies
25 // eg. requires(chassis);
26 requires(shooter);
27
28 this.wheelP = this.shooter.wheelP;
29 this.wheelI = this.shooter.wheelI;
30 this.wheelD = this.shooter.wheelD;
31 this.wheelController = new PIDController(this.wheelP, this.wheelI,
32 this.wheelD);
33 this.wheelController.setDoneRange(0.5);
34 this.wheelController.setMaxOutput(1.0);
35 this.wheelController.setMinDoneCycles(3);
36 this.target = speed;
37 }
38
39 // Called just before this Command runs the first time
40 protected void initialize() {
41 this.wheelController.setSetPoint(this.target);
42 }
43
44 // Called repeatedly when this Command is scheduled to run
45 protected void execute() {
46 double shooterSpeed = this.wheelController
47 .calcPID(this.shooter.getShooterSpeed());
48
49 this.shooter.setFlyWheelMotorVal(shooterSpeed);
50 }
51
52 // Make this return true when this Command no longer needs to run execute()
53 protected boolean isFinished() {
54 boolean isDone = this.wheelController.isDone();
55 if (timeSinceInitialized() >= maxTimeOut || isDone) {
56 System.out.println("time: " + timeSinceInitialized());
57 return true;
58 }
59 return false;
60 }
61
62 // Called once after isFinished returns true
63 protected void end() {
64 this.shooter.stopFlyWheel();
65 }
66
67 // Called when another command which requires one or more of the same
68 // subsystems is scheduled to run
69 protected void interrupted() {
70 end();
71 }
72 }