Robot Core Documentation
Loading...
Searching...
No Matches
edu.wpi.first.math.MathUtil Class Reference

Static Public Member Functions

static int clamp (int value, int low, int high)
 
static double clamp (double value, double low, double high)
 
static double applyDeadband (double value, double deadband, double maxMagnitude)
 
static double applyDeadband (double value, double deadband)
 
static double inputModulus (double input, double minimumInput, double maximumInput)
 
static double angleModulus (double angleRadians)
 
static double interpolate (double startValue, double endValue, double t)
 
static double inverseInterpolate (double startValue, double endValue, double q)
 
static boolean isNear (double expected, double actual, double tolerance)
 
static boolean isNear (double expected, double actual, double tolerance, double min, double max)
 

Detailed Description

Math utility functions.

Member Function Documentation

◆ angleModulus()

static double edu.wpi.first.math.MathUtil.angleModulus ( double angleRadians)
static

Wraps an angle to the range -pi to pi radians.

Parameters
angleRadiansAngle to wrap in radians.
Returns
The wrapped angle.

◆ applyDeadband() [1/2]

static double edu.wpi.first.math.MathUtil.applyDeadband ( double value,
double deadband )
static

Returns 0.0 if the given value is within the specified range around zero. The remaining range between the deadband and 1.0 is scaled from 0.0 to 1.0.

Parameters
valueValue to clip.
deadbandRange around zero.
Returns
The value after the deadband is applied.

◆ applyDeadband() [2/2]

static double edu.wpi.first.math.MathUtil.applyDeadband ( double value,
double deadband,
double maxMagnitude )
static

Returns 0.0 if the given value is within the specified range around zero. The remaining range between the deadband and the maximum magnitude is scaled from 0.0 to the maximum magnitude.

Parameters
valueValue to clip.
deadbandRange around zero.
maxMagnitudeThe maximum magnitude of the input. Can be infinite.
Returns
The value after the deadband is applied.

◆ clamp() [1/2]

static double edu.wpi.first.math.MathUtil.clamp ( double value,
double low,
double high )
static

Returns value clamped between low and high boundaries.

Parameters
valueValue to clamp.
lowThe lower boundary to which to clamp value.
highThe higher boundary to which to clamp value.
Returns
The clamped value.

◆ clamp() [2/2]

static int edu.wpi.first.math.MathUtil.clamp ( int value,
int low,
int high )
static

Returns value clamped between low and high boundaries.

Parameters
valueValue to clamp.
lowThe lower boundary to which to clamp value.
highThe higher boundary to which to clamp value.
Returns
The clamped value.

◆ inputModulus()

static double edu.wpi.first.math.MathUtil.inputModulus ( double input,
double minimumInput,
double maximumInput )
static

Returns modulus of input.

Parameters
inputInput value to wrap.
minimumInputThe minimum value expected from the input.
maximumInputThe maximum value expected from the input.
Returns
The wrapped value.

◆ interpolate()

static double edu.wpi.first.math.MathUtil.interpolate ( double startValue,
double endValue,
double t )
static

Perform linear interpolation between two values.

Parameters
startValueThe value to start at.
endValueThe value to end at.
tHow far between the two values to interpolate. This is clamped to [0, 1].
Returns
The interpolated value.

◆ inverseInterpolate()

static double edu.wpi.first.math.MathUtil.inverseInterpolate ( double startValue,
double endValue,
double q )
static

Return where within interpolation range [0, 1] q is between startValue and endValue.

Parameters
startValueLower part of interpolation range.
endValueUpper part of interpolation range.
qQuery.
Returns
Interpolant in range [0, 1].

◆ isNear() [1/2]

static boolean edu.wpi.first.math.MathUtil.isNear ( double expected,
double actual,
double tolerance )
static

Checks if the given value matches an expected value within a certain tolerance.

Parameters
expectedThe expected value
actualThe actual value
toleranceThe allowed difference between the actual and the expected value
Returns
Whether or not the actual value is within the allowed tolerance

◆ isNear() [2/2]

static boolean edu.wpi.first.math.MathUtil.isNear ( double expected,
double actual,
double tolerance,
double min,
double max )
static

Checks if the given value matches an expected value within a certain tolerance. Supports continuous input for cases like absolute encoders.

Continuous input means that the min and max value are considered to be the same point, and tolerances can be checked across them. A common example would be for absolute encoders: calling isNear(2, 359, 5, 0, 360) returns true because 359 is 1 away from 360 (which is treated as the same as 0) and 2 is 2 away from 0, adding up to an error of 3 degrees, which is within the given tolerance of 5.

Parameters
expectedThe expected value
actualThe actual value
toleranceThe allowed difference between the actual and the expected value
minSmallest value before wrapping around to the largest value
maxLargest value before wrapping around to the smallest value
Returns
Whether or not the actual value is within the allowed tolerance

The documentation for this class was generated from the following file: