Skip to content
This repository was archived by the owner on Sep 14, 2019. It is now read-only.

Commit ebe418e

Browse files
committed
Merge branch 'lift-merging' of https://github.com/Gabe-Mitnick/RobotCode2018.git into lift
2 parents a4703bc + 5d8f5d6 commit ebe418e

4 files changed

Lines changed: 214 additions & 203 deletions

File tree

Robot2018/src/org/usfirst/frc/team199/Robot2018/commands/AutoLift.java

Lines changed: 84 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -12,103 +12,105 @@
1212
/**
1313
*
1414
*/
15-
public class AutoLift extends Command implements PIDOutput{
15+
public class AutoLift extends Command implements PIDOutput {
1616
/**
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.
2020
*/
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+
4028
private double desiredDist = 0;
4129
private double currDist;
4230
private LiftInterface lift;
4331
private Position desiredPos;
44-
32+
4533
private PIDController liftController;
4634

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() {
7476
// 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));
7679
// output in "motor units" (arcade and tank only accept values [-1, 1]
7780
liftController.setOutputRange(-1.0, 1.0);
7881
liftController.setContinuous(false);
79-
//liftController.setAbsoluteTolerance(Robot.getConst("MoveTolerance", 2));
82+
// liftController.setAbsoluteTolerance(Robot.getConst("MoveTolerance", 2));
8083
liftController.setSetpoint(desiredDist);
8184
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
110113
public void pidWrite(double output) {
111114
lift.runMotor(output);
112115
}
113-
114116
}

Robot2018/src/org/usfirst/frc/team199/Robot2018/subsystems/Lift.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ public class Lift extends Subsystem implements LiftInterface {
1818
private final Encoder liftEnc = RobotMap.liftEnc;
1919
private Position currPosition = Position.GROUND;
2020

21+
private final int NUM_STAGES;
22+
private final double WIGGLE_ROOM;
23+
24+
public Lift() {
25+
NUM_STAGES = (int) Robot.getConst("Lift stages", 1);
26+
WIGGLE_ROOM = (int) Robot.getConst("Lift wiggle room", 3.0);
27+
}
28+
2129
/**
2230
* Set the default command for a subsystem here.
2331
*/
@@ -51,7 +59,7 @@ public void setCurrPosition(Position newPosition) {
5159
* Uses (insert sensor here) to detect the current lift position
5260
*/
5361
public double getHeight() {
54-
return liftEnc.getDistance() * 3;
62+
return liftEnc.getDistance() * NUM_STAGES;
5563
}
5664

5765
/**
@@ -94,4 +102,17 @@ public void resetEnc() {
94102
liftEnc.reset();
95103
}
96104

105+
/**
106+
* Gets the number of stages variable
107+
*/
108+
public int getNumStages() {
109+
return NUM_STAGES;
110+
}
111+
112+
/**
113+
* Gets the extra distance above the switch or scale we want to lift in inches
114+
*/
115+
public double getWiggleRoom() {
116+
return WIGGLE_ROOM;
117+
}
97118
}
Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,66 @@
11
package org.usfirst.frc.team199.Robot2018.subsystems;
22

3-
import org.usfirst.frc.team199.Robot2018.subsystems.LiftInterface.Position;
4-
53
public interface LiftInterface {
6-
4+
75
/**
86
* Set the default command for a subsystem here.
9-
* */
7+
*/
108
public void initDefaultCommand();
11-
9+
1210
public enum Position {
13-
GROUND,
14-
SWITCH,
15-
SCALE,
16-
BAR
11+
GROUND, SWITCH, SCALE, BAR
1712
}
18-
13+
1914
/**
20-
* Uses (insert sensor here) to detect the current lift position
15+
* Uses (insert sensor here) to detect the current lift position
2116
*/
2217
public double getHeight();
23-
18+
2419
/**
2520
* stops the lift
2621
*/
2722
public void stopLift();
28-
23+
2924
/**
3025
* gets current motor values
3126
*/
3227
public double getLiftSpeed();
33-
28+
3429
/**
3530
* Runs lift motors at specified speed
36-
* @param speed - desired speed to run at
31+
*
32+
* @param speed
33+
* - desired speed to run at
3734
*/
3835
public void runMotor(double speed);
39-
36+
4037
/**
4138
* Returns the position the lift is currently at
39+
*
4240
* @return pos - current position
4341
*/
4442
public Position getCurrPos();
45-
43+
4644
/**
4745
* Resets the encoder
4846
*/
4947
public void resetEnc();
50-
48+
5149
/**
5250
* Sets the current position in the lift subsystem
53-
* @param newPosition - the new position meant to be set
51+
*
52+
* @param newPosition
53+
* - the new position meant to be set
5454
*/
5555
public void setCurrPosition(Position newPosition);
56-
57-
56+
57+
/**
58+
* Gets the number of stages variable
59+
*/
60+
public int getNumStages();
61+
62+
/**
63+
* Gets the extra distance above the switch or scale we want to lift in inches
64+
*/
65+
public double getWiggleRoom();
5866
}

0 commit comments

Comments
 (0)