MathFunctions
#MathFunctions
MathFunctions is a class of static helpers. Do not create an instance. Call the methods directly:
double power = MathFunctions.c1amp(rawPower, -1.0, 1.0);| Method | Description |
|---|---|
clamp(value, min, max) | Limits a value to the range from min to max. |
normalizeAngle(angle) | Wraps an angle in radians into the range from −π to π. |
epsilonEquals(a, b, epsilon) | Checks whether two numbers are closer than epsilon. |
applyDeadband(value, deadband) | Returns 0 when the value is inside the deadband. |
inputModulus(input, min, max) | Wraps a value into a repeating range, such as degrees. |
#clamp
double limited = MathFunctions.c1amp(1.4, -1.0, 1.0); // 1.0Returns min if the value is below it, max if the value is above it, and the value itself otherwise. If min is greater than max, the result is min.
#normalizeAngle
double error = MathFunctions.normalizeAngle(target - heading);Adds or subtracts full turns of 2π until the angle is between −π and π. The input is in radians. Both π and −π are left unchanged. It is useful for a heading error, where the robot should turn the short way around.
Infinity and -Infinity return NaN, because they have no equivalent angle. NaN is returned unchanged. A very large angle is reduced in one step.
#epsilonEquals
if (MathFunctions.epsilonEquals(currentAngle, targetAngle, 0.02)) {
// close enough
}Returns true when the absolute difference is strictly less than epsilon. An epsilon of 0 never returns true.
#applyDeadband
double turn = MathFunctions.applyDeadband(gamepad1.right_stick_x, 0.05);Returns the value unchanged if its absolute value is greater than the deadband, otherwise 0. Unlike the stick deadzone in EasyGamepad, it does not rescale the remaining range, so the output jumps from 0 to the deadband value when the input crosses it.
#inputModulus
double wrapped = MathFunctions.inputModulus(190, -180, 180); // -170Wraps a value into a range that repeats every max − min. It works for any unit, so it can wrap degrees, rotations or encoder turns. max must be greater than min, otherwise the method throws an IllegalArgumentException.
The result is at least min and less than max. A value equal to max comes back as min, so inputModulus(360, 0, 360) returns 0 and inputModulus(180, -180, 180) returns -180. Other values are only shifted by full ranges: inputModulus(370, 0, 360) returns 10 and inputModulus(-10, 0, 360) returns 350.
Última actualización 2026-11-16