Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/main/java/org/team2342/frc/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,14 +38,18 @@
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;
@Getter private final Vision vision;

private final LoggedDashboardChooser<Command> 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);

Expand Down
10 changes: 2 additions & 8 deletions src/main/java/org/team2342/frc/commands/DriveCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
89 changes: 89 additions & 0 deletions src/main/java/org/team2342/lib/util/EnhancedXboxController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// 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;
import lombok.Getter;
import lombok.Setter;

/** 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.
*/
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);
}
}