Fill out MoveIntakeArmToBallIntakeHeight command
authorShivani Oghanta <shivani.oghanta@gmail.com>
Sun, 7 Feb 2016 01:44:23 +0000 (17:44 -0800)
committerCindy Zhang <cindyzyx9@gmail.com>
Sat, 13 Feb 2016 19:52:19 +0000 (11:52 -0800)
src/org/usfirst/frc/team3501/robot/commands/MoveIntakeArmToBallIntakeHeight.java

index 805bd78694a9436931ceaa6675522c1e92af340e..deda77b4e5b287587c9cf15efaa0809577a232cf 100644 (file)
@@ -1,5 +1,56 @@
 package org.usfirst.frc.team3501.robot.commands;
 
-public class MoveIntakeArmToBallIntakeHeight {
+import org.usfirst.frc.team3501.robot.Robot;
 
+import edu.wpi.first.wpilibj.command.Command;
+
+public class MoveIntakeArmToBallIntakeHeight extends Command {
+       private double targetHeight;
+       private double currentHeight;
+       private double targetSpeed;
+       private double SENSITIVITY_THRESHOLD = 0.1;
+       private double NO_MOVEMENT_SPEED = 0;
+
+       public MoveIntakeArmToBallIntakeHeight(double height, double speed) {
+               requires(Robot.intakeArm);
+               targetHeight = height;
+               targetSpeed = speed;
+       }
+
+       @Override
+       protected void initialize() {
+               currentHeight = Robot.intakeArm.getArmAngle();
+               double difference = targetHeight - currentHeight;
+               if (difference > 0) {
+                       Robot.intakeArm.setArmVoltage(targetSpeed);
+               } else {
+                       Robot.intakeArm.setArmVoltage(-targetSpeed);
+               }
+       }
+
+       @Override
+       protected void execute() {
+
+       }
+
+       @Override
+       protected boolean isFinished() {
+               currentHeight = Robot.intakeArm.getArmAngle();
+               double distance = Math.abs(currentHeight - targetHeight);
+               if (distance <= SENSITIVITY_THRESHOLD) {
+                       return true;
+               } else {
+                       return false;
+               }
+
+       }
+
+       @Override
+       protected void end() {
+               Robot.intakeArm.setArmVoltage(NO_MOVEMENT_SPEED);
+       }
+
+       @Override
+       protected void interrupted() {
+       }
 }