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

Commit 1090534

Browse files
committed
address concerns in pr; consolidated code in intake eject and removed ability for user to mess up the toggle commands
1 parent 3b1cbbd commit 1090534

1 file changed

Lines changed: 66 additions & 58 deletions

File tree

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

Lines changed: 66 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public class IntakeEject extends Subsystem implements IntakeEjectInterface {
2222
private final DoubleSolenoid leftHorizontalSolenoid = RobotMap.leftIntakeHorizontalSolenoid;
2323
private final DoubleSolenoid rightHorizontalSolenoid = RobotMap.rightIntakeHorizontalSolenoid;
2424

25+
private boolean leftOpen = false;
26+
private boolean rightOpen = leftOpen;
27+
2528
/**
2629
* Set the default command for a subsystem here.
2730
*/
@@ -100,93 +103,98 @@ public void runIntake(double speed) {
100103
* Raises the intake
101104
*/
102105
public void raiseIntake() {
103-
DoubleSolenoid.Value leftSet = Robot.getBool("Intake Left Vertical Solenoid Inverted", false)
104-
? DoubleSolenoid.Value.kReverse
105-
: DoubleSolenoid.Value.kForward;
106-
DoubleSolenoid.Value rightSet = Robot.getBool("Intake Right Vertical Solenoid Inverted", false)
107-
? DoubleSolenoid.Value.kReverse
108-
: DoubleSolenoid.Value.kForward;
109-
leftVerticalSolenoid.set(leftSet);
110-
rightVerticalSolenoid.set(rightSet);
106+
leftVerticalSolenoid.set(solenoidSet(true, true));
107+
rightVerticalSolenoid.set(solenoidSet(false, true));
111108
}
112109

113110
/**
114111
* Lowers the intake
115112
*/
116113
public void lowerIntake() {
117-
DoubleSolenoid.Value leftSet = Robot.getBool("Intake Left Vertical Solenoid Inverted", false)
118-
? DoubleSolenoid.Value.kForward
119-
: DoubleSolenoid.Value.kReverse;
120-
DoubleSolenoid.Value rightSet = Robot.getBool("Intake Right Vertical Solenoid Inverted", false)
121-
? DoubleSolenoid.Value.kForward
122-
: DoubleSolenoid.Value.kReverse;
123-
leftVerticalSolenoid.set(leftSet);
124-
rightVerticalSolenoid.set(rightSet);
114+
leftVerticalSolenoid.set(solenoidSet(true, false));
115+
rightVerticalSolenoid.set(solenoidSet(false, false));
125116
}
126117

127118
/**
128-
* Toggles the left intake between open and closed
119+
* Takes into account SmartDashboard keys to set the position of one of the
120+
* vertical solenoids
121+
*
122+
* @param left
123+
* Whether or not the solenoid to toggle is the left solenoid
124+
* @param up
125+
* Whether or not the solenoid should be set to raised
126+
* @return The DoubleSolenoid.Value that the solenoid should be set to
129127
*/
130-
public void toggleLeftIntake() {
131-
boolean open = SmartDashboard.getBoolean("Left Horizontal Solenoid Open", true);
132-
DoubleSolenoid.Value set;
133-
if (open) {
134-
set = Robot.getBool("Intake Left Horizontal Solenoid Inverted", false) ? DoubleSolenoid.Value.kForward
135-
: DoubleSolenoid.Value.kReverse;
128+
public DoubleSolenoid.Value solenoidSet(boolean left, boolean up) {
129+
String side = left ? "Left" : "Right";
130+
String key = "Intake " + side + " Vertical Solenoid Inverted";
131+
boolean inverted = Robot.getBool(key, false);
132+
if ((up && inverted) || (!up && !inverted)) {
133+
return DoubleSolenoid.Value.kReverse;
136134
} else {
137-
set = Robot.getBool("Intake Left Horizontal Solenoid Inverted", false) ? DoubleSolenoid.Value.kReverse
138-
: DoubleSolenoid.Value.kForward;
135+
return DoubleSolenoid.Value.kForward;
139136
}
140-
leftHorizontalSolenoid.set(set);
141-
SmartDashboard.putBoolean("Left Horizontal Solenoid Open", !open);
142137
}
143138

144139
/**
145-
* Toggles the right intake between open and closed
140+
* Takes into account SmartDashboard keys and current position to toggle the
141+
* position of one of the horizontal solenoids
142+
*
143+
* @param left
144+
* Whether or not the solenoid to toggle is the left solenoid
145+
* @return The DoubleSolenoid.Value that the solenoid should be set to
146146
*/
147-
public void toggleRightIntake() {
148-
boolean open = SmartDashboard.getBoolean("Right Horizontal Solenoid Open", true);
149-
DoubleSolenoid.Value set;
150-
if (open) {
151-
set = Robot.getBool("Intake Right Horizontal Solenoid Inverted", false) ? DoubleSolenoid.Value.kForward
152-
: DoubleSolenoid.Value.kReverse;
147+
public DoubleSolenoid.Value toggleHorizontal(boolean left) {
148+
boolean open = left ? leftOpen : rightOpen;
149+
String side = left ? "Left" : "Right";
150+
String key = "Intake " + side + " Horizontal Solenoid Inverted";
151+
boolean inverted = Robot.getBool(key, false);
152+
if ((open && inverted) || (!open && !inverted)) {
153+
return DoubleSolenoid.Value.kForward;
153154
} else {
154-
set = Robot.getBool("Intake Right Horizontal Solenoid Inverted", false) ? DoubleSolenoid.Value.kReverse
155-
: DoubleSolenoid.Value.kForward;
155+
return DoubleSolenoid.Value.kReverse;
156156
}
157-
rightHorizontalSolenoid.set(set);
158-
SmartDashboard.putBoolean("Right Horizontal Solenoid Open", !open);
157+
}
158+
159+
/**
160+
* Toggles the left intake between open and closed
161+
*/
162+
public void toggleLeftIntake() {
163+
leftHorizontalSolenoid.set(toggleHorizontal(true));
164+
leftOpen = !leftOpen;
165+
SmartDashboard.putBoolean("Left Horizontal Solenoid Open", leftOpen);
166+
}
167+
168+
/**
169+
* Toggles the right intake between open and closed
170+
*/
171+
public void toggleRightIntake() {
172+
rightHorizontalSolenoid.set(toggleHorizontal(false));
173+
rightOpen = !rightOpen;
174+
SmartDashboard.putBoolean("Right Horizontal Solenoid Open", rightOpen);
159175
}
160176

161177
/**
162178
* Closes the intake
163179
*/
164180
public void closeIntake() {
165-
DoubleSolenoid.Value leftSet = Robot.getBool("Intake Left Horizontal Solenoid Inverted", false)
166-
? DoubleSolenoid.Value.kReverse
167-
: DoubleSolenoid.Value.kForward;
168-
DoubleSolenoid.Value rightSet = Robot.getBool("Intake Right Horizontal Solenoid Inverted", false)
169-
? DoubleSolenoid.Value.kReverse
170-
: DoubleSolenoid.Value.kForward;
171-
SmartDashboard.putBoolean("Left Horizontal Solenoid Open", false);
172-
SmartDashboard.putBoolean("Right Horizontal Solenoid Open", false);
173-
leftHorizontalSolenoid.set(leftSet);
174-
rightHorizontalSolenoid.set(rightSet);
181+
if (leftOpen) {
182+
toggleLeftIntake();
183+
}
184+
if (rightOpen) {
185+
toggleRightIntake();
186+
}
175187
}
176188

177189
/**
178190
* Opens the intake
179191
*/
180192
public void openIntake() {
181-
DoubleSolenoid.Value leftSet = Robot.getBool("Intake Left Horizontal Solenoid Inverted", false)
182-
? DoubleSolenoid.Value.kForward
183-
: DoubleSolenoid.Value.kReverse;
184-
DoubleSolenoid.Value rightSet = Robot.getBool("Intake Right Horizontal Solenoid Inverted", false)
185-
? DoubleSolenoid.Value.kForward
186-
: DoubleSolenoid.Value.kReverse;
187-
SmartDashboard.putBoolean("Left Horizontal Solenoid Open", true);
188-
SmartDashboard.putBoolean("Right Horizontal Solenoid Open", true);
189-
leftHorizontalSolenoid.set(leftSet);
190-
rightHorizontalSolenoid.set(rightSet);
193+
if (!leftOpen) {
194+
toggleLeftIntake();
195+
}
196+
if (!rightOpen) {
197+
toggleRightIntake();
198+
}
191199
}
192200
}

0 commit comments

Comments
 (0)