[wpimath] Add copySignPow to MathUtil for joystick input shaping (#8013)

This commit is contained in:
Michael Lesirge
2025-06-15 14:08:41 -07:00
committed by GitHub
parent e2517b7a21
commit fb399eef3d
6 changed files with 173 additions and 8 deletions

View File

@@ -265,8 +265,8 @@ public class DifferentialDrive extends RobotDriveBase implements Sendable, AutoC
// Square the inputs (while preserving the sign) to increase fine control
// while permitting full power.
if (squareInputs) {
xSpeed = Math.copySign(xSpeed * xSpeed, xSpeed);
zRotation = Math.copySign(zRotation * zRotation, zRotation);
xSpeed = MathUtil.copySignPow(xSpeed, 2);
zRotation = MathUtil.copySignPow(zRotation, 2);
}
double leftSpeed = xSpeed - zRotation;
@@ -340,8 +340,8 @@ public class DifferentialDrive extends RobotDriveBase implements Sendable, AutoC
// Square the inputs (while preserving the sign) to increase fine control
// while permitting full power.
if (squareInputs) {
leftSpeed = Math.copySign(leftSpeed * leftSpeed, leftSpeed);
rightSpeed = Math.copySign(rightSpeed * rightSpeed, rightSpeed);
leftSpeed = MathUtil.copySignPow(leftSpeed, 2);
rightSpeed = MathUtil.copySignPow(rightSpeed, 2);
}
return new WheelSpeeds(leftSpeed, rightSpeed);