Skip to content

Commit

Permalink
Added controller limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
honzikschenk committed Mar 31, 2023
1 parent 79b84d2 commit 5417986
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ public static final class DriveConstants {

public static final SimpleMotorFeedforward driveFF = new SimpleMotorFeedforward(0.254, 0.137);

public static final double maxDriveSpeed = 14.4;
public static final double maxTurnRate = 2 * Math.PI;
public static final double maxDriveSpeed = 3;
public static final double maxTurnRate = Math.PI;

public static final double driveJoystickDeadbandPercent = 0.075;
public static final double driveMaxJerk = 200.0;
public static final double driveMaxJerk = 100.0;

}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ private void configureSubsystems() {
() -> -rightStick.getRawAxis(0),
true
));
SmartDashboard.putNumber("Controller Reduction", 1);

//index.setDefaultCommand(new Waiting(index));
shooter.setDefaultCommand(
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/frc/robot/commands/DriveWithJoysticks.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class DriveWithJoysticks extends CommandBase {
private final AxisProcessor yProcessor = new AxisProcessor(false);
private final AxisProcessor omegaProcessor = new AxisProcessor(true);

private double controllerReduction = 0.1;

/** Creates a new DriveWithJoysticks. */
public DriveWithJoysticks(Drive drive, DoubleSupplier xPercent, DoubleSupplier yPercent, DoubleSupplier omegaPercent, boolean fieldRelative) {
this.drive = drive;
Expand All @@ -47,9 +49,10 @@ public void initialize() {
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
double xMPerS = xProcessor.processJoystickInputs(xPercent.getAsDouble() * 0.75) * DriveConstants.maxDriveSpeed;
double yMPerS = yProcessor.processJoystickInputs(yPercent.getAsDouble() * 0.75) * DriveConstants.maxDriveSpeed;
double omegaRadPerS = omegaProcessor.processJoystickInputs(omegaPercent.getAsDouble()) * DriveConstants.maxTurnRate;
controllerReduction = SmartDashboard.getNumber("Controller Reduction", controllerReduction);
double xMPerS = xProcessor.processJoystickInputs(xPercent.getAsDouble() * 0.75) * DriveConstants.maxDriveSpeed * controllerReduction;
double yMPerS = yProcessor.processJoystickInputs(yPercent.getAsDouble() * 0.75) * DriveConstants.maxDriveSpeed * controllerReduction;
double omegaRadPerS = omegaProcessor.processJoystickInputs(omegaPercent.getAsDouble()) * DriveConstants.maxTurnRate * controllerReduction;

SmartDashboard.putNumber("XMPerS", xMPerS);

Expand Down

0 comments on commit 5417986

Please sign in to comment.