|
4 | 4 |
|
5 | 5 | import com.pathplanner.lib.auto.AutoBuilder; |
6 | 6 | import com.pathplanner.lib.auto.NamedCommands; |
7 | | -import edu.wpi.first.math.MathUtil; |
8 | 7 | import edu.wpi.first.math.geometry.Pose2d; |
9 | 8 | import edu.wpi.first.math.geometry.Rotation2d; |
10 | 9 | import edu.wpi.first.math.geometry.Transform2d; |
|
64 | 63 | import frc.robot.subsystems.vision.CameraIOPhotonVision; |
65 | 64 | import frc.robot.subsystems.vision.CameraIOSim; |
66 | 65 | import frc.robot.subsystems.vision.VisionConstants; |
| 66 | +import frc.robot.utility.JoystickUtil; |
67 | 67 | import frc.robot.utility.OverrideSwitch; |
68 | 68 | import frc.robot.utility.commands.CustomCommands; |
69 | 69 | import java.util.Arrays; |
70 | | -import java.util.function.DoubleSupplier; |
| 70 | +import java.util.function.BiConsumer; |
71 | 71 | import org.littletonrobotics.junction.networktables.LoggedDashboardChooser; |
72 | 72 |
|
73 | 73 | /** |
@@ -398,10 +398,17 @@ private void configureDriverControllerBindings( |
398 | 398 | .ignoringDisable(true) |
399 | 399 | .withName("Reset Gyro Heading")); |
400 | 400 |
|
401 | | - xbox.povRight().whileTrue(ManualAlignCommands.alignToSourceRight(drive, input)); |
402 | | - xbox.povLeft().whileTrue(ManualAlignCommands.alignToSourceLeft(drive, input)); |
403 | | - xbox.povUp().whileTrue(ManualAlignCommands.alignToCage(drive, input)); |
404 | | - xbox.povDown().whileTrue(ManualAlignCommands.alignToReef(drive, input)); |
| 401 | + final BiConsumer<Trigger, Command> configureAlignmentAuto = |
| 402 | + (trigger, command) -> { |
| 403 | + trigger.onTrue(command.until(() -> input.getOmegaRadiansPerSecond() != 0)); |
| 404 | + }; |
| 405 | + |
| 406 | + configureAlignmentAuto.accept( |
| 407 | + xbox.povRight(), ManualAlignCommands.alignToSourceRight(drive, input)); |
| 408 | + configureAlignmentAuto.accept( |
| 409 | + xbox.povLeft(), ManualAlignCommands.alignToSourceLeft(drive, input)); |
| 410 | + configureAlignmentAuto.accept(xbox.povUp(), ManualAlignCommands.alignToCage(drive, input)); |
| 411 | + configureAlignmentAuto.accept(xbox.povDown(), ManualAlignCommands.alignToReef(drive, input)); |
405 | 412 |
|
406 | 413 | if (includeAutoAlign) { |
407 | 414 | // Align to reef |
@@ -483,34 +490,35 @@ private void configureOperatorControllerBindings(CommandXboxController xbox) { |
483 | 490 | xbox.rightTrigger().and(xbox.a().negate()).whileTrue(superstructure.outtake()); |
484 | 491 | xbox.rightTrigger().and(xbox.a()).whileTrue(superstructure.outtakeL1()); |
485 | 492 |
|
486 | | - configureOperatorControllerBindingLevel(xbox.y(), Superstructure.State.L4); |
487 | | - configureOperatorControllerBindingLevel(xbox.x(), Superstructure.State.L3); |
488 | | - configureOperatorControllerBindingLevel(xbox.a(), Superstructure.State.L2); |
| 493 | + final BiConsumer<Trigger, Superstructure.State> configureOperatorControllerBindingLevel = |
| 494 | + (trigger, level) -> { |
| 495 | + trigger.whileTrue(superstructure.run(level)); |
| 496 | + }; |
489 | 497 |
|
490 | | - configureOperatorControllerBindingLevel(xbox.b(), Superstructure.State.L1); |
| 498 | + configureOperatorControllerBindingLevel.accept(xbox.y(), Superstructure.State.L4); |
| 499 | + configureOperatorControllerBindingLevel.accept(xbox.x(), Superstructure.State.L3); |
| 500 | + configureOperatorControllerBindingLevel.accept(xbox.a(), Superstructure.State.L2); |
| 501 | + configureOperatorControllerBindingLevel.accept(xbox.b(), Superstructure.State.L1); |
491 | 502 |
|
492 | 503 | xbox.povDown().onTrue(superstructure.stowLow()); |
493 | 504 |
|
| 505 | + // Intake |
| 506 | + |
494 | 507 | coralIntake.setDefaultCommand(superstructure.passiveIntake()); |
| 508 | + new Trigger(() -> !JoystickUtil.isDeadband(xbox.getLeftX())) |
| 509 | + .and(DriverStation::isTeleopEnabled) |
| 510 | + .whileTrue( |
| 511 | + Commands.run( |
| 512 | + () -> coralIntake.setMotors(JoystickUtil.applyDeadband(xbox.getRightX())))); |
495 | 513 |
|
496 | 514 | // Hang |
497 | | - hang.setDefaultCommand(hang.run(() -> hang.set(MathUtil.applyDeadband(xbox.getLeftX(), 0.2)))); |
498 | | - |
499 | | - DoubleSupplier hangSpeed = () -> MathUtil.applyDeadband(xbox.getRightX(), 0.2); |
500 | | - new Trigger(() -> hangSpeed.getAsDouble() != 0) |
501 | | - .and(DriverStation::isTeleopEnabled) |
502 | | - .whileTrue(Commands.run(() -> hang.set(hangSpeed.getAsDouble()))); |
| 515 | + hang.setDefaultCommand(hang.run(() -> hang.set(JoystickUtil.applyDeadband(xbox.getLeftX())))); |
503 | 516 |
|
504 | 517 | xbox.rightBumper().and(xbox.leftBumper().negate()).onTrue(hang.deploy()); |
505 | 518 | xbox.leftBumper().and(xbox.rightBumper().negate()).onTrue(hang.retract()); |
506 | 519 | xbox.rightBumper().and(xbox.leftBumper()).onTrue(hang.stow()); |
507 | 520 | } |
508 | 521 |
|
509 | | - private void configureOperatorControllerBindingLevel( |
510 | | - Trigger trigger, Superstructure.State state) { |
511 | | - trigger.whileTrue(superstructure.run(state)); |
512 | | - } |
513 | | - |
514 | 522 | private Command rumbleController(CommandXboxController controller, double rumbleIntensity) { |
515 | 523 | return Commands.startEnd( |
516 | 524 | () -> controller.setRumble(RumbleType.kBothRumble, rumbleIntensity), |
|
0 commit comments