17
17
import frc .robot .Constants ;
18
18
19
19
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
+ ) {}
26
25
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 );
31
28
32
29
public enum IntakeStates implements SystemState {
33
- IDLE {
30
+ STOP {
34
31
@ Override
35
32
public void initialize () {
36
- s_intakeInstance .stopFlapperIntake ();
37
- s_intakeInstance .stopFunnelIntake ();
33
+ s_intakeInstance .stopIntakeMotor ();
38
34
}
39
35
40
36
@ Override
41
37
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 ) {
45
42
return INTAKE ;
46
43
} else if (s_requestedState == REGURGITATE ) {
47
44
return REGURGITATE ;
@@ -52,15 +49,15 @@ public IntakeStates nextState() {
52
49
INTAKE {
53
50
@ Override
54
51
public void initialize () {
55
- s_intakeInstance .startFlapperIntake ();
56
- s_intakeInstance .startFunnelIntake ();
52
+ s_intakeInstance .intake ();
57
53
}
58
54
59
55
@ Override
60
56
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 ) {
64
61
return INTAKE ;
65
62
} else if (s_requestedState == REGURGITATE ) {
66
63
return REGURGITATE ;
@@ -71,15 +68,15 @@ public IntakeStates nextState() {
71
68
REGURGITATE {
72
69
@ Override
73
70
public void initialize () {
74
- s_intakeInstance .startReverseFlapperIntake ();
75
- s_intakeInstance .startReverseFunnelIntake ();
71
+ s_intakeInstance .reverseIntake ();
76
72
}
77
73
78
74
@ Override
79
75
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 ) {
83
80
return INTAKE ;
84
81
} else if (s_requestedState == REGURGITATE ) {
85
82
return REGURGITATE ;
@@ -91,34 +88,29 @@ public IntakeStates nextState() {
91
88
92
89
private static IntakeStates s_requestedState ;
93
90
private static IntakeSubsystem s_intakeInstance ;
94
- private final Spark m_flapperMotor ;
95
- private final Spark m_funnelMotor ;
91
+ private final Spark m_intakeMotor ;
96
92
private final LimitSwitch m_firstBeamBreak ;
97
93
private final LimitSwitch m_secondBeamBreak ;
98
94
99
95
/** Creates a new IntakeSubsystem */
100
96
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 ;
104
99
this .m_firstBeamBreak = intakeHardware .firstBeamBreak ;
105
100
this .m_secondBeamBreak = intakeHardware .secondBeamBreak ;
106
- s_requestedState = IntakeStates .IDLE ;
101
+ s_requestedState = IntakeStates .STOP ;
107
102
108
103
// Restore to factory defaults
109
- m_flapperMotor .restoreFactoryDefaults ();
110
- m_funnelMotor .restoreFactoryDefaults ();
104
+ m_intakeMotor .restoreFactoryDefaults ();
111
105
112
106
// Set idle mode
113
- m_flapperMotor .setIdleMode (IdleMode .kBrake );
114
- m_funnelMotor .setIdleMode (IdleMode .kBrake );
107
+ m_intakeMotor .setIdleMode (IdleMode .kBrake );
115
108
}
116
109
117
110
/**
118
111
* Get an instance of IntakeSubsystem
119
112
* <p>
120
113
* Will only return an instance once, subsequent calls will return null.
121
- *
122
114
* @param intakeHardware Necessary hardware for this subsystem
123
115
* @return Subsystem instance
124
116
*/
@@ -132,110 +124,85 @@ public static IntakeSubsystem getInstance(Hardware intakeHardware) {
132
124
133
125
/**
134
126
* Initialize hardware devices for intake subsystem
135
- *
136
127
* @return Hardware object containing all necessary devices for this subsystem
137
128
*/
138
129
public static Hardware initializeHardware () {
139
130
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
+ );
146
135
return intakeHardware ;
147
136
}
148
137
149
138
/**
150
- * Calls the idle state in the state machine for API purposes
139
+ * Calls the stop state in the state machine for API purposes
151
140
*/
152
- public void idle () {
153
- s_requestedState = IntakeStates .IDLE ;
141
+ public void stop () {
142
+ s_requestedState = IntakeStates .STOP ;
154
143
}
155
144
156
145
/**
157
146
* Calls the intake state in the state machine for API purpose
158
147
*/
159
- public void intake () {
148
+ public void startIntake () {
160
149
s_requestedState = IntakeStates .INTAKE ;
161
150
}
162
151
163
152
/**
164
153
* Calls the regurgitate state in the state machine for APi purposes
165
154
*/
166
- public void regurgitate () {
155
+ public void startRegurgitate () {
167
156
s_requestedState = IntakeStates .REGURGITATE ;
168
157
}
169
158
170
159
/**
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
193
162
*/
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 ));
196
165
}
197
166
198
167
/**
199
168
* Checks if coral is fully in the intake using the beam breaks
200
- *
201
169
* @return Boolean value whether coral is fully in intake or not
202
170
*/
203
- public boolean coralFullyInIntake () {
171
+ public boolean coralInIntake () {
204
172
return ((m_firstBeamBreak .getInputs ().value ) && !(m_secondBeamBreak .getInputs ().value ));
205
173
}
206
174
207
175
public boolean isEmpty () {
208
176
return !m_firstBeamBreak .getInputs ().value && !m_secondBeamBreak .getInputs ().value ;
209
177
}
210
178
211
- /**
212
- * Stop all the flapper motor
179
+ /**
180
+ * Intake coral using intake motor
213
181
*/
214
- private void stopFlapperIntake () {
215
- m_flapperMotor . stopMotor ( );
182
+ private void intake () {
183
+ m_intakeMotor . set ( INTAKE_SPEED . in ( Value ) );
216
184
}
217
185
218
186
/**
219
- * Stop all the funnel motor
187
+ * Outtakes the coral using the intake motor
220
188
*/
221
- private void stopFunnelIntake () {
222
- m_funnelMotor . stopMotor ( );
189
+ private void reverseIntake () {
190
+ m_intakeMotor . set ( INTAKE_SPEED . in ( Value ) );
223
191
}
224
192
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 ( );
230
198
}
231
199
200
+
232
201
/**
233
202
* Closes all the motors, makes intake instance null
234
203
*/
235
204
public void close () {
236
- m_flapperMotor .close ();
237
- m_funnelMotor .close ();
205
+ m_intakeMotor .close ();
238
206
s_intakeInstance = null ;
239
207
}
240
208
}
241
-
0 commit comments