From 8c2ff94d70fcafa3ed1deeb73de25f7262a2c758 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Wed, 4 Dec 2019 20:39:12 -0800 Subject: [PATCH] Rename MathUtils to MathUtil for consistency with other util classes (#2155) --- .../wpilibj/controller/PIDController.java | 8 ++++---- .../wpilibj/drive/DifferentialDrive.java | 20 +++++++++---------- .../first/wpilibj/drive/KilloughDrive.java | 6 +++--- .../wpi/first/wpilibj/drive/MecanumDrive.java | 6 +++--- .../wpi/first/wpilibj/MotorEncoderTest.java | 6 +++--- .../math/{MathUtils.java => MathUtil.java} | 4 ++-- 6 files changed, 25 insertions(+), 25 deletions(-) rename wpiutil/src/main/java/edu/wpi/first/wpiutil/math/{MathUtils.java => MathUtil.java} (94%) diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/controller/PIDController.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/controller/PIDController.java index c7bdb2556c..04e34b1154 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/controller/PIDController.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/controller/PIDController.java @@ -12,7 +12,7 @@ import edu.wpi.first.hal.HAL; import edu.wpi.first.wpilibj.Sendable; import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; -import edu.wpi.first.wpiutil.math.MathUtils; +import edu.wpi.first.wpiutil.math.MathUtil; /** * Implements a PID control loop. @@ -197,7 +197,7 @@ public class PIDController implements Sendable, AutoCloseable { */ public void setSetpoint(double setpoint) { if (m_maximumInput > m_minimumInput) { - m_setpoint = MathUtils.clamp(setpoint, m_minimumInput, m_maximumInput); + m_setpoint = MathUtil.clamp(setpoint, m_minimumInput, m_maximumInput); } else { m_setpoint = setpoint; } @@ -320,7 +320,7 @@ public class PIDController implements Sendable, AutoCloseable { m_velocityError = (m_positionError - m_prevError) / m_period; if (m_Ki != 0) { - m_totalError = MathUtils.clamp(m_totalError + m_positionError * m_period, + m_totalError = MathUtil.clamp(m_totalError + m_positionError * m_period, m_minimumIntegral / m_Ki, m_maximumIntegral / m_Ki); } @@ -378,7 +378,7 @@ public class PIDController implements Sendable, AutoCloseable { // Clamp setpoint to new input if (m_maximumInput > m_minimumInput) { - m_setpoint = MathUtils.clamp(m_setpoint, m_minimumInput, m_maximumInput); + m_setpoint = MathUtil.clamp(m_setpoint, m_minimumInput, m_maximumInput); } } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/DifferentialDrive.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/DifferentialDrive.java index 11ef39c269..cbfd3c0532 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/DifferentialDrive.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/DifferentialDrive.java @@ -17,7 +17,7 @@ import edu.wpi.first.wpilibj.SpeedController; import edu.wpi.first.wpilibj.SpeedControllerGroup; import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; -import edu.wpi.first.wpiutil.math.MathUtils; +import edu.wpi.first.wpiutil.math.MathUtil; /** * A class for driving differential drive/skid-steer drive platforms such as the Kit of Parts drive @@ -184,10 +184,10 @@ public class DifferentialDrive extends RobotDriveBase implements Sendable, AutoC m_reported = true; } - xSpeed = MathUtils.clamp(xSpeed, -1.0, 1.0); + xSpeed = MathUtil.clamp(xSpeed, -1.0, 1.0); xSpeed = applyDeadband(xSpeed, m_deadband); - zRotation = MathUtils.clamp(zRotation, -1.0, 1.0); + zRotation = MathUtil.clamp(zRotation, -1.0, 1.0); zRotation = applyDeadband(zRotation, m_deadband); // Square the inputs (while preserving the sign) to increase fine control @@ -222,9 +222,9 @@ public class DifferentialDrive extends RobotDriveBase implements Sendable, AutoC } } - m_leftMotor.set(MathUtils.clamp(leftMotorOutput, -1.0, 1.0) * m_maxOutput); + m_leftMotor.set(MathUtil.clamp(leftMotorOutput, -1.0, 1.0) * m_maxOutput); double maxOutput = m_maxOutput * m_rightSideInvertMultiplier; - m_rightMotor.set(MathUtils.clamp(rightMotorOutput, -1.0, 1.0) * maxOutput); + m_rightMotor.set(MathUtil.clamp(rightMotorOutput, -1.0, 1.0) * maxOutput); feed(); } @@ -251,10 +251,10 @@ public class DifferentialDrive extends RobotDriveBase implements Sendable, AutoC m_reported = true; } - xSpeed = MathUtils.clamp(xSpeed, -1.0, 1.0); + xSpeed = MathUtil.clamp(xSpeed, -1.0, 1.0); xSpeed = applyDeadband(xSpeed, m_deadband); - zRotation = MathUtils.clamp(zRotation, -1.0, 1.0); + zRotation = MathUtil.clamp(zRotation, -1.0, 1.0); zRotation = applyDeadband(zRotation, m_deadband); double angularPower; @@ -263,7 +263,7 @@ public class DifferentialDrive extends RobotDriveBase implements Sendable, AutoC if (isQuickTurn) { if (Math.abs(xSpeed) < m_quickStopThreshold) { m_quickStopAccumulator = (1 - m_quickStopAlpha) * m_quickStopAccumulator - + m_quickStopAlpha * MathUtils.clamp(zRotation, -1.0, 1.0) * 2; + + m_quickStopAlpha * MathUtil.clamp(zRotation, -1.0, 1.0) * 2; } overPower = true; angularPower = zRotation; @@ -342,10 +342,10 @@ public class DifferentialDrive extends RobotDriveBase implements Sendable, AutoC m_reported = true; } - leftSpeed = MathUtils.clamp(leftSpeed, -1.0, 1.0); + leftSpeed = MathUtil.clamp(leftSpeed, -1.0, 1.0); leftSpeed = applyDeadband(leftSpeed, m_deadband); - rightSpeed = MathUtils.clamp(rightSpeed, -1.0, 1.0); + rightSpeed = MathUtil.clamp(rightSpeed, -1.0, 1.0); rightSpeed = applyDeadband(rightSpeed, m_deadband); // Square the inputs (while preserving the sign) to increase fine control diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/KilloughDrive.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/KilloughDrive.java index d1270bd8ea..45da78a476 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/KilloughDrive.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/KilloughDrive.java @@ -16,7 +16,7 @@ import edu.wpi.first.wpilibj.Sendable; import edu.wpi.first.wpilibj.SpeedController; import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; -import edu.wpi.first.wpiutil.math.MathUtils; +import edu.wpi.first.wpiutil.math.MathUtil; /** * A class for driving Killough drive platforms. @@ -179,10 +179,10 @@ public class KilloughDrive extends RobotDriveBase implements Sendable, AutoClose m_reported = true; } - ySpeed = MathUtils.clamp(ySpeed, -1.0, 1.0); + ySpeed = MathUtil.clamp(ySpeed, -1.0, 1.0); ySpeed = applyDeadband(ySpeed, m_deadband); - xSpeed = MathUtils.clamp(xSpeed, -1.0, 1.0); + xSpeed = MathUtil.clamp(xSpeed, -1.0, 1.0); xSpeed = applyDeadband(xSpeed, m_deadband); // Compensate for gyro angle. diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/MecanumDrive.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/MecanumDrive.java index 1d3a8788d5..702bdf5d06 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/MecanumDrive.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/MecanumDrive.java @@ -16,7 +16,7 @@ import edu.wpi.first.wpilibj.Sendable; import edu.wpi.first.wpilibj.SpeedController; import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; -import edu.wpi.first.wpiutil.math.MathUtils; +import edu.wpi.first.wpiutil.math.MathUtil; /** * A class for driving Mecanum drive platforms. @@ -164,10 +164,10 @@ public class MecanumDrive extends RobotDriveBase implements Sendable, AutoClosea m_reported = true; } - ySpeed = MathUtils.clamp(ySpeed, -1.0, 1.0); + ySpeed = MathUtil.clamp(ySpeed, -1.0, 1.0); ySpeed = applyDeadband(ySpeed, m_deadband); - xSpeed = MathUtils.clamp(xSpeed, -1.0, 1.0); + xSpeed = MathUtil.clamp(xSpeed, -1.0, 1.0); xSpeed = applyDeadband(xSpeed, m_deadband); // Compensate for gyro angle. diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/MotorEncoderTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/MotorEncoderTest.java index d2db15029f..7fcd01f0d9 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/MotorEncoderTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/MotorEncoderTest.java @@ -23,7 +23,7 @@ import edu.wpi.first.wpilibj.controller.PIDController; import edu.wpi.first.wpilibj.fixtures.MotorEncoderFixture; import edu.wpi.first.wpilibj.test.AbstractComsSetup; import edu.wpi.first.wpilibj.test.TestBench; -import edu.wpi.first.wpiutil.math.MathUtils; +import edu.wpi.first.wpiutil.math.MathUtil; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -184,7 +184,7 @@ public class MotorEncoderTest extends AbstractComsSetup { Notifier pidRunner = new Notifier(() -> { var speed = pidController.calculate(me.getEncoder().getDistance()); - me.getMotor().set(MathUtils.clamp(speed, -0.2, 0.2)); + me.getMotor().set(MathUtil.clamp(speed, -0.2, 0.2)); }); pidRunner.startPeriodic(pidController.getPeriod()); @@ -207,7 +207,7 @@ public class MotorEncoderTest extends AbstractComsSetup { Notifier pidRunner = new Notifier(() -> { var speed = filter.calculate(me.getEncoder().getRate()); - me.getMotor().set(MathUtils.clamp(speed, -0.3, 0.3)); + me.getMotor().set(MathUtil.clamp(speed, -0.3, 0.3)); }); pidRunner.startPeriodic(pidController.getPeriod()); diff --git a/wpiutil/src/main/java/edu/wpi/first/wpiutil/math/MathUtils.java b/wpiutil/src/main/java/edu/wpi/first/wpiutil/math/MathUtil.java similarity index 94% rename from wpiutil/src/main/java/edu/wpi/first/wpiutil/math/MathUtils.java rename to wpiutil/src/main/java/edu/wpi/first/wpiutil/math/MathUtil.java index 2f910656e5..cf578349fb 100644 --- a/wpiutil/src/main/java/edu/wpi/first/wpiutil/math/MathUtils.java +++ b/wpiutil/src/main/java/edu/wpi/first/wpiutil/math/MathUtil.java @@ -7,8 +7,8 @@ package edu.wpi.first.wpiutil.math; -public final class MathUtils { - private MathUtils() { +public final class MathUtil { + private MathUtil() { throw new AssertionError("utility class"); }