6
6
import edu .wpi .first .math .geometry .Transform2d ;
7
7
import edu .wpi .first .wpilibj .DriverStation ;
8
8
import edu .wpi .first .wpilibj .GenericHID ;
9
+ import edu .wpi .first .wpilibj .Timer ;
9
10
import edu .wpi .first .wpilibj .smartdashboard .SendableChooser ;
10
11
import edu .wpi .first .wpilibj .smartdashboard .SmartDashboard ;
11
12
import edu .wpi .first .wpilibj2 .command .*;
@@ -47,6 +48,12 @@ public class RobotContainer {
47
48
Camera .CameraType .PHOTONVISION ,
48
49
VisionConstants .RIGHT_CAM_TRANSFORM );
49
50
51
+ private final Camera centerCam =
52
+ new Camera (
53
+ "centerCam" ,
54
+ Camera .CameraType .PHOTONVISION ,
55
+ VisionConstants .CENTER_CAM_TRANSFORM );
56
+
50
57
private final Odometry odometry = Odometry .getInstance ();
51
58
// Auto Chooser
52
59
SendableChooser <Command > superSecretMissileTech = new SendableChooser <>();
@@ -125,20 +132,35 @@ private void configureBindings() {
125
132
primaryController
126
133
.rightBumper ()
127
134
.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 )));
135
+ new SequentialCommandGroup (
136
+ new ParallelRaceGroup (
137
+ new DriveCommands (
138
+ swerveSubsystem ,
139
+ primaryController ::getLeftY ,
140
+ primaryController ::getLeftX ,
141
+ () -> -primaryController .getRightX () * Math .PI ,
142
+ true ,
143
+ true ),
144
+ new ElevatorArmCommand (
145
+ elevatorSubsystem ,
146
+ armSubsystem ,
147
+ () -> ScoringConstants .ScoringHeights .INTAKE ),
148
+ new IntakeCommand (
149
+ intakeSubsystem , IntakeCommand .IntakeMode .INTAKE )),
150
+ new RunCommand (
151
+ () ->
152
+ swerveSubsystem .drive (
153
+ ConfigManager .getInstance ()
154
+ .get ("back_mps" , -1.0 ),
155
+ 0.0 ,
156
+ 0.0 ,
157
+ false ,
158
+ false ,
159
+ false ),
160
+ swerveSubsystem )
161
+ .withTimeout (
162
+ ConfigManager .getInstance ()
163
+ .get ("back_time_sec" , 0.2 ))));
142
164
143
165
elevatorSubsystem .setDefaultCommand (new BaseCommand (elevatorSubsystem , armSubsystem ));
144
166
@@ -206,6 +228,7 @@ private void configureBindings() {
206
228
public void robotInit () {
207
229
odometry .addCamera (leftCam );
208
230
odometry .addCamera (rightCam );
231
+ odometry .addCamera (centerCam );
209
232
}
210
233
211
234
/** Runs every 20ms while the robot is on */
@@ -253,6 +276,7 @@ public Command getAutonomousCommand() {
253
276
private Command getPlaceCommand (
254
277
Supplier <CoralQueue .CoralPosition > currentSupplier ,
255
278
Supplier <CoralQueue .CoralPosition > nextSupplier ) {
279
+
256
280
return new SequentialCommandGroup (
257
281
new ParallelRaceGroup (
258
282
new AlignCommand (
@@ -290,7 +314,23 @@ private Command getPlaceCommand(
290
314
armSubsystem ,
291
315
() -> nextSupplier .get ().getHeight ()),
292
316
new IntakeCommand (intakeSubsystem , IntakeCommand .IntakeMode .OUTTAKE )
293
- .withTimeout (1 )));
317
+ .withTimeout (1 )),
318
+ new ParallelRaceGroup (
319
+ new AutoEndCommand (),
320
+ new BaseCommand (elevatorSubsystem , armSubsystem ),
321
+ new RunCommand (
322
+ () ->
323
+ swerveSubsystem .drive (
324
+ ConfigManager .getInstance ()
325
+ .get ("back_mps" , -1.0 ),
326
+ 0.0 ,
327
+ 0.0 ,
328
+ false ,
329
+ false ,
330
+ false ),
331
+ swerveSubsystem )
332
+ .withTimeout (
333
+ ConfigManager .getInstance ().get ("back_time_sec" , 0.2 ))));
294
334
}
295
335
296
336
/**
@@ -315,22 +355,13 @@ private Command getAutoIntakeCommand(IntakeSides side) {
315
355
intakePose .plus (new Transform2d (0 , 0 , Rotation2d .fromRadians (Math .PI )));
316
356
317
357
return new ParallelRaceGroup (
318
- new SequentialCommandGroup (
319
- new AlignCommand (
320
- swerveSubsystem ,
321
- () ->
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" )),
358
+ new ParallelCommandGroup (
359
+ new AlignCommand (swerveSubsystem , () -> intakePoseFinal , true , "rough" ),
360
+ new IntakeCommand (intakeSubsystem , IntakeCommand .IntakeMode .INTAKE )),
329
361
new ElevatorArmCommand (
330
362
elevatorSubsystem ,
331
363
armSubsystem ,
332
- () -> ScoringConstants .ScoringHeights .INTAKE ),
333
- new IntakeCommand (intakeSubsystem , IntakeCommand .IntakeMode .INTAKE ));
364
+ () -> ScoringConstants .ScoringHeights .INTAKE ));
334
365
}
335
366
336
367
private static Pose2d getPose2d (IntakeSides side ) {
@@ -356,4 +387,20 @@ private enum IntakeSides {
356
387
LEFT ,
357
388
RIGHT
358
389
}
390
+
391
+ private class AutoEndCommand extends Command {
392
+ private double currTime = Timer .getFPGATimestamp () * 1000 ;
393
+
394
+ @ Override
395
+ public void initialize () {
396
+ this .currTime = Timer .getFPGATimestamp () * 1000 ;
397
+ }
398
+
399
+ @ Override
400
+ public boolean isFinished () {
401
+ return DriverStation .isAutonomous ()
402
+ && Timer .getFPGATimestamp () * 1000 - this .currTime
403
+ > ConfigManager .getInstance ().get ("auto_place_backup_time_ms" , 0.2 );
404
+ }
405
+ }
359
406
}
0 commit comments