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

Commit 618015d

Browse files
committed
implemented HOLD_CUBE as first targ when told to go to the GROUND
for UpdateLiftPosition and LiftToPosition
1 parent a9fdf4d commit 618015d

4 files changed

Lines changed: 85 additions & 31 deletions

File tree

Robot2018/src/org/usfirst/frc/team199/Robot2018/Robot.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ public void robotInit() {
181181
listen = new Listener();
182182
// CameraServer.getInstance().startAutomaticCapture(0);
183183
// CameraServer.getInstance().startAutomaticCapture(1);
184+
185+
lift.resetEnc();
184186
}
185187

186188
/**
@@ -207,7 +209,6 @@ public void disabledPeriodic() {
207209
@Override
208210
public void autonomousInit() {
209211
dt.resetAHRS();
210-
lift.resetEnc();
211212
AutoUtils.state = new State(0, 0, 0);
212213
Scheduler.getInstance().add(new ShiftLowGear());
213214
Scheduler.getInstance().add(new CloseIntake());

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class LiftToPosition extends Command {
1313

1414
private Lift lift;
1515
private LiftHeight pos;
16+
private boolean goToGround;
1617

1718
public LiftToPosition(Lift lift, String goal) {
1819
requires(Robot.lift);
@@ -25,14 +26,14 @@ public LiftToPosition(Lift lift, String goal) {
2526
protected void initialize() {
2627
lift.getPIDController().setPID(Robot.getConst("LiftkP", 0.1), Robot.getConst("LiftkI", 0),
2728
Robot.getConst("LiftkD", 0), Robot.getConst("LiftkF", 0.1));
28-
double setpoint = lift.getDesiredDistFromPos(pos);
29-
lift.setSetpoint(setpoint);
30-
System.out.println("Target Height: " + setpoint);
3129
}
3230

3331
// Called repeatedly when this Command is scheduled to run
3432
@Override
3533
protected void execute() {
34+
double setpoint = lift.getDesiredDistFromPos(pos);
35+
lift.setSetpoint(setpoint);
36+
System.out.println("Target Height: " + setpoint);
3637
System.out.println("Current Height: " + lift.getHeight());
3738
}
3839

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

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class UpdateLiftPosition extends Command {
1616
private LiftHeight desiredPos;
1717

1818
private boolean manipulatorPluggedIn = true;
19-
private boolean goToGround = false;
19+
private boolean goToGround;
2020

2121
public UpdateLiftPosition(Lift lift) {
2222
requires(Robot.lift);
@@ -32,6 +32,7 @@ protected void initialize() {
3232
System.err.println("[ERROR] Manipulator not plugged in.");
3333
manipulatorPluggedIn = false;
3434
}
35+
goToGround = false;
3536
}
3637

3738
// Called repeatedly when this Command is scheduled to run
@@ -42,18 +43,8 @@ protected void execute() {
4243

4344
System.out.println("POV Reading: " + angle);
4445

45-
// 180 degrees is down and -1 is "nothing," so basically default to GROUND,
46-
// anything else is SWITCH
47-
// if (angle != 180 && angle != -1) {
48-
// desiredPos = LiftHeight.SWITCH;
49-
// // NOTE: if full lift functionality does become a thing, need to add a couple
50-
// // more if-elses here to account for those enum values
51-
// } else {
52-
// desiredPos = LiftHeight.GROUND;
53-
// }
54-
5546
if (angle == 180) {
56-
desiredPos = LiftHeight.HOLD_CUBE;
47+
desiredPos = LiftHeight.GROUND;
5748
goToGround = true;
5849
} else if (angle == 270) {
5950
desiredPos = LiftHeight.HOLD_CUBE;
@@ -63,17 +54,17 @@ protected void execute() {
6354
goToGround = false;
6455
}
6556

66-
if (angle != -1) {
57+
if (goToGround || angle != -1) {
6758
desiredDist = lift.getDesiredDistFromPos(desiredPos);
6859
lift.setSetpoint(desiredDist);
6960
}
7061

71-
if (goToGround && lift.onTarget() && lift.getSpeed() <= 0.1) {
72-
desiredPos = LiftHeight.GROUND;
73-
desiredDist = lift.getDesiredDistFromPos(desiredPos);
74-
lift.setSetpoint(desiredDist);
75-
goToGround = false;
76-
}
62+
// if (goToGround && lift.onTarget() && lift.getSpeed() <= 0.1) {
63+
// desiredPos = LiftHeight.GROUND;
64+
// desiredDist = lift.getDesiredDistFromPos(desiredPos);
65+
// lift.setSetpoint(desiredDist);
66+
// goToGround = false;
67+
// }
7768
}
7869
}
7970

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

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@ public class Lift extends PIDSubsystem implements LiftInterface {
2020

2121
private final int NUM_STAGES;
2222
private final double WIGGLE_ROOM;
23+
private final double GROUND_DIST;
24+
private final double HOLD_CUBE_DIST;
2325
private final double SWITCH_DIST;
2426
private final double SCALE_DIST;
2527
private final double BAR_DIST;
2628

29+
private LiftHeight desiredPos;
30+
private boolean goToGround;
31+
2732
public Lift() {
2833
super("Lift", 0, 0, 0, 0);
2934

@@ -35,7 +40,7 @@ public Lift() {
3540
double kP = r / getLiftTimeConstant() / maxSpeed;
3641
double kI = 0;
3742
double kD = r / maxSpeed;
38-
double kF = 1 / (maxSpeed * Robot.getConst("Default PID Update Time", 0.05));
43+
double kF = 1 / maxSpeed * Robot.getConst("Default PID Update Time", 0.05);
3944

4045
PIDController liftController = getPIDController();
4146

@@ -56,6 +61,8 @@ public Lift() {
5661
WIGGLE_ROOM = (int) Robot.getConst("Lift wiggle room", 3.0); // inches
5762

5863
// calculate constant measurements
64+
GROUND_DIST = 0;
65+
HOLD_CUBE_DIST = 4;
5966
// distance to switch 18.75 inches in starting position
6067
SWITCH_DIST = (18.75 + WIGGLE_ROOM) / NUM_STAGES;
6168
// distance to scale 5 feet starting 63 / 3 = 21
@@ -74,37 +81,91 @@ public void initDefaultCommand() {
7481
setDefaultCommand(new UpdateLiftPosition(this));
7582
}
7683

84+
/**
85+
* @return whether or not the cube
86+
*/
87+
private boolean atHoldCube() {
88+
double tol = Robot.getConst("Lift Tolerance", 0.8);
89+
double height = getHeight();
90+
// true if (height within tolerance of HOLD_CUBE height) and (lift is not
91+
// moving)
92+
return height <= (HOLD_CUBE_DIST + tol) && height >= (HOLD_CUBE_DIST - tol) && getSpeed() <= 0.1;
93+
}
94+
95+
/**
96+
* @return true if reached target height and does not still have to go to the
97+
* ground as a secondary, consecutive target
98+
*/
99+
@Override
100+
public boolean onTarget() {
101+
double targ = getSetpoint();
102+
double tol = Robot.getConst("Lift Tolerance", 0.8);
103+
double height = getHeight();
104+
// true if (height within tolerance of targ) and (lift is not moving)
105+
boolean wInTol = height <= (targ + tol) && height >= (targ - tol) && getSpeed() <= 0.1;
106+
return wInTol && !goToGround;
107+
}
108+
109+
/**
110+
* Set the lift's setpoint to this value continuously.
111+
*
112+
* @param pos
113+
* - the desired FINAL height
114+
* @return the FIRST height to travel to; in all cases but GROUND, FIRST = FINAL
115+
* targ
116+
*/
77117
public double getDesiredDistFromPos(LiftHeight pos) {
78118
double desiredDist;
79-
switch (pos) {
119+
LiftHeight height = pos;
120+
switch (height) {
80121
case GROUND:
81-
desiredDist = 0;
82-
break;
122+
if (atHoldCube()) {
123+
desiredDist = GROUND_DIST;
124+
// false bc doesn't need to hold the GROUND as a second consecutive targ anymore
125+
goToGround = false;
126+
break;
127+
} else {
128+
// falls through to HOLD_CUBE case
129+
height = LiftHeight.HOLD_CUBE;
130+
goToGround = true;
131+
}
83132
case HOLD_CUBE:
84-
desiredDist = 4;
133+
desiredDist = HOLD_CUBE_DIST;
134+
goToGround = false;
85135
break;
86136
case SWITCH:
87137
desiredDist = SWITCH_DIST;
138+
goToGround = false;
88139
break;
89140
case SCALE:
90141
desiredDist = SCALE_DIST;
142+
goToGround = false;
91143
break;
92144
case BAR:
93145
desiredDist = BAR_DIST;
146+
goToGround = false;
94147
break;
95148
default:
96-
desiredDist = 0;
149+
desiredDist = GROUND_DIST;
150+
goToGround = false;
97151
break;
98152
}
99153

100154
return desiredDist;
101155
}
102156

103157
/**
104-
* @return the rate of the lift encoder (in/s)
158+
* @return the desired LiftHeight to be at
159+
*/
160+
public LiftHeight desiredPos() {
161+
return desiredPos;
162+
}
163+
164+
/**
165+
* @return the absolute rate of the lift encoder (in/s)
105166
*/
106167
public double getSpeed() {
107-
return liftEnc.getRate();
168+
return Math.abs(liftEnc.getRate());
108169
}
109170

110171
/**

0 commit comments

Comments
 (0)