Skip to content

Commit a2cea26

Browse files
committed
Merge remote-tracking branch 'origin/intake-work' into develop
2 parents ea2c0de + 19f6b4d commit a2cea26

File tree

2 files changed

+58
-92
lines changed

2 files changed

+58
-92
lines changed

src/main/java/frc/robot/Constants.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ public static class LiftHardware {
9999
}
100100

101101
public static class IntakeHardware {
102-
public static final Spark.ID FLAPPER_MOTOR_ID = new Spark.ID("IntakeHardware/FlapperIntakeMotor", 7);
103-
public static final Spark.ID FUNNEL_MOTOR_ID = new Spark.ID("IntakeHardware/FrontIntakeMotor", 8);
102+
public static final Spark.ID FLAPPER_MOTOR_ID = new Spark.ID("IntakeHardware/IntakeMotor", 7);
104103
public static final LimitSwitch.ID FIRST_INTAKE_BEAM_BREAK = new LimitSwitch.ID(
105104
"IntakeHardware/FirstIntakeBeamBreak", 1);
106105
public static final LimitSwitch.ID SECOND_INTAKE_BEAM_BREAK = new LimitSwitch.ID(

src/main/java/frc/robot/subsystems/intake/IntakeSubsystem.java

+57-90
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,28 @@
1717
import frc.robot.Constants;
1818

1919
public class IntakeSubsystem extends StateMachine implements AutoCloseable {
20-
public static record Hardware(
21-
Spark flapperMotor,
22-
Spark funnelMotor,
23-
LimitSwitch firstBeamBreak,
24-
LimitSwitch secondBeamBreak) {
25-
}
20+
public static record Hardware (
21+
Spark intakeMotor,
22+
LimitSwitch firstBeamBreak,
23+
LimitSwitch secondBeamBreak
24+
) {}
2625

27-
static final Dimensionless FLAPPER_INTAKE_SPEED = Percent.of(100);
28-
static final Dimensionless FUNNEL_INTAKE_SPEED = Percent.of(100);
29-
static final Dimensionless REVERSE_FLAPPER_INTAKE_SPEED = Percent.of(-50);
30-
static final Dimensionless REVERSE_FUNNEL_INTAKE_SPEED = Percent.of(-50);
26+
static final Dimensionless INTAKE_SPEED = Percent.of(100);
27+
static final Dimensionless REVERSE_INTAKE_SPEED = Percent.of(-50);
3128

3229
public enum IntakeStates implements SystemState {
33-
IDLE {
30+
STOP {
3431
@Override
3532
public void initialize() {
36-
s_intakeInstance.stopFlapperIntake();
37-
s_intakeInstance.stopFunnelIntake();
33+
s_intakeInstance.stopIntakeMotor();
3834
}
3935

4036
@Override
4137
public IntakeStates nextState() {
42-
if (s_requestedState == IDLE) {
43-
return IDLE;
44-
} else if (s_requestedState == INTAKE) {
38+
if (s_requestedState == STOP) {
39+
return STOP;
40+
}
41+
else if (s_requestedState == INTAKE) {
4542
return INTAKE;
4643
} else if (s_requestedState == REGURGITATE) {
4744
return REGURGITATE;
@@ -52,15 +49,15 @@ public IntakeStates nextState() {
5249
INTAKE {
5350
@Override
5451
public void initialize() {
55-
s_intakeInstance.startFlapperIntake();
56-
s_intakeInstance.startFunnelIntake();
52+
s_intakeInstance.intake();
5753
}
5854

5955
@Override
6056
public IntakeStates nextState() {
61-
if (s_requestedState == IDLE) {
62-
return IDLE;
63-
} else if (s_requestedState == INTAKE) {
57+
if (s_requestedState == STOP) {
58+
return STOP;
59+
}
60+
else if (s_requestedState == INTAKE) {
6461
return INTAKE;
6562
} else if (s_requestedState == REGURGITATE) {
6663
return REGURGITATE;
@@ -71,15 +68,15 @@ public IntakeStates nextState() {
7168
REGURGITATE {
7269
@Override
7370
public void initialize() {
74-
s_intakeInstance.startReverseFlapperIntake();
75-
s_intakeInstance.startReverseFunnelIntake();
71+
s_intakeInstance.reverseIntake();
7672
}
7773

7874
@Override
7975
public IntakeStates nextState() {
80-
if (s_requestedState == IDLE) {
81-
return IDLE;
82-
} else if (s_requestedState == INTAKE) {
76+
if (s_requestedState == STOP) {
77+
return STOP;
78+
}
79+
else if (s_requestedState == INTAKE) {
8380
return INTAKE;
8481
} else if (s_requestedState == REGURGITATE) {
8582
return REGURGITATE;
@@ -91,34 +88,29 @@ public IntakeStates nextState() {
9188

9289
private static IntakeStates s_requestedState;
9390
private static IntakeSubsystem s_intakeInstance;
94-
private final Spark m_flapperMotor;
95-
private final Spark m_funnelMotor;
91+
private final Spark m_intakeMotor;
9692
private final LimitSwitch m_firstBeamBreak;
9793
private final LimitSwitch m_secondBeamBreak;
9894

9995
/** Creates a new IntakeSubsystem */
10096
private IntakeSubsystem(Hardware intakeHardware) {
101-
super(IntakeStates.IDLE);
102-
this.m_flapperMotor = intakeHardware.flapperMotor;
103-
this.m_funnelMotor = intakeHardware.funnelMotor;
97+
super(IntakeStates.STOP);
98+
this.m_intakeMotor = intakeHardware.intakeMotor;
10499
this.m_firstBeamBreak = intakeHardware.firstBeamBreak;
105100
this.m_secondBeamBreak = intakeHardware.secondBeamBreak;
106-
s_requestedState = IntakeStates.IDLE;
101+
s_requestedState = IntakeStates.STOP;
107102

108103
// Restore to factory defaults
109-
m_flapperMotor.restoreFactoryDefaults();
110-
m_funnelMotor.restoreFactoryDefaults();
104+
m_intakeMotor.restoreFactoryDefaults();
111105

112106
// Set idle mode
113-
m_flapperMotor.setIdleMode(IdleMode.kBrake);
114-
m_funnelMotor.setIdleMode(IdleMode.kBrake);
107+
m_intakeMotor.setIdleMode(IdleMode.kBrake);
115108
}
116109

117110
/**
118111
* Get an instance of IntakeSubsystem
119112
* <p>
120113
* Will only return an instance once, subsequent calls will return null.
121-
*
122114
* @param intakeHardware Necessary hardware for this subsystem
123115
* @return Subsystem instance
124116
*/
@@ -132,110 +124,85 @@ public static IntakeSubsystem getInstance(Hardware intakeHardware) {
132124

133125
/**
134126
* Initialize hardware devices for intake subsystem
135-
*
136127
* @return Hardware object containing all necessary devices for this subsystem
137128
*/
138129
public static Hardware initializeHardware() {
139130
Hardware intakeHardware = new Hardware(
140-
new Spark(Constants.IntakeHardware.FLAPPER_MOTOR_ID, MotorKind.NEO_VORTEX),
141-
new Spark(Constants.IntakeHardware.FUNNEL_MOTOR_ID, MotorKind.NEO_VORTEX),
142-
new LimitSwitch(Constants.IntakeHardware.FIRST_INTAKE_BEAM_BREAK, SwitchPolarity.NORMALLY_OPEN,
143-
Constants.Frequencies.BEAM_BREAK_UPDATE_RATE),
144-
new LimitSwitch(Constants.IntakeHardware.SECOND_INTAKE_BEAM_BREAK, SwitchPolarity.NORMALLY_OPEN,
145-
Constants.Frequencies.BEAM_BREAK_UPDATE_RATE));
131+
new Spark(Constants.IntakeHardware.FLAPPER_MOTOR_ID, MotorKind.NEO_VORTEX),
132+
new LimitSwitch(Constants.IntakeHardware.FIRST_INTAKE_BEAM_BREAK, SwitchPolarity.NORMALLY_OPEN, Constants.Frequencies.BEAM_BREAK_UPDATE_RATE),
133+
new LimitSwitch(Constants.IntakeHardware.SECOND_INTAKE_BEAM_BREAK, SwitchPolarity.NORMALLY_OPEN, Constants.Frequencies.BEAM_BREAK_UPDATE_RATE)
134+
);
146135
return intakeHardware;
147136
}
148137

149138
/**
150-
* Calls the idle state in the state machine for API purposes
139+
* Calls the stop state in the state machine for API purposes
151140
*/
152-
public void idle() {
153-
s_requestedState = IntakeStates.IDLE;
141+
public void stop() {
142+
s_requestedState = IntakeStates.STOP;
154143
}
155144

156145
/**
157146
* Calls the intake state in the state machine for API purpose
158147
*/
159-
public void intake() {
148+
public void startIntake() {
160149
s_requestedState = IntakeStates.INTAKE;
161150
}
162151

163152
/**
164153
* Calls the regurgitate state in the state machine for APi purposes
165154
*/
166-
public void regurgitate() {
155+
public void startRegurgitate() {
167156
s_requestedState = IntakeStates.REGURGITATE;
168157
}
169158

170159
/**
171-
* Intake coral using only flapper intake motor
172-
*/
173-
private void startFlapperIntake() {
174-
m_flapperMotor.set(FLAPPER_INTAKE_SPEED.in(Value));
175-
}
176-
177-
/**
178-
* Intakes the coral using the funnel motor into the end effector
179-
*/
180-
private void startFunnelIntake() {
181-
m_funnelMotor.set(FUNNEL_INTAKE_SPEED.in(Value));
182-
}
183-
184-
/**
185-
* Outtakes the coral using the flapper motor
186-
*/
187-
private void startReverseFlapperIntake() {
188-
m_flapperMotor.set(REVERSE_FLAPPER_INTAKE_SPEED.in(Value));
189-
}
190-
191-
/**
192-
* Outtakes the coral using the funnel motor
160+
* Checks if coral is NOT fully in the intake using the beam breaks
161+
* @return Boolean value whether coral in fully in the intake or not
193162
*/
194-
private void startReverseFunnelIntake() {
195-
m_funnelMotor.set(REVERSE_FUNNEL_INTAKE_SPEED.in(Value));
163+
public boolean coralNotInIntake() {
164+
return (!(m_firstBeamBreak.getInputs().value) && !(m_secondBeamBreak.getInputs().value));
196165
}
197166

198167
/**
199168
* Checks if coral is fully in the intake using the beam breaks
200-
*
201169
* @return Boolean value whether coral is fully in intake or not
202170
*/
203-
public boolean coralFullyInIntake() {
171+
public boolean coralInIntake() {
204172
return ((m_firstBeamBreak.getInputs().value) && !(m_secondBeamBreak.getInputs().value));
205173
}
206174

207175
public boolean isEmpty() {
208176
return !m_firstBeamBreak.getInputs().value && !m_secondBeamBreak.getInputs().value;
209177
}
210178

211-
/**
212-
* Stop all the flapper motor
179+
/**
180+
* Intake coral using intake motor
213181
*/
214-
private void stopFlapperIntake() {
215-
m_flapperMotor.stopMotor();
182+
private void intake() {
183+
m_intakeMotor.set(INTAKE_SPEED.in(Value));
216184
}
217185

218186
/**
219-
* Stop all the funnel motor
187+
* Outtakes the coral using the intake motor
220188
*/
221-
private void stopFunnelIntake() {
222-
m_funnelMotor.stopMotor();
189+
private void reverseIntake() {
190+
m_intakeMotor.set(INTAKE_SPEED.in(Value));
223191
}
224192

225-
@Override
226-
public void periodic() {
227-
super.periodic();
228-
229-
Logger.recordOutput(getName() + "/state", getState().toString());
193+
/**
194+
* Stop the intake motor
195+
*/
196+
private void stopIntakeMotor() {
197+
m_intakeMotor.stopMotor();
230198
}
231199

200+
232201
/**
233202
* Closes all the motors, makes intake instance null
234203
*/
235204
public void close() {
236-
m_flapperMotor.close();
237-
m_funnelMotor.close();
205+
m_intakeMotor.close();
238206
s_intakeInstance = null;
239207
}
240208
}
241-

0 commit comments

Comments
 (0)