From 98006dbb415d54350bf963dd67ce417b067a95d8 Mon Sep 17 00:00:00 2001 From: Luddo183 <93882319+Luddo183@users.noreply.github.com> Date: Thu, 4 Dec 2025 09:08:57 -0500 Subject: [PATCH 1/3] basic enhanced controller class added deadband, rumble command --- .../java/org/team2342/frc/RobotContainer.java | 7 ++- .../team2342/frc/commands/DriveCommands.java | 10 +--- .../lib/util/EnhancedXboxController.java | 55 +++++++++++++++++++ 3 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 src/main/java/org/team2342/lib/util/EnhancedXboxController.java diff --git a/src/main/java/org/team2342/frc/RobotContainer.java b/src/main/java/org/team2342/frc/RobotContainer.java index c61e90b..e299e4d 100644 --- a/src/main/java/org/team2342/frc/RobotContainer.java +++ b/src/main/java/org/team2342/frc/RobotContainer.java @@ -18,7 +18,6 @@ import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.Commands; -import edu.wpi.first.wpilibj2.command.button.CommandXboxController; import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine; import lombok.Getter; import org.littletonrobotics.junction.inputs.LoggedPowerDistribution; @@ -39,6 +38,7 @@ import org.team2342.frc.subsystems.vision.VisionIO; import org.team2342.frc.subsystems.vision.VisionIOPhoton; import org.team2342.frc.subsystems.vision.VisionIOSim; +import org.team2342.lib.util.EnhancedXboxController; public class RobotContainer { @Getter private final Drive drive; @@ -46,7 +46,10 @@ public class RobotContainer { private final LoggedDashboardChooser autoChooser; - @Getter private final CommandXboxController driverController = new CommandXboxController(0); + @Getter + private final EnhancedXboxController driverController = + new EnhancedXboxController(0, DriveConstants.CONTROLLER_DEADBAND); + private final Alert driverControllerAlert = new Alert("Driver controller is disconnected!", AlertType.kError); diff --git a/src/main/java/org/team2342/frc/commands/DriveCommands.java b/src/main/java/org/team2342/frc/commands/DriveCommands.java index 2210ec6..bafcc35 100644 --- a/src/main/java/org/team2342/frc/commands/DriveCommands.java +++ b/src/main/java/org/team2342/frc/commands/DriveCommands.java @@ -7,7 +7,6 @@ package org.team2342.frc.commands; -import edu.wpi.first.math.MathUtil; import edu.wpi.first.math.controller.ProfiledPIDController; import edu.wpi.first.math.filter.SlewRateLimiter; import edu.wpi.first.math.geometry.Pose2d; @@ -44,9 +43,7 @@ public class DriveCommands { private DriveCommands() {} public static Translation2d getLinearVelocityFromJoysticks(double x, double y) { - // Apply deadband - double linearMagnitude = - MathUtil.applyDeadband(Math.hypot(x, y), DriveConstants.CONTROLLER_DEADBAND); + double linearMagnitude = Math.hypot(x, y); Rotation2d linearDirection = new Rotation2d(Math.atan2(y, x)); // Square magnitude for more precise control @@ -72,10 +69,7 @@ public static Command joystickDrive( Translation2d linearVelocity = getLinearVelocityFromJoysticks(xSupplier.getAsDouble(), ySupplier.getAsDouble()); - // Apply rotation deadband - double omega = - MathUtil.applyDeadband( - omegaSupplier.getAsDouble(), DriveConstants.CONTROLLER_DEADBAND); + double omega = omegaSupplier.getAsDouble(); // Square rotation value for more precise control omega = Math.copySign(omega * omega, omega); diff --git a/src/main/java/org/team2342/lib/util/EnhancedXboxController.java b/src/main/java/org/team2342/lib/util/EnhancedXboxController.java new file mode 100644 index 0000000..3a69525 --- /dev/null +++ b/src/main/java/org/team2342/lib/util/EnhancedXboxController.java @@ -0,0 +1,55 @@ +// Copyright (c) 2025 Team 2342 +// https://github.com/FRCTeamPhoenix +// +// This source code is licensed under the MIT License. +// See the LICENSE file in the root directory of this project. + +package org.team2342.lib.util; + +import edu.wpi.first.math.MathUtil; +import edu.wpi.first.wpilibj.GenericHID.RumbleType; +import edu.wpi.first.wpilibj2.command.Command; +import edu.wpi.first.wpilibj2.command.Commands; +import edu.wpi.first.wpilibj2.command.button.CommandXboxController; + +public class EnhancedXboxController extends CommandXboxController { + private double deadband; + + public EnhancedXboxController(int port, double deadband) { + super(port); + } + + public EnhancedXboxController(int port) { + this(port, 0); + } + + public Command rumble(RumbleType type, double intensity) { + return Commands.startEnd( + () -> super.setRumble(type, intensity), () -> super.setRumble(type, 0.0)); + } + + public Command timedRumble(RumbleType type, double intensity, double seconds) { + return Commands.runEnd(() -> super.setRumble(type, intensity), () -> super.setRumble(type, 0.0)) + .withTimeout(seconds); + } + + @Override + public double getLeftX() { + return MathUtil.applyDeadband(super.getLeftX(), deadband); + } + + @Override + public double getLeftY() { + return MathUtil.applyDeadband(super.getLeftY(), deadband); + } + + @Override + public double getRightX() { + return MathUtil.applyDeadband(super.getRightX(), deadband); + } + + @Override + public double getRightY() { + return MathUtil.applyDeadband(super.getRightY(), deadband); + } +} From 08fe313c75949f21132f09420ba296520b0008ca Mon Sep 17 00:00:00 2001 From: Luddo183 <93882319+Luddo183@users.noreply.github.com> Date: Mon, 8 Dec 2025 08:42:59 -0500 Subject: [PATCH 2/3] comments --- .../lib/util/EnhancedXboxController.java | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/team2342/lib/util/EnhancedXboxController.java b/src/main/java/org/team2342/lib/util/EnhancedXboxController.java index 3a69525..61abe8b 100644 --- a/src/main/java/org/team2342/lib/util/EnhancedXboxController.java +++ b/src/main/java/org/team2342/lib/util/EnhancedXboxController.java @@ -11,43 +11,90 @@ import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.Commands; import edu.wpi.first.wpilibj2.command.button.CommandXboxController; +import lombok.Getter; +import lombok.Setter; +/** + * Extended {@link CommandXboxController} class + */ public class EnhancedXboxController extends CommandXboxController { - private double deadband; + + @Getter @Setter private double deadband; + + /** + * Construct an instance of a controller. + * + * @param port The port index on the Driver Station that the controller is plugged into. + * @param deadband The deadband that will be applied to the controller sticks. + */ public EnhancedXboxController(int port, double deadband) { super(port); } + /** + * Construct an instance of a controller with no deadband. + * + * @param port The port index on the Driver Station that the controller is plugged into. + */ public EnhancedXboxController(int port) { this(port, 0); } + /** + * Set the rumble output for the controller. + * + * @param type Which rumble value to set + * @param intensity The normalized value (0 to 1) to set the rumble to + * + * @return A command to rumble the controller + */ public Command rumble(RumbleType type, double intensity) { return Commands.startEnd( () -> super.setRumble(type, intensity), () -> super.setRumble(type, 0.0)); } + /** + * Set the rumble output for the controller with a specified timeout. + * + * @param type Which rumble value to set + * @param intensity The normalized value (0 to 1) to set the rumble to + * @param seconds The length of time to rumble the controller for in seconds + * + * @return A command to rumble the controller for the specifed time + */ public Command timedRumble(RumbleType type, double intensity, double seconds) { return Commands.runEnd(() -> super.setRumble(type, intensity), () -> super.setRumble(type, 0.0)) .withTimeout(seconds); } + /** + * Get the deadbanded X axis value of left side of the controller. Right is positive. + */ @Override public double getLeftX() { return MathUtil.applyDeadband(super.getLeftX(), deadband); } + /** + * Get the deadbanded Y axis value of left side of the controller. Back is positive. + */ @Override public double getLeftY() { return MathUtil.applyDeadband(super.getLeftY(), deadband); } + /** + * Get the deadbanded X axis value of right side of the controller. Right is positive. + */ @Override public double getRightX() { return MathUtil.applyDeadband(super.getRightX(), deadband); } + /** + * Get the deadbanded Y axis value of right side of the controller. Back is positive. + */ @Override public double getRightY() { return MathUtil.applyDeadband(super.getRightY(), deadband); From 29e4cdf8426e67af72258ff4652671ac563b53fc Mon Sep 17 00:00:00 2001 From: Phoenix2342-Bot Date: Mon, 8 Dec 2025 13:46:08 +0000 Subject: [PATCH 3/3] Auto-format code --- .../lib/util/EnhancedXboxController.java | 33 ++++++------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/team2342/lib/util/EnhancedXboxController.java b/src/main/java/org/team2342/lib/util/EnhancedXboxController.java index 61abe8b..3934488 100644 --- a/src/main/java/org/team2342/lib/util/EnhancedXboxController.java +++ b/src/main/java/org/team2342/lib/util/EnhancedXboxController.java @@ -14,25 +14,22 @@ import lombok.Getter; import lombok.Setter; -/** - * Extended {@link CommandXboxController} class - */ +/** Extended {@link CommandXboxController} class */ public class EnhancedXboxController extends CommandXboxController { - + @Getter @Setter private double deadband; - /** + /** * Construct an instance of a controller. * * @param port The port index on the Driver Station that the controller is plugged into. * @param deadband The deadband that will be applied to the controller sticks. */ - public EnhancedXboxController(int port, double deadband) { super(port); } - /** + /** * Construct an instance of a controller with no deadband. * * @param port The port index on the Driver Station that the controller is plugged into. @@ -41,12 +38,11 @@ public EnhancedXboxController(int port) { this(port, 0); } - /** + /** * Set the rumble output for the controller. * * @param type Which rumble value to set * @param intensity The normalized value (0 to 1) to set the rumble to - * * @return A command to rumble the controller */ public Command rumble(RumbleType type, double intensity) { @@ -54,13 +50,12 @@ public Command rumble(RumbleType type, double intensity) { () -> super.setRumble(type, intensity), () -> super.setRumble(type, 0.0)); } - /** + /** * Set the rumble output for the controller with a specified timeout. * * @param type Which rumble value to set * @param intensity The normalized value (0 to 1) to set the rumble to * @param seconds The length of time to rumble the controller for in seconds - * * @return A command to rumble the controller for the specifed time */ public Command timedRumble(RumbleType type, double intensity, double seconds) { @@ -68,33 +63,25 @@ public Command timedRumble(RumbleType type, double intensity, double seconds) { .withTimeout(seconds); } - /** - * Get the deadbanded X axis value of left side of the controller. Right is positive. - */ + /** Get the deadbanded X axis value of left side of the controller. Right is positive. */ @Override public double getLeftX() { return MathUtil.applyDeadband(super.getLeftX(), deadband); } - /** - * Get the deadbanded Y axis value of left side of the controller. Back is positive. - */ + /** Get the deadbanded Y axis value of left side of the controller. Back is positive. */ @Override public double getLeftY() { return MathUtil.applyDeadband(super.getLeftY(), deadband); } - /** - * Get the deadbanded X axis value of right side of the controller. Right is positive. - */ + /** Get the deadbanded X axis value of right side of the controller. Right is positive. */ @Override public double getRightX() { return MathUtil.applyDeadband(super.getRightX(), deadband); } - /** - * Get the deadbanded Y axis value of right side of the controller. Back is positive. - */ + /** Get the deadbanded Y axis value of right side of the controller. Back is positive. */ @Override public double getRightY() { return MathUtil.applyDeadband(super.getRightY(), deadband);