code review changes
[3501/2017steamworks] / src / org / usfirst / frc / team3501 / robot / commands / shooter / RunIndexWheel.java
index 58a59fbdd8e9669a534703caa1d59b9313ff5b8b..6abb095b60a0a5ac74de61627244f479ae2248f6 100644 (file)
@@ -1,5 +1,8 @@
 package org.usfirst.frc.team3501.robot.commands.shooter;
 
+import org.usfirst.frc.team3501.robot.Robot;
+import org.usfirst.frc.team3501.robot.subsystems.Shooter;
+
 import edu.wpi.first.wpilibj.command.Command;
 
 /**
@@ -11,8 +14,8 @@ import edu.wpi.first.wpilibj.command.Command;
  * @author Shaina
  */
 public class RunIndexWheel extends Command {
+  private Shooter shooter = Robot.getShooter();
   private double time;
-  private double motorVal;
 
   /**
    * See JavaDoc comment in class for details
@@ -22,8 +25,8 @@ public class RunIndexWheel extends Command {
    * @param time
    *          in seconds, amount of time to run index wheel motor
    */
-  public RunIndexWheel(double motorVal, double time) {
-    this.motorVal = motorVal;
+  public RunIndexWheel(double time) {
+    requires(shooter);
     this.time = time;
   }
 
@@ -35,22 +38,29 @@ public class RunIndexWheel extends Command {
   // Called repeatedly when this Command is scheduled to run
   @Override
   protected void execute() {
+    double shooterSpeed = shooter.getShooterRPM();
+    double targetShooterSpeed = shooter.getTargetShootingSpeed();
+    double threshold = shooter.getRPMThreshold();
+    if (Math.abs(shooterSpeed - targetShooterSpeed) <= threshold)
+      shooter.runIndexWheel();
   }
 
   // Called once after isFinished returns true
   @Override
   protected void end() {
+    shooter.stopIndexWheel();
   }
 
   // Called when another command which requires one or more of the same
   // subsystems is scheduled to run
   @Override
   protected void interrupted() {
+    end();
   }
 
   @Override
   protected boolean isFinished() {
-    return false;
+    return timeSinceInitialized() >= time;
   }
 
 }