mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[wpimath] Move RobotDriveBase::ApplyDeadband() to MathUtil (#3529)
It's a useful function outside of the drive classes. For backwards compatibility, deprecate (rather than remove) RobotDriveBase.applyDeadband()
This commit is contained in:
@@ -33,6 +33,26 @@ public final class MathUtil {
|
||||
return Math.max(low, Math.min(value, high));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 0.0 if the given value is within the specified range around zero. The remaining range
|
||||
* between the deadband and 1.0 is scaled from 0.0 to 1.0.
|
||||
*
|
||||
* @param value Value to clip.
|
||||
* @param deadband Range around zero.
|
||||
* @return The value after the deadband is applied.
|
||||
*/
|
||||
public static double applyDeadband(double value, double deadband) {
|
||||
if (Math.abs(value) > deadband) {
|
||||
if (value > 0.0) {
|
||||
return (value - deadband) / (1.0 - deadband);
|
||||
} else {
|
||||
return (value + deadband) / (1.0 - deadband);
|
||||
}
|
||||
} else {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns modulus of input.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user