-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRobot.java
More file actions
682 lines (609 loc) · 25.9 KB
/
Robot.java
File metadata and controls
682 lines (609 loc) · 25.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
package frc.robot;
import static frc.robot.subsystems.vision.VisionConstants.*;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.DriverStation.Alliance;
import edu.wpi.first.wpilibj.PneumaticsModuleType;
import edu.wpi.first.wpilibj.PowerDistribution;
import edu.wpi.first.wpilibj.PowerDistribution.ModuleType;
import edu.wpi.first.wpilibj.smartdashboard.Field2d;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.RunCommand;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import edu.wpi.first.wpilibj2.command.button.Trigger;
import frc.game.Field;
import frc.game.GameState;
import frc.lib.AllianceSelector;
import frc.lib.AutoOption;
import frc.lib.AutoSelector;
import frc.lib.CommandZorroController;
import frc.lib.ControllerSelector;
import frc.lib.ControllerSelector.ControllerType;
import frc.lib.ControllerSelector.DriverConfig;
import frc.lib.ControllerSelector.DriverController;
import frc.lib.ControllerSelector.OperatorConfig;
import frc.lib.ZorroController.Axis;
import frc.robot.Constants.DIOPorts;
import frc.robot.auto.B_LeftTrenchAuto;
import frc.robot.auto.B_LeftTrenchMoveFirstAuto;
import frc.robot.auto.B_RightTrenchAuto;
import frc.robot.auto.B_RightTrenchMoveFirstAuto;
import frc.robot.auto.R_LeftTrenchAuto;
import frc.robot.auto.R_LeftTrenchMoveFirstAuto;
import frc.robot.auto.R_RightTrenchAuto;
import frc.robot.auto.R_RightTrenchMoveFirstAuto;
import frc.robot.commands.DriveCommands;
import frc.robot.subsystems.drive.Drive;
import frc.robot.subsystems.drive.DriveConstants;
import frc.robot.subsystems.drive.GyroIO;
import frc.robot.subsystems.drive.GyroIOBoron;
import frc.robot.subsystems.drive.ModuleIO;
import frc.robot.subsystems.drive.ModuleIOSimWPI;
import frc.robot.subsystems.drive.ModuleIOTalonFX;
import frc.robot.subsystems.feeder.Feeder;
import frc.robot.subsystems.feeder.KickerIO;
import frc.robot.subsystems.feeder.KickerIOSimSpark;
import frc.robot.subsystems.feeder.KickerIOSpark;
import frc.robot.subsystems.feeder.SpindexerIO;
import frc.robot.subsystems.feeder.SpindexerIOSimSpark;
import frc.robot.subsystems.feeder.SpindexerIOSpark;
import frc.robot.subsystems.intake.Intake;
import frc.robot.subsystems.intake.IntakeArmIO;
import frc.robot.subsystems.intake.IntakeArmIOReal;
import frc.robot.subsystems.intake.IntakeArmIOSim;
import frc.robot.subsystems.intake.IntakeConstants.RollerConstants;
import frc.robot.subsystems.intake.RollerIO;
import frc.robot.subsystems.intake.RollerIOSimTalonFX;
import frc.robot.subsystems.intake.RollerIOTalonFX;
import frc.robot.subsystems.launcher.FlywheelIO;
import frc.robot.subsystems.launcher.FlywheelIOSimTalonFX;
import frc.robot.subsystems.launcher.FlywheelIOTalonFX;
import frc.robot.subsystems.launcher.HoodIO;
import frc.robot.subsystems.launcher.HoodIOSimSpark;
import frc.robot.subsystems.launcher.HoodIOSpark;
import frc.robot.subsystems.launcher.Launcher;
import frc.robot.subsystems.launcher.TurretIO;
import frc.robot.subsystems.launcher.TurretIOSimSpark;
import frc.robot.subsystems.launcher.TurretIOSpark;
import frc.robot.subsystems.leds.LEDController;
import frc.robot.subsystems.vision.Vision;
import frc.robot.subsystems.vision.VisionIO;
import frc.robot.subsystems.vision.VisionIOPhotonVision;
import frc.robot.subsystems.vision.VisionIOPhotonVisionSim;
import frc.robot.util.CanandgyroThread;
import frc.robot.util.SparkOdometryThread;
import frc.robot.util.VisionThread;
import org.littletonrobotics.junction.LogFileUtil;
import org.littletonrobotics.junction.LoggedRobot;
import org.littletonrobotics.junction.Logger;
import org.littletonrobotics.junction.networktables.NT4Publisher;
import org.littletonrobotics.junction.wpilog.WPILOGReader;
import org.littletonrobotics.junction.wpilog.WPILOGWriter;
/**
* The VM is configured to automatically run this class, and to call the functions corresponding to
* each mode, as described in the TimedRobot documentation. If you change the name of this class or
* the package after creating this project, you must also update the build.gradle file in the
* project.
*/
public class Robot extends LoggedRobot {
public static final AllianceSelector allianceSelector =
new AllianceSelector(DIOPorts.allianceColorSelector);
public static final AutoSelector autoSelector =
new AutoSelector(DIOPorts.autonomousModeSelector, allianceSelector::getAllianceColor);
public static final Field2d field = new Field2d();
public final PowerDistribution powerDistribution = new PowerDistribution(1, ModuleType.kRev);
// Subsystems
private Drive drive;
private Vision vision;
private Launcher launcher;
private Feeder feeder;
private Intake intake;
// private Hopper hopper;
private LEDController leds = LEDController.getInstance();
public Robot() {
// Record metadata
Logger.recordMetadata("ProjectName", BuildConstants.MAVEN_NAME);
Logger.recordMetadata("BuildDate", BuildConstants.BUILD_DATE);
Logger.recordMetadata("GitSHA", BuildConstants.GIT_SHA);
Logger.recordMetadata("GitDate", BuildConstants.GIT_DATE);
Logger.recordMetadata("GitBranch", BuildConstants.GIT_BRANCH);
switch (BuildConstants.DIRTY) {
case 0:
Logger.recordMetadata("GitDirty", "All changes committed");
break;
case 1:
Logger.recordMetadata("GitDirty", "Uncomitted changes");
break;
default:
Logger.recordMetadata("GitDirty", "Unknown");
break;
}
// Set up data receivers & replay source
switch (Constants.currentMode) {
case REAL: // Running on a real robot
// Log to a USB stick ("/U/logs")
Logger.addDataReceiver(new WPILOGWriter());
Logger.addDataReceiver(new NT4Publisher());
// Instantiate hardware IO implementations
drive =
new Drive(
new GyroIOBoron(),
new ModuleIOTalonFX(DriveConstants.FrontLeft),
new ModuleIOTalonFX(DriveConstants.FrontRight),
new ModuleIOTalonFX(DriveConstants.BackLeft),
new ModuleIOTalonFX(DriveConstants.BackRight));
vision =
new Vision(
drive::addVisionMeasurement,
drive::getPose,
new VisionIOPhotonVision(cameraFrontRightName, robotToFrontRightCamera),
new VisionIOPhotonVision(cameraFrontLeftName, robotToFrontLeftCamera),
new VisionIOPhotonVision(cameraBackRightName, robotToBackRightCamera),
new VisionIOPhotonVision(cameraBackLeftName, robotToBackLeftCamera));
launcher =
new Launcher(
drive::getPose,
drive::getRobotRelativeChassisSpeeds,
new TurretIOSpark(),
new FlywheelIOTalonFX(),
new HoodIOSpark());
intake =
new Intake(
new RollerIOTalonFX(RollerConstants.upperRollerConfig),
new RollerIOTalonFX(RollerConstants.lowerRollerConfig),
new IntakeArmIOReal());
// hopper = new Hopper(new HopperIOReal());
feeder = new Feeder(new SpindexerIOSpark(), new KickerIOSpark());
SmartDashboard.putData(new Compressor(PneumaticsModuleType.REVPH));
break;
case SIM: // Running a physics simulator
// Log to NT
Logger.addDataReceiver(new NT4Publisher());
// Instantiate physics sim IO implementations
drive =
new Drive(
new GyroIO() {},
new ModuleIOSimWPI(DriveConstants.FrontLeft),
new ModuleIOSimWPI(DriveConstants.FrontRight),
new ModuleIOSimWPI(DriveConstants.BackLeft),
new ModuleIOSimWPI(DriveConstants.BackRight));
vision =
new Vision(
drive::addVisionMeasurement,
drive::getPose,
new VisionIOPhotonVisionSim(
cameraFrontRightName, robotToFrontRightCamera, drive::getPose),
new VisionIOPhotonVisionSim(
cameraFrontLeftName, robotToFrontLeftCamera, drive::getPose),
new VisionIOPhotonVisionSim(
cameraBackRightName, robotToBackRightCamera, drive::getPose),
new VisionIOPhotonVisionSim(
cameraBackLeftName, robotToBackLeftCamera, drive::getPose));
launcher =
new Launcher(
drive::getPose,
drive::getRobotRelativeChassisSpeeds,
new TurretIOSimSpark(),
new FlywheelIOSimTalonFX(),
new HoodIOSimSpark());
feeder = new Feeder(new SpindexerIOSimSpark(), new KickerIOSimSpark());
intake =
new Intake(
new RollerIOSimTalonFX(RollerConstants.upperRollerConfig),
new RollerIOSimTalonFX(RollerConstants.lowerRollerConfig),
new IntakeArmIOSim());
// hopper = new Hopper(new HopperIOSim());
break;
case REPLAY: // Replaying a log
default:
// Set up replay source
setUseTiming(false); // Run as fast as possible
String logPath = LogFileUtil.findReplayLog();
Logger.setReplaySource(new WPILOGReader(logPath));
Logger.addDataReceiver(new WPILOGWriter(LogFileUtil.addPathSuffix(logPath, "_sim")));
// Disable IO implementations
drive =
new Drive(
new GyroIO() {},
new ModuleIO() {},
new ModuleIO() {},
new ModuleIO() {},
new ModuleIO() {});
vision =
new Vision(
drive::addVisionMeasurement,
drive::getPose,
new VisionIO() {},
new VisionIO() {},
new VisionIO() {},
new VisionIO() {});
launcher =
new Launcher(
drive::getPose,
drive::getRobotRelativeChassisSpeeds,
new TurretIO() {},
new FlywheelIO() {},
new HoodIO() {});
intake = new Intake(new RollerIO() {}, new RollerIO() {}, new IntakeArmIO() {});
// hopper = new Hopper(new HopperIO() {});
feeder = new Feeder(new SpindexerIO() {}, new KickerIO() {});
break;
}
// Start background threads (for non-blocking CAN/network reads)
SparkOdometryThread.getInstance().start();
VisionThread.getInstance().start();
CanandgyroThread.getInstance().start();
// Start AdvantageKit logger
Logger.start();
configureControlPanelBindings();
configureAutoOptions();
SmartDashboard.putData(
"Align Encoders",
new InstantCommand(() -> drive.zeroAbsoluteEncoders()).ignoringDisable(true));
SmartDashboard.putData(CommandScheduler.getInstance());
SmartDashboard.putData(drive);
SmartDashboard.putData(vision);
SmartDashboard.putData(launcher);
SmartDashboard.putData(feeder);
SmartDashboard.putData(intake);
SmartDashboard.putData("Field", field);
Field.plotRegions();
feeder.setDefaultCommand(Commands.startEnd(feeder::stop, () -> {}, feeder).withName("Stop"));
intake.setDefaultCommand(intake.getDefaultCommand());
// hopper.setDefaultCommand(hopper.getDefaultCommand());
launcher.setDefaultCommand(
launcher
.initializeHoodCommand()
.andThen(
new RunCommand(
() -> launcher.aim(GameState.getTarget(drive.getPose()).getTranslation()),
launcher)
.withName("Aim at hub")));
}
/** This function is called periodically during all modes. */
@Override
public void robotPeriodic() {
long loopStart = Constants.PROFILING_ENABLED ? System.nanoTime() : 0;
// Runs the Scheduler. This is responsible for polling buttons, adding
// newly-scheduled commands, running already-scheduled commands, removing
// finished or interrupted commands, and running subsystem periodic() methods.
// This must be called from the robot's periodic block in order for anything in
// the Command-based framework to work.
CommandScheduler.getInstance().run();
long t1 = Constants.PROFILING_ENABLED ? System.nanoTime() : 0;
GameState.logValues();
long t2 = Constants.PROFILING_ENABLED ? System.nanoTime() : 0;
// Profiling output
if (Constants.PROFILING_ENABLED) {
Logger.recordOutput("Profiling/Robot/SchedulerMs", (t1 - loopStart) / 1_000_000);
Logger.recordOutput("Profiling/Robot/GameStateMs", (t2 - t1) / 1_000_000);
Logger.recordOutput("Profiling/Robot/TotalMs", (t2 - loopStart) / 1_000_000);
}
// Return to non-RT thread priority (do not modify the first argument)
// Threads.setCurrentThreadPriority(false, 10);
}
/** This function is called once when the robot is disabled. */
@Override
public void disabledInit() {
leds.clear();
}
/** This function is called periodically when disabled. */
@Override
public void disabledPeriodic() {
allianceSelector.disabledPeriodic();
autoSelector.disabledPeriodic();
ControllerSelector.getInstance().scan(false);
leds.displayAutoSelection();
var autoOption = autoSelector.get();
autoOption.ifPresent(
a ->
a.getInitialPose()
.ifPresent(targetPose -> leds.displayPoseSeek(drive.getPose(), targetPose)));
}
/** This function is called once when autonomous mode is enabled. */
@Override
public void autonomousInit() {
drive.setDefaultCommand(Commands.runOnce(drive::stop, drive).withName("Stop"));
autoSelector.scheduleAuto();
leds.clear();
}
/** This function is called periodically during autonomous. */
@Override
public void autonomousPeriodic() {
leds.displayHubCountdown();
leds.displayRobotState(() -> launcher.isOnTarget(), () -> feeder.isSpinning());
}
/** This function is called once when teleop mode is enabled. */
@Override
public void teleopInit() {
autoSelector.cancelAuto();
ControllerSelector.getInstance().scan(true);
leds.clear();
}
/** This function is called periodically during operator control. */
@Override
public void teleopPeriodic() {
leds.displayHubCountdown();
leds.displayRobotState(() -> launcher.isOnTarget(), () -> feeder.isSpinning());
}
/** This function is called once when test mode is enabled. */
@Override
public void testInit() {
// Cancels all running commands at the start of test mode.
CommandScheduler.getInstance().cancelAll();
leds.clear();
}
/** This function is called periodically during test mode. */
@Override
public void testPeriodic() {
leds.displayHubCountdown();
leds.displayRobotState(() -> launcher.isOnTarget(), () -> feeder.isSpinning());
}
/** This function is called once when the robot is first started up. */
@Override
public void simulationInit() {
leds.clear();
}
/** This function is called periodically whilst in simulation. */
@Override
public void simulationPeriodic() {
leds.displayHubCountdown();
leds.displayRobotState(() -> launcher.isOnTarget(), () -> feeder.isSpinning());
}
private void configureControlPanelBindings() {
ControllerSelector.configure(
// ZORRO is always preferred as driver in REAL and SIM mode
new DriverConfig(
ControllerType.ZORRO, this::bindZorroDriver, Constants.Mode.REAL, Constants.Mode.SIM),
// XBOX is always preferred as operator in REAL and SIM mode
new OperatorConfig(
ControllerType.XBOX, this::bindXboxOperator, Constants.Mode.REAL, Constants.Mode.SIM),
// XBOX is permitted as driver in REAL and SIM mode
new DriverConfig(
ControllerType.XBOX, this::bindXboxDriver, Constants.Mode.REAL, Constants.Mode.SIM));
}
public DriverController bindZorroDriver(int port) {
var zorroDriver = new CommandZorroController(port);
var controller =
new DriverController() {
public double getXTranslationInput() {
return -zorroDriver.getRightYAxis();
}
public double getYTranslationInput() {
return -zorroDriver.getRightXAxis();
}
public double getRotationInput() {
return -zorroDriver.getLeftXAxis();
}
public boolean getFieldRelativeInput() {
return zorroDriver.getHID().getEUp();
}
};
// Drive in field-relative mode while switch E is up
// Drive in robot-relative mode while switch E is down
drive.setDefaultCommand(
DriveCommands.joystickDrive(
drive,
() -> controller.getXTranslationInput(),
() -> controller.getYTranslationInput(),
() -> controller.getRotationInput(),
() -> controller.getFieldRelativeInput(),
allianceSelector::fieldRotated));
// Reset gyro to 0° when button G is pressed
zorroDriver
.GIn()
.onTrue(
Commands.runOnce(
() ->
drive.resetHeading(
allianceSelector.fieldRotated()
? Rotation2d.k180deg
: Rotation2d.kZero),
drive)
.ignoringDisable(true));
// Switch to X pattern when button D is pressed
// zorroDriver.DIn().onTrue(Commands.runOnce(drive::stopWithX, drive));
// Desaturate turret and advance feeder
zorroDriver.AIn().whileTrue(createDesaturateAndShootCommand(controller));
// Launcher
Trigger launcherEnabled = zorroDriver.axisGreaterThan(Axis.kLeftDial.value, 0.5).debounce(0.1);
launcherEnabled
.or(() -> DriverStation.isFMSAttached())
.whileTrue(
launcher
.initializeHoodCommand()
.andThen(
new RunCommand(
() ->
launcher.aim(GameState.getTarget(drive.getPose()).getTranslation()),
launcher)
.withName("Aim at hub")));
// Intake
zorroDriver.HIn().whileTrue(intake.getDeployCommand());
// zorroDriver.HIn().and(() -> hopper.isDeployed()).onTrue(intake.getDeployCommand());
// zorroDriver.HIn().negate().and(() -> hopper.isDeployed()).onTrue(intake.getDefaultCommand());
// Hopper
// zorroDriver
// .FDown()
// .onTrue(Commands.startEnd(hopper::deploy, () -> {}, hopper).withName("Deploy"));
// zorroDriver
// .FUp()
// .onTrue(
// new ConditionalCommand(
// // If intake is stowed, immediately retract hopper
// hopper.getDefaultCommand(),
// // If intake is deployed, retract it first before retracting hopper
// Commands.parallel(
// intake.getDefaultCommand(),
//
// hopper.idle().withTimeout(Seconds.of(2)).andThen(hopper.getDefaultCommand())),
// // Condition to check
// () -> intake.isStowed()));
return controller;
}
public DriverController bindXboxDriver(int port) {
var xboxDriver = new CommandXboxController(port);
var controller =
new DriverController() {
public double getXTranslationInput() {
return -xboxDriver.getLeftY();
}
public double getYTranslationInput() {
return -xboxDriver.getLeftX();
}
public double getRotationInput() {
return -xboxDriver.getRightX();
}
public boolean getFieldRelativeInput() {
return !xboxDriver.getHID().getLeftBumperButton();
}
};
// Drive in field-relative mode while left bumper is released
// Drive in robot-relative mode while left bumper is pressed
drive.setDefaultCommand(
DriveCommands.joystickDrive(
drive,
() -> controller.getXTranslationInput(),
() -> controller.getYTranslationInput(),
() -> controller.getRotationInput(),
() -> controller.getFieldRelativeInput(),
allianceSelector::fieldRotated));
// Reset gyro to 0° when B button is pressed
xboxDriver
.b()
.onTrue(
Commands.runOnce(
() ->
drive.resetHeading(
allianceSelector.fieldRotated()
? Rotation2d.k180deg
: Rotation2d.kZero),
drive)
.ignoringDisable(true));
// xboxDriver
// .a()
// .whileTrue(
// Commands.run(() -> launcher.aim(GameState.getMyHubPose().getTranslation()), launcher)
// .withName("Aim at hub"));
// xboxDriver
// .y()
// .whileTrue(
// Commands.run(() -> launcher.aim(GameState.getFieldTarget().getTranslation()),
// launcher)
// .withName("Aim at Target"));
// // Point at Hub while A button is held
// xboxDriver
// .a()
// .whileTrue(
// DriveCommands.joystickDriveAtFixedOrientation(
// drive,
// () -> -xboxDriver.getLeftY(),
// () -> -xboxDriver.getLeftX(),
// () ->
// GameState.getMyHubPose()
// .toPose2d()
// .getTranslation()
// .minus(drive.getPose().getTranslation())
// .getAngle(),
// allianceSelector::fieldRotated));
// // Point in the direction of the commanded translation while Y button is held
// xboxDriver
// .y()
// .whileTrue(
// DriveCommands.joystickDrivePointedForward(
// drive,
// () -> -xboxDriver.getLeftY(),
// () -> -xboxDriver.getLeftX(),
// allianceSelector::fieldRotated));
// Point at vision target while A button is held
// xboxDriver
// .a()
// .whileTrue(
// DriveCommands.pointAtTarget(
// drive, () -> vision.getTargetX(0), allianceSelector::fieldRotated));
// Drive 1m forward while A button is held
// xboxDriver.a().whileTrue(PathCommands.advanceForward(drive, Meters.of(1)));
// Align with pose, approaching in correct orientation from 1 m away
// xboxDriver
// .a()
// .whileTrue(
// PathCommands.dockToTargetPose(
// drive, new Pose2d(8.2296, 4.1148, Rotation2d.kZero), Meters.of(1)));
// Drive to point, approaching in correct orientation from 2 m away
// xboxDriver
// .a()
// .whileTrue(
// PathCommands.dockToTargetPoint(drive, new Translation2d(8.2296, 4.1148), Meters.of(2)));
// Switch to X pattern when X button is pressed
xboxDriver.x().onTrue(Commands.runOnce(drive::stopWithX, drive));
return controller;
}
public void bindXboxOperator(int port, DriverController driver) {
var xboxOperator = new CommandXboxController(port);
// Intake
xboxOperator.b().whileTrue(intake.getDeployCommand());
// xboxOperator.b().and(() -> hopper.isDeployed()).whileTrue(intake.getDeployCommand());
xboxOperator.y().whileTrue(intake.getReverseCommand());
// xboxOperator.y().and(() -> hopper.isDeployed()).whileTrue(intake.getReverseCommand());
// Feeder
xboxOperator
.a()
.whileTrue(Commands.startEnd(feeder::spinForward, () -> {}, feeder).withName("Advance"));
xboxOperator
.x()
.whileTrue(Commands.startEnd(feeder::reverse, () -> {}, feeder).withName("Reverse"));
// Desaturate turret and advance feeder
xboxOperator.rightBumper().whileTrue(createDesaturateAndShootCommand(driver));
}
public void configureAutoOptions() {
autoSelector.addAuto(
new AutoOption(Alliance.Blue, 1, new B_LeftTrenchAuto(drive, feeder, intake, launcher)));
autoSelector.addAuto(
new AutoOption(Alliance.Red, 1, new R_LeftTrenchAuto(drive, feeder, intake, launcher)));
autoSelector.addAuto(
new AutoOption(Alliance.Blue, 2, new B_RightTrenchAuto(drive, feeder, intake, launcher)));
autoSelector.addAuto(
new AutoOption(Alliance.Red, 2, new R_RightTrenchAuto(drive, feeder, intake, launcher)));
autoSelector.addAuto(
new AutoOption(
Alliance.Blue, 3, new B_LeftTrenchMoveFirstAuto(drive, feeder, intake, launcher)));
autoSelector.addAuto(
new AutoOption(
Alliance.Red, 3, new R_LeftTrenchMoveFirstAuto(drive, feeder, intake, launcher)));
autoSelector.addAuto(
new AutoOption(
Alliance.Blue, 4, new B_RightTrenchMoveFirstAuto(drive, feeder, intake, launcher)));
autoSelector.addAuto(
new AutoOption(
Alliance.Red, 4, new R_RightTrenchMoveFirstAuto(drive, feeder, intake, launcher)));
}
public static Alliance getAlliance() {
return allianceSelector.getAllianceColor();
}
private Command createDesaturateAndShootCommand(DriverController driver) {
return Commands.parallel(
DriveCommands.joystickDrive(
drive,
driver::getXTranslationInput,
driver::getYTranslationInput,
// launcher::desaturateTurret,
() -> {
if (launcher.isTurretDesaturated()) {
return driver.getRotationInput();
} else {
return launcher.getTurretDesaturationDelta();
}
},
driver::getFieldRelativeInput,
allianceSelector::fieldRotated)
.withName("Desaturate turret"),
Commands.sequence(
Commands.waitUntil(launcher::isTurretDesaturated),
Commands.startEnd(feeder::spinForward, () -> {}, feeder).withName("Advance")));
}
}