Skip to content

Commit 5365eba

Browse files
better controller bindings
1 parent 3fe21bd commit 5365eba

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

src/main/java/frc/robot/RobotContainer.java

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import com.pathplanner.lib.auto.AutoBuilder;
66
import com.pathplanner.lib.auto.NamedCommands;
7-
import edu.wpi.first.math.MathUtil;
87
import edu.wpi.first.math.geometry.Pose2d;
98
import edu.wpi.first.math.geometry.Rotation2d;
109
import edu.wpi.first.math.geometry.Transform2d;
@@ -64,10 +63,11 @@
6463
import frc.robot.subsystems.vision.CameraIOPhotonVision;
6564
import frc.robot.subsystems.vision.CameraIOSim;
6665
import frc.robot.subsystems.vision.VisionConstants;
66+
import frc.robot.utility.JoystickUtil;
6767
import frc.robot.utility.OverrideSwitch;
6868
import frc.robot.utility.commands.CustomCommands;
6969
import java.util.Arrays;
70-
import java.util.function.DoubleSupplier;
70+
import java.util.function.BiConsumer;
7171
import org.littletonrobotics.junction.networktables.LoggedDashboardChooser;
7272

7373
/**
@@ -398,10 +398,17 @@ private void configureDriverControllerBindings(
398398
.ignoringDisable(true)
399399
.withName("Reset Gyro Heading"));
400400

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));
405412

406413
if (includeAutoAlign) {
407414
// Align to reef
@@ -483,34 +490,35 @@ private void configureOperatorControllerBindings(CommandXboxController xbox) {
483490
xbox.rightTrigger().and(xbox.a().negate()).whileTrue(superstructure.outtake());
484491
xbox.rightTrigger().and(xbox.a()).whileTrue(superstructure.outtakeL1());
485492

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+
};
489497

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);
491502

492503
xbox.povDown().onTrue(superstructure.stowLow());
493504

505+
// Intake
506+
494507
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()))));
495513

496514
// 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()))));
503516

504517
xbox.rightBumper().and(xbox.leftBumper().negate()).onTrue(hang.deploy());
505518
xbox.leftBumper().and(xbox.rightBumper().negate()).onTrue(hang.retract());
506519
xbox.rightBumper().and(xbox.leftBumper()).onTrue(hang.stow());
507520
}
508521

509-
private void configureOperatorControllerBindingLevel(
510-
Trigger trigger, Superstructure.State state) {
511-
trigger.whileTrue(superstructure.run(state));
512-
}
513-
514522
private Command rumbleController(CommandXboxController controller, double rumbleIntensity) {
515523
return Commands.startEnd(
516524
() -> controller.setRumble(RumbleType.kBothRumble, rumbleIntensity),

src/main/java/frc/robot/utility/JoystickUtil.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ public static double applySimpleDeadband(double value, double deadband) {
1616
public static double applyDeadband(double value) {
1717
return MathUtil.applyDeadband(value, JOYSTICK_DEADBAND);
1818
}
19+
20+
public static boolean isDeadband(double value) {
21+
return Math.abs(value) < JOYSTICK_DEADBAND;
22+
}
1923
}

0 commit comments

Comments
 (0)