mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Rename MathUtils to MathUtil for consistency with other util classes (#2155)
This commit is contained in:
committed by
Peter Johnson
parent
d003ec2dc9
commit
8c2ff94d70
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user