EasyStack Docs

MathFunctions

Esta página ainda não foi traduzida. Mostrando a versão em inglês.

#MathFunctions

MathFunctions is a class of static helpers. Do not create an instance. Call the methods directly:

Java
double power = MathFunctions.c1amp(rawPower, -1.0, 1.0);
MethodDescription
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

Java
double limited = MathFunctions.c1amp(1.4, -1.0, 1.0); // 1.0

Returns 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

Java
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

Java
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

Java
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

Java
double wrapped = MathFunctions.inputModulus(190, -180, 180); // -170

Wraps 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 atualização 2026-11-16

EasyStack - FTC Java library

This site records page views of visitors to understand how the documentation is used. Nothing is sold or shared with third parties.