1
1
/* Black Knights Robotics (C) 2025 */
2
2
package org .blackknights ;
3
3
4
+ import edu .wpi .first .math .geometry .Pose2d ;
5
+ import edu .wpi .first .math .geometry .Rotation2d ;
6
+ import edu .wpi .first .math .geometry .Transform2d ;
4
7
import edu .wpi .first .wpilibj .DriverStation ;
5
8
import edu .wpi .first .wpilibj .GenericHID ;
6
9
import edu .wpi .first .wpilibj .smartdashboard .SendableChooser ;
7
10
import edu .wpi .first .wpilibj .smartdashboard .SmartDashboard ;
8
11
import edu .wpi .first .wpilibj2 .command .*;
12
+ import edu .wpi .first .wpilibj2 .command .button .CommandXboxController ;
9
13
import java .util .function .Supplier ;
10
14
import org .blackknights .commands .*;
11
15
import org .blackknights .constants .ScoringConstants ;
@@ -28,8 +32,8 @@ public class RobotContainer {
28
32
ButtonBoardSubsystem buttonBoardSubsystem = new ButtonBoardSubsystem (buttonBoard );
29
33
30
34
// Controllers
31
- Controller primaryController = new Controller (0 );
32
- Controller secondaryController = new Controller (1 );
35
+ CommandXboxController primaryController = new CommandXboxController (0 );
36
+ CommandXboxController secondaryController = new CommandXboxController (1 );
33
37
34
38
private final NetworkTablesUtils NTTune = NetworkTablesUtils .getTable ("debug" );
35
39
@@ -61,17 +65,33 @@ public RobotContainer() {
61
65
SmartDashboard .putData (cqProfiles );
62
66
SmartDashboard .putData ("Auto Chooser" , superSecretMissileTech );
63
67
68
+ // Autos
64
69
superSecretMissileTech .addOption (
65
- "Left " ,
70
+ "LEFT_3 " ,
66
71
new SequentialCommandGroup (
67
72
getLocationPlaceCommand (CoralQueue .CoralPosition .fromString ("10L4" )),
68
- getAutoIntakeCommand (),
73
+ getAutoIntakeCommand (IntakeSides . LEFT ),
69
74
getLocationPlaceCommand (CoralQueue .CoralPosition .fromString ("8L4" )),
70
- getAutoIntakeCommand (),
75
+ getAutoIntakeCommand (IntakeSides . LEFT ),
71
76
getLocationPlaceCommand (CoralQueue .CoralPosition .fromString ("9L4" ))));
72
77
73
78
superSecretMissileTech .addOption (
74
- "One pose" , getLocationPlaceCommand (CoralQueue .CoralPosition .fromString ("10L4" )));
79
+ "RIGHT_3" ,
80
+ new SequentialCommandGroup (
81
+ getLocationPlaceCommand (CoralQueue .CoralPosition .fromString ("3L4" )),
82
+ getAutoIntakeCommand (IntakeSides .RIGHT ),
83
+ getLocationPlaceCommand (CoralQueue .CoralPosition .fromString ("6L4" )),
84
+ getAutoIntakeCommand (IntakeSides .RIGHT ),
85
+ getLocationPlaceCommand (CoralQueue .CoralPosition .fromString ("7L4" ))));
86
+
87
+ superSecretMissileTech .addOption (
88
+ "CENTER_LEFT" ,
89
+ getLocationPlaceCommand (CoralQueue .CoralPosition .fromString ("12L4" )));
90
+ superSecretMissileTech .addOption (
91
+ "CENTER_RIGHT" ,
92
+ getLocationPlaceCommand (CoralQueue .CoralPosition .fromString ("1L4" )));
93
+
94
+ superSecretMissileTech .addOption ("INTAKE_TEST" , getAutoIntakeCommand (IntakeSides .RIGHT ));
75
95
}
76
96
77
97
/** Configure controller bindings */
@@ -82,33 +102,104 @@ private void configureBindings() {
82
102
swerveSubsystem .setDefaultCommand (
83
103
new DriveCommands (
84
104
swerveSubsystem ,
85
- () -> primaryController .getLeftY () * 2.5 ,
86
- () -> primaryController .getLeftX () * 2.5 ,
87
- () -> -primaryController .getRightX () * Math .PI ,
105
+ () ->
106
+ primaryController .getLeftY ()
107
+ * ConfigManager .getInstance ().get ("driver_max_speed" , 3.5 ),
108
+ () ->
109
+ primaryController .getLeftX ()
110
+ * ConfigManager .getInstance ().get ("driver_max_speed" , 3.5 ),
111
+ () ->
112
+ -primaryController .getRightX ()
113
+ * Math .toRadians (
114
+ ConfigManager .getInstance ()
115
+ .get ("driver_max_speed_rot" , 360 )),
88
116
true ,
89
117
true ));
90
118
91
- primaryController .rightBumper .whileTrue (
92
- getPlaceCommand (() -> coralQueue .getCurrentPosition (), () -> coralQueue .getNext ()));
119
+ primaryController
120
+ .leftBumper ()
121
+ .whileTrue (
122
+ getPlaceCommand (
123
+ () -> coralQueue .getCurrentPosition (), () -> coralQueue .getNext ()));
93
124
94
- primaryController .leftBumper .whileTrue (
95
- new ParallelCommandGroup (
96
- new ElevatorArmCommand (
97
- elevatorSubsystem ,
98
- armSubsystem ,
99
- () -> ScoringConstants .ScoringHeights .INTAKE ),
100
- new IntakeCommand (
101
- intakeSubsystem , IntakeCommand .IntakeMode .INTAKE , () -> false )));
125
+ primaryController
126
+ .rightBumper ()
127
+ .whileTrue (
128
+ new ParallelCommandGroup (
129
+ new DriveCommands (
130
+ swerveSubsystem ,
131
+ primaryController ::getLeftY ,
132
+ primaryController ::getLeftX ,
133
+ () -> -primaryController .getRightX () * Math .PI ,
134
+ true ,
135
+ true ),
136
+ new ElevatorArmCommand (
137
+ elevatorSubsystem ,
138
+ armSubsystem ,
139
+ () -> ScoringConstants .ScoringHeights .INTAKE ),
140
+ new IntakeCommand (
141
+ intakeSubsystem , IntakeCommand .IntakeMode .INTAKE )));
102
142
103
143
elevatorSubsystem .setDefaultCommand (new BaseCommand (elevatorSubsystem , armSubsystem ));
104
144
145
+ primaryController .povDown ().whileTrue (new RunCommand (() -> swerveSubsystem .zeroGyro ()));
146
+
147
+ secondaryController
148
+ .rightStick ()
149
+ .onTrue (new InstantCommand (ScoringConstants ::recomputeCoralPositions ));
150
+
151
+ // SECONDARY CONTROLLER
152
+
105
153
climberSubsystem .setDefaultCommand (
106
154
new ClimberCommand (climberSubsystem , secondaryController ));
107
155
108
- primaryController .dpadDown .whileTrue (new RunCommand (() -> swerveSubsystem .zeroGyro ()));
156
+ secondaryController
157
+ .a ()
158
+ .whileTrue (
159
+ new ElevatorArmCommand (
160
+ elevatorSubsystem ,
161
+ armSubsystem ,
162
+ () -> ScoringConstants .ScoringHeights .L1 ));
163
+
164
+ secondaryController
165
+ .b ()
166
+ .whileTrue (
167
+ new ElevatorArmCommand (
168
+ elevatorSubsystem ,
169
+ armSubsystem ,
170
+ () -> ScoringConstants .ScoringHeights .L2 ));
171
+
172
+ secondaryController
173
+ .x ()
174
+ .whileTrue (
175
+ new ElevatorArmCommand (
176
+ elevatorSubsystem ,
177
+ armSubsystem ,
178
+ () -> ScoringConstants .ScoringHeights .L3 ));
179
+
180
+ secondaryController
181
+ .y ()
182
+ .whileTrue (
183
+ new ElevatorArmCommand (
184
+ elevatorSubsystem ,
185
+ armSubsystem ,
186
+ () -> ScoringConstants .ScoringHeights .L4 ));
187
+
188
+ secondaryController
189
+ .leftBumper ()
190
+ .onTrue (new InstantCommand (() -> coralQueue .stepForwards ())); //
109
191
110
- secondaryController .leftBumper .onTrue (new InstantCommand (() -> coralQueue .stepBackwards ()));
111
- secondaryController .rightBumper .onTrue (new InstantCommand (() -> coralQueue .stepForwards ()));
192
+ secondaryController
193
+ .rightBumper ()
194
+ .onTrue (new InstantCommand (() -> coralQueue .stepBackwards ()));
195
+
196
+ secondaryController
197
+ .rightTrigger (0.2 )
198
+ .whileTrue (new IntakeCommand (intakeSubsystem , IntakeCommand .IntakeMode .OUTTAKE ));
199
+
200
+ secondaryController
201
+ .leftTrigger (0.2 )
202
+ .whileTrue (new IntakeCommand (intakeSubsystem , IntakeCommand .IntakeMode .INTAKE ));
112
203
}
113
204
114
205
/** Runs once when the code starts */
@@ -125,7 +216,10 @@ public void robotPeriodic() {
125
216
126
217
/** Runs ones when enabled in teleop */
127
218
public void teleopInit () {
128
- CoralQueue .getInstance ().loadProfile (cqProfiles .getSelected ());
219
+ buttonBoardSubsystem .bind ();
220
+
221
+ if (cqProfiles .getSelected () != null )
222
+ CoralQueue .getInstance ().loadProfile (cqProfiles .getSelected ());
129
223
}
130
224
131
225
/**
@@ -171,22 +265,32 @@ private Command getPlaceCommand(
171
265
false ,
172
266
"rough" ),
173
267
new BaseCommand (elevatorSubsystem , armSubsystem )),
174
- new ParallelCommandGroup (
175
- new SequentialCommandGroup (
176
- new AlignCommand (
268
+ new ParallelRaceGroup (
269
+ new AlignCommand (
177
270
swerveSubsystem ,
178
271
() -> currentSupplier .get ().getPose (),
179
272
true ,
180
- "fine" ),
181
- new IntakeCommand (
182
- intakeSubsystem ,
183
- IntakeCommand .IntakeMode .OUTTAKE ,
184
- () -> armSubsystem .hasGamePiece ())
185
- .withTimeout (2 )),
273
+ "fine" )
274
+ .withTimeout (
275
+ ConfigManager .getInstance ()
276
+ .get ("align_fine_max_time" , 3.0 )),
277
+ new RunCommand (
278
+ () ->
279
+ intakeSubsystem .setSpeed (
280
+ ConfigManager .getInstance ()
281
+ .get ("intake_slow_voltage" , -2.0 )),
282
+ intakeSubsystem ),
186
283
new ElevatorArmCommand (
187
284
elevatorSubsystem ,
188
285
armSubsystem ,
189
- () -> nextSupplier .get ().getHeight ())));
286
+ () -> currentSupplier .get ().getHeight ())),
287
+ new ParallelRaceGroup (
288
+ new ElevatorArmCommand (
289
+ elevatorSubsystem ,
290
+ armSubsystem ,
291
+ () -> nextSupplier .get ().getHeight ()),
292
+ new IntakeCommand (intakeSubsystem , IntakeCommand .IntakeMode .OUTTAKE )
293
+ .withTimeout (1 )));
190
294
}
191
295
192
296
/**
@@ -204,27 +308,52 @@ private Command getLocationPlaceCommand(CoralQueue.CoralPosition position) {
204
308
*
205
309
* @return The command to goto the feeder
206
310
*/
207
- private Command getAutoIntakeCommand () {
208
- return new ParallelDeadlineGroup (
311
+ private Command getAutoIntakeCommand (IntakeSides side ) {
312
+ Pose2d intakePose = getPose2d (side );
313
+
314
+ Pose2d intakePoseFinal =
315
+ intakePose .plus (new Transform2d (0 , 0 , Rotation2d .fromRadians (Math .PI )));
316
+
317
+ return new ParallelRaceGroup (
209
318
new SequentialCommandGroup (
210
319
new AlignCommand (
211
320
swerveSubsystem ,
212
321
() ->
213
- DriverStation .getAlliance ().isPresent ()
214
- && DriverStation .getAlliance ().get ()
215
- == DriverStation .Alliance .Blue
216
- ? ScoringConstants .INTAKE_BLUE
217
- : ScoringConstants .INTAKE_RED ,
218
- true ,
219
- "rough" ),
220
- new IntakeCommand (
221
- intakeSubsystem ,
222
- IntakeCommand .IntakeMode .INTAKE ,
223
- () -> armSubsystem .hasGamePiece ())
224
- .withTimeout (2 )),
322
+ AlignUtils .getXDistBack (
323
+ intakePoseFinal ,
324
+ ConfigManager .getInstance ()
325
+ .get ("autointake_first_back" , 1.0 )),
326
+ false ,
327
+ "auto" ),
328
+ new AlignCommand (swerveSubsystem , () -> intakePoseFinal , true , "fine" )),
225
329
new ElevatorArmCommand (
226
330
elevatorSubsystem ,
227
331
armSubsystem ,
228
- () -> ScoringConstants .ScoringHeights .INTAKE ));
332
+ () -> ScoringConstants .ScoringHeights .INTAKE ),
333
+ new IntakeCommand (intakeSubsystem , IntakeCommand .IntakeMode .INTAKE ));
334
+ }
335
+
336
+ private static Pose2d getPose2d (IntakeSides side ) {
337
+ Pose2d intakePose ;
338
+ if (DriverStation .getAlliance ().isPresent ()
339
+ && DriverStation .getAlliance ().get () == DriverStation .Alliance .Blue ) {
340
+ if (side == IntakeSides .LEFT ) {
341
+ intakePose = ScoringConstants .INTAKE_BLUE_LEFT ;
342
+ } else {
343
+ intakePose = ScoringConstants .INTAKE_BLUE_RIGHT ;
344
+ }
345
+ } else {
346
+ if (side == IntakeSides .LEFT ) {
347
+ intakePose = ScoringConstants .INTAKE_RED_LEFT ;
348
+ } else {
349
+ intakePose = ScoringConstants .INTAKE_RED_RIGHT ;
350
+ }
351
+ }
352
+ return intakePose ;
353
+ }
354
+
355
+ private enum IntakeSides {
356
+ LEFT ,
357
+ RIGHT
229
358
}
230
359
}
0 commit comments