|
12 | 12 | /** |
13 | 13 | * |
14 | 14 | */ |
15 | | -public class AutoLift extends Command implements PIDOutput{ |
| 15 | +public class AutoLift extends Command implements PIDOutput { |
16 | 16 | /** |
17 | | - * All distances are measured from bottom of cube and + 3 inches for wiggle room for dropping cubes |
18 | | - * Also, actual distances are divided by 3 because according to cad, the lift will have a 1:3 ratio from winch |
19 | | - * to actual height. |
| 17 | + * All distances are measured from bottom of cube and + 3 inches for wiggle room |
| 18 | + * for dropping cubes Also, actual distances are divided by 3 because according |
| 19 | + * to cad, the lift will have a 1:3 ratio from winch to actual height. |
20 | 20 | */ |
21 | | - |
22 | | - /** |
23 | | - * Distance to switch |
24 | | - * 18.75 inches in starting position (this measurement is the fence that surrounds the switch) |
25 | | - * 21.75 / 3 for ratio = 7.25 |
26 | | - */ |
27 | | - private final double SWITCH_DIST = 7.25; |
28 | | - /** |
29 | | - * Distance to scale |
30 | | - * 5 feet starting |
31 | | - * 63 / 3 = 21 |
32 | | - */ |
33 | | - private final double SCALE_DIST = 21; |
34 | | - /** |
35 | | - * Distance to bar |
36 | | - * 87 / 3 = 29 |
37 | | - * 7 feet starting; bar distance should be changed because I'm not aware how climber mech will be positioned |
38 | | - */ |
39 | | - private final double BAR_DIST = 29; |
| 21 | + |
| 22 | + private final int NUM_STAGES; |
| 23 | + private final double WIGGLE_ROOM; |
| 24 | + private final double SWITCH_DIST; |
| 25 | + private final double SCALE_DIST; |
| 26 | + private final double BAR_DIST; |
| 27 | + |
40 | 28 | private double desiredDist = 0; |
41 | 29 | private double currDist; |
42 | 30 | private LiftInterface lift; |
43 | 31 | private Position desiredPos; |
44 | | - |
| 32 | + |
45 | 33 | private PIDController liftController; |
46 | 34 |
|
47 | | - public AutoLift(Position stage, LiftInterface lift) { |
48 | | - this.lift = lift; |
49 | | - requires(Robot.lift); |
50 | | - currDist = lift.getHeight(); |
51 | | - switch(stage) { |
52 | | - case GROUND: |
53 | | - desiredDist = -currDist; |
54 | | - break; |
55 | | - case SWITCH: |
56 | | - desiredDist = SWITCH_DIST - currDist; |
57 | | - break; |
58 | | - case SCALE: |
59 | | - desiredDist = SCALE_DIST - currDist; |
60 | | - break; |
61 | | - case BAR: |
62 | | - desiredDist = BAR_DIST - currDist; |
63 | | - break; |
64 | | - } |
65 | | - |
66 | | - liftController = new PIDController(Robot.getConst("LiftkP", 1), Robot.getConst("LiftkI", 0), |
67 | | - Robot.getConst("LiftkD", 0),RobotMap.liftEnc, this); |
68 | | - |
69 | | - desiredPos = stage; |
70 | | - } |
71 | | - |
72 | | - // Called just before this Command runs the first time |
73 | | - protected void initialize() { |
| 35 | + public AutoLift(Position stage, LiftInterface lift) { |
| 36 | + this.lift = lift; |
| 37 | + requires(Robot.lift); |
| 38 | + |
| 39 | + currDist = lift.getHeight(); |
| 40 | + |
| 41 | + // calculate constant measurements |
| 42 | + |
| 43 | + NUM_STAGES = lift.getNumStages(); |
| 44 | + WIGGLE_ROOM = lift.getWiggleRoom(); |
| 45 | + // distance to switch 18.75 inches in starting position |
| 46 | + SWITCH_DIST = (18.75 + WIGGLE_ROOM) / NUM_STAGES; |
| 47 | + // distance to scale 5 feet starting 63 / 3 = 21 |
| 48 | + SCALE_DIST = (60.0 + WIGGLE_ROOM) / NUM_STAGES; |
| 49 | + // 7 feet starting; bar distance should be changed because I'm not aware how |
| 50 | + // climber mech will be positioned |
| 51 | + BAR_DIST = (84.0 + WIGGLE_ROOM) / NUM_STAGES; |
| 52 | + |
| 53 | + switch (stage) { |
| 54 | + case GROUND: |
| 55 | + desiredDist = -currDist; |
| 56 | + break; |
| 57 | + case SWITCH: |
| 58 | + desiredDist = SWITCH_DIST - currDist; |
| 59 | + break; |
| 60 | + case SCALE: |
| 61 | + desiredDist = SCALE_DIST - currDist; |
| 62 | + break; |
| 63 | + case BAR: |
| 64 | + desiredDist = BAR_DIST - currDist; |
| 65 | + break; |
| 66 | + } |
| 67 | + |
| 68 | + liftController = new PIDController(Robot.getConst("LiftkP", 1), Robot.getConst("LiftkI", 0), |
| 69 | + Robot.getConst("LiftkD", 0), RobotMap.liftEnc, this); |
| 70 | + |
| 71 | + desiredPos = stage; |
| 72 | + } |
| 73 | + |
| 74 | + // Called just before this Command runs the first time |
| 75 | + protected void initialize() { |
74 | 76 | // input is in inches |
75 | | - //liftController.setInputRange(-Robot.getConst("Max High Speed", 204), Robot.getConst("Max High Speed", 204)); |
| 77 | + // liftController.setInputRange(-Robot.getConst("Max High Speed", 204), |
| 78 | + // Robot.getConst("Max High Speed", 204)); |
76 | 79 | // output in "motor units" (arcade and tank only accept values [-1, 1] |
77 | 80 | liftController.setOutputRange(-1.0, 1.0); |
78 | 81 | liftController.setContinuous(false); |
79 | | - //liftController.setAbsoluteTolerance(Robot.getConst("MoveTolerance", 2)); |
| 82 | + // liftController.setAbsoluteTolerance(Robot.getConst("MoveTolerance", 2)); |
80 | 83 | liftController.setSetpoint(desiredDist); |
81 | 84 | liftController.enable(); |
82 | | - } |
83 | | - |
84 | | - // Called repeatedly when this Command is scheduled to run |
85 | | - protected void execute() { |
86 | | - } |
87 | | - |
88 | | - // Make this return true when this Command no longer needs to run execute() |
89 | | - protected boolean isFinished() { |
90 | | - if(liftController.onTarget()) { |
91 | | - lift.setCurrPosition(desiredPos); |
92 | | - return true; |
93 | | - } |
94 | | - return false; |
95 | | - } |
96 | | - |
97 | | - // Called once after isFinished returns true |
98 | | - protected void end() { |
99 | | - liftController.disable(); |
100 | | - liftController.free(); |
101 | | - } |
102 | | - |
103 | | - // Called when another command which requires one or more of the same |
104 | | - // subsystems is scheduled to run |
105 | | - protected void interrupted() { |
106 | | - end(); |
107 | | - } |
108 | | - |
109 | | - @Override |
| 85 | + } |
| 86 | + |
| 87 | + // Called repeatedly when this Command is scheduled to run |
| 88 | + protected void execute() { |
| 89 | + } |
| 90 | + |
| 91 | + // Make this return true when this Command no longer needs to run execute() |
| 92 | + protected boolean isFinished() { |
| 93 | + if (liftController.onTarget()) { |
| 94 | + lift.setCurrPosition(desiredPos); |
| 95 | + return true; |
| 96 | + } |
| 97 | + return false; |
| 98 | + } |
| 99 | + |
| 100 | + // Called once after isFinished returns true |
| 101 | + protected void end() { |
| 102 | + liftController.disable(); |
| 103 | + liftController.free(); |
| 104 | + } |
| 105 | + |
| 106 | + // Called when another command which requires one or more of the same |
| 107 | + // subsystems is scheduled to run |
| 108 | + protected void interrupted() { |
| 109 | + end(); |
| 110 | + } |
| 111 | + |
| 112 | + @Override |
110 | 113 | public void pidWrite(double output) { |
111 | 114 | lift.runMotor(output); |
112 | 115 | } |
113 | | - |
114 | 116 | } |
0 commit comments