delete anything to do with pots and motors in IntakeArm and Constants, add the left...
[3501/stronghold-2016] / src / org / usfirst / frc / team3501 / robot / commands / intakearm / MoveIntakeArmToAngle.java
CommitLineData
6bb7f8ac 1package org.usfirst.frc.team3501.robot.commands.intakearm;
b4eeeb65
SO
2
3import org.usfirst.frc.team3501.robot.Robot;
4
5import edu.wpi.first.wpilibj.command.Command;
6
7public class MoveIntakeArmToAngle extends Command {
822569e2
ME
8 private double currentAngle;
9 private double targetAngle;
10 private double targetSpeed;
11 private double calculatedSpeed;
12 private double SENSITIVITY_THRESHOLD = 0.1;
e8dc1f31 13 private double MIN_SPEED = .3;
822569e2
ME
14
15 public MoveIntakeArmToAngle(double angle, double speed) {
16 requires(Robot.intakeArm);
17 targetAngle = angle;
18 targetSpeed = speed;
19
20 }
21
22 @Override
23 protected void initialize() {
24
25 // set the arm speed to the calculated angle
e8dc1f31 26 double speed = getCalculatedSpeed();
822569e2 27
e8dc1f31
ME
28 if (speed < MIN_SPEED && speed > 0)
29 speed = Math.signum(getCalculatedSpeed()) * MIN_SPEED;
30 Robot.intakeArm.setArmSpeed(speed);
822569e2
ME
31 }
32
33 @Override
34 protected void execute() {
35 // set the arm speed to the calculated angle
36 Robot.intakeArm.setArmSpeed(calculatedSpeed);
37 }
38
39 private double getError() {
40 // targetAngle - currentAngle = error
41 return Robot.intakeArm.getArmAngle() - targetAngle;
42 }
43
44 private double getCalculatedSpeed() {
45 // if the arm has to move up -- the speed will be +
46 // if the arm has to move down -- the speed will be -
47
48 return (getError() / targetAngle) * targetSpeed;
49 }
50
51 @Override
52 protected boolean isFinished() {
53 // if the arm's angle is close enough to the target value return true
54 // else return false
55 return (Math.abs(getError()) <= SENSITIVITY_THRESHOLD);
56 }
57
58 @Override
59 protected void end() {
60 Robot.intakeArm.stop();
61 }
62
63 @Override
64 protected void interrupted() {
65 end();
66 }
b4eeeb65
SO
67
68}