mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +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:
@@ -170,8 +170,8 @@ public class DifferentialDrive extends RobotDriveBase implements Sendable, AutoC
|
||||
m_reported = true;
|
||||
}
|
||||
|
||||
xSpeed = applyDeadband(xSpeed, m_deadband);
|
||||
zRotation = applyDeadband(zRotation, m_deadband);
|
||||
xSpeed = MathUtil.applyDeadband(xSpeed, m_deadband);
|
||||
zRotation = MathUtil.applyDeadband(zRotation, m_deadband);
|
||||
|
||||
var speeds = arcadeDriveIK(xSpeed, zRotation, squareInputs);
|
||||
|
||||
@@ -203,8 +203,8 @@ public class DifferentialDrive extends RobotDriveBase implements Sendable, AutoC
|
||||
m_reported = true;
|
||||
}
|
||||
|
||||
xSpeed = applyDeadband(xSpeed, m_deadband);
|
||||
zRotation = applyDeadband(zRotation, m_deadband);
|
||||
xSpeed = MathUtil.applyDeadband(xSpeed, m_deadband);
|
||||
zRotation = MathUtil.applyDeadband(zRotation, m_deadband);
|
||||
|
||||
var speeds = curvatureDriveIK(xSpeed, zRotation, allowTurnInPlace);
|
||||
|
||||
@@ -241,8 +241,8 @@ public class DifferentialDrive extends RobotDriveBase implements Sendable, AutoC
|
||||
m_reported = true;
|
||||
}
|
||||
|
||||
leftSpeed = applyDeadband(leftSpeed, m_deadband);
|
||||
rightSpeed = applyDeadband(rightSpeed, m_deadband);
|
||||
leftSpeed = MathUtil.applyDeadband(leftSpeed, m_deadband);
|
||||
rightSpeed = MathUtil.applyDeadband(rightSpeed, m_deadband);
|
||||
|
||||
var speeds = tankDriveIK(leftSpeed, rightSpeed, squareInputs);
|
||||
|
||||
|
||||
@@ -191,8 +191,8 @@ public class KilloughDrive extends RobotDriveBase implements Sendable, AutoClose
|
||||
m_reported = true;
|
||||
}
|
||||
|
||||
ySpeed = applyDeadband(ySpeed, m_deadband);
|
||||
xSpeed = applyDeadband(xSpeed, m_deadband);
|
||||
ySpeed = MathUtil.applyDeadband(ySpeed, m_deadband);
|
||||
xSpeed = MathUtil.applyDeadband(xSpeed, m_deadband);
|
||||
|
||||
var speeds = driveCartesianIK(ySpeed, xSpeed, zRotation, gyroAngle);
|
||||
|
||||
|
||||
@@ -169,8 +169,8 @@ public class MecanumDrive extends RobotDriveBase implements Sendable, AutoClosea
|
||||
m_reported = true;
|
||||
}
|
||||
|
||||
ySpeed = applyDeadband(ySpeed, m_deadband);
|
||||
xSpeed = applyDeadband(xSpeed, m_deadband);
|
||||
ySpeed = MathUtil.applyDeadband(ySpeed, m_deadband);
|
||||
xSpeed = MathUtil.applyDeadband(xSpeed, m_deadband);
|
||||
|
||||
var speeds = driveCartesianIK(ySpeed, xSpeed, zRotation, gyroAngle);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.drive;
|
||||
|
||||
import edu.wpi.first.math.MathUtil;
|
||||
import edu.wpi.first.wpilibj.MotorSafety;
|
||||
|
||||
/** Common base class for drive platforms. */
|
||||
@@ -41,7 +42,7 @@ public abstract class RobotDriveBase extends MotorSafety {
|
||||
*
|
||||
* <p>The default value is {@value #kDefaultDeadband}. Inputs smaller than the deadband are set to
|
||||
* 0.0 while inputs larger than the deadband are scaled from 0.0 to 1.0. See {@link
|
||||
* #applyDeadband}.
|
||||
* edu.wpi.first.math.MathUtil#applyDeadband}.
|
||||
*
|
||||
* @param deadband The deadband to set.
|
||||
*/
|
||||
@@ -83,17 +84,11 @@ public abstract class RobotDriveBase extends MotorSafety {
|
||||
* @param value value to clip
|
||||
* @param deadband range around zero
|
||||
* @return The value after the deadband is applied.
|
||||
* @deprecated Use MathUtil.applyDeadband(double,double).
|
||||
*/
|
||||
@Deprecated(since = "2021", forRemoval = true)
|
||||
protected 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;
|
||||
}
|
||||
return MathUtil.applyDeadband(value, deadband);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user