Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Origin/feature/acceleration limiter #2

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 3 additions & 20 deletions src/main/java/frc/robot/commands/DriveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,26 +94,9 @@ public void execute() {
double absoluteNextThetaSpeed = Math.abs(nextThetaSpeed);

// Apply global deadband.
if (
absoluteNextXSpeed < DriveCommand.X_DEADBAND &&
absoluteNextYSpeed < DriveCommand.Y_DEADBAND &&
absoluteNextThetaSpeed < DriveCommand.THETA_DEADBAND
) {

nextXSpeed = 0;
nextYSpeed = 0;
nextThetaSpeed = 0;

} else {

// Enforce maximum change in acceleration.
nextXSpeed = ControlsUtilities.enforceMaximumPositiveDelta(currentXSpeed, nextXSpeed, X_MAX_ACCELERATION);
nextYSpeed = ControlsUtilities.enforceMaximumPositiveDelta(currentYSpeed, nextYSpeed, Y_MAX_ACCELERATION);
nextThetaSpeed = ControlsUtilities.enforceMaximumPositiveDelta(currentThetaSpeed, nextThetaSpeed, THETA_MAX_ACCELERATION);

}


nextXSpeed = absoluteNextXSpeed < DriveCommand.X_DEADBAND ? 0 : ControlsUtilities.enforceMaximumPositiveDelta(currentXSpeed, nextXSpeed, X_MAX_ACCELERATION);
ActualSkinwalker marked this conversation as resolved.
Show resolved Hide resolved
nextYSpeed = absoluteNextYSpeed < DriveCommand.Y_DEADBAND ? 0 : ControlsUtilities.enforceMaximumPositiveDelta(currentYSpeed, nextYSpeed, Y_MAX_ACCELERATION);
nextThetaSpeed = absoluteNextThetaSpeed < DriveCommand.THETA_DEADBAND ? 0 : ControlsUtilities.enforceMaximumPositiveDelta(currentThetaSpeed, nextThetaSpeed, THETA_MAX_ACCELERATION);

this.speedMultiplier = slowMode.getAsBoolean() ? 0.25 : 1;

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/frc/robot/util/ControlsUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ public static double applyDeadband(double input, double deadband) {
return Math.abs(input) < deadband ? 0 : input;

}

public static double applyCircularDeadband (double xInput, double yInput, double deadband, boolean valueToRetrieve) {

double hypotenuse = Math.sqrt(Math.pow(xInput, 2) + Math.pow(yInput, 2));

if (Math.abs(hypotenuse) < deadband) {
if (valueToRetrieve) return xInput;
ActualSkinwalker marked this conversation as resolved.
Show resolved Hide resolved
else return yInput;
}

else return 0;
}

/**
* Returns the new value so long as its delta from the old value does not
Expand Down