Package frc.spectrumLib.util
Class Util
java.lang.Object
frc.spectrumLib.util.Util
From 254 lib imported from 1678-2024 Contains basic functions that are used often.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final TriggerTrigger that is true when the robot is enabled in autonomous mode.static final TriggerTrigger that is true when the robot is disabled.static final TriggerTrigger that is true when the DriverStation is attached.static final doubleSmall value used for floating-point equality comparisons.static final TriggerTrigger that is true when the robot is enabled in teleop mode.static final TriggerTrigger that is true when the robot is enabled in test mode. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanallCloseTo(List<Double> list, double value, double epsilon) Checks whether every element inlistis withinepsilonofvalue.static booleanepsilonEquals(double a, double b) static booleanepsilonEquals(double a, double b, double epsilon) Checks whetheraandbare withinepsilonof each other.static booleanepsilonEquals(int a, int b, int epsilon) Checks whether integeraandbare withinepsilonof each other.static booleaninRange(double v, double maxMagnitude) Checks whethervis strictly within [-maxMagnitude,maxMagnitude].static booleaninRange(double v, double min, double max) Checks if the given input is within the range (min, max), both exclusive.static booleaninRange(DoubleSupplier v, DoubleSupplier min, DoubleSupplier max) Checks whether the value supplied byvis strictly between the values supplied byminandmax.static doubleinterpolate(double a, double b, double x) Linearly interpolates betweenaandbby a factorx, clamped to [0, 1].static StringjoinStrings(String delim, List<?> strings) Joins a list of objects into a single string with the given delimiter.static doublelimit(double v, double maxMagnitude) Clampsvto the range [-maxMagnitude,maxMagnitude].static doublelimit(double v, double min, double max) Clampsvto the range [min,max].
-
Field Details
-
EPSILON
public static final double EPSILONSmall value used for floating-point equality comparisons.- See Also:
-
teleop
Trigger that is true when the robot is enabled in teleop mode. -
autoMode
Trigger that is true when the robot is enabled in autonomous mode. -
testMode
Trigger that is true when the robot is enabled in test mode. -
disabled
Trigger that is true when the robot is disabled. -
dsAttached
Trigger that is true when the DriverStation is attached.
-
-
Method Details
-
limit
public static double limit(double v, double maxMagnitude) Clampsvto the range [-maxMagnitude,maxMagnitude].- Parameters:
v- the value to clampmaxMagnitude- the maximum absolute value allowed- Returns:
- the clamped value
-
limit
public static double limit(double v, double min, double max) Clampsvto the range [min,max].- Parameters:
v- the value to clampmin- the lower bound (inclusive)max- the upper bound (inclusive)- Returns:
- the clamped value
-
inRange
public static boolean inRange(double v, double maxMagnitude) Checks whethervis strictly within [-maxMagnitude,maxMagnitude].- Parameters:
v- the value to testmaxMagnitude- the maximum absolute value (exclusive bound)- Returns:
trueif|v| < maxMagnitude
-
inRange
public static boolean inRange(double v, double min, double max) Checks if the given input is within the range (min, max), both exclusive. -
inRange
Checks whether the value supplied byvis strictly between the values supplied byminandmax.- Parameters:
v- supplier of the value to testmin- supplier of the lower bound (exclusive)max- supplier of the upper bound (exclusive)- Returns:
trueifmin.get() < v.get() < max.get()
-
interpolate
public static double interpolate(double a, double b, double x) Linearly interpolates betweenaandbby a factorx, clamped to [0, 1].- Parameters:
a- the start value (x = 0)b- the end value (x = 1)x- the interpolation factor, clamped to [0, 1]- Returns:
- the interpolated value
-
joinStrings
Joins a list of objects into a single string with the given delimiter.- Parameters:
delim- the delimiter placed between consecutive elementsstrings- the list of objects whosetoString()values are joined- Returns:
- the joined string
-
epsilonEquals
public static boolean epsilonEquals(double a, double b, double epsilon) Checks whetheraandbare withinepsilonof each other.- Parameters:
a- first valueb- second valueepsilon- the allowed absolute difference- Returns:
trueif|a - b| <= epsilon
-
epsilonEquals
public static boolean epsilonEquals(double a, double b) - Parameters:
a- first valueb- second value- Returns:
trueif|a - b| <= EPSILON
-
epsilonEquals
public static boolean epsilonEquals(int a, int b, int epsilon) Checks whether integeraandbare withinepsilonof each other.- Parameters:
a- first integer valueb- second integer valueepsilon- the allowed absolute difference- Returns:
trueif|a - b| <= epsilon
-
allCloseTo
Checks whether every element inlistis withinepsilonofvalue.- Parameters:
list- the list of doubles to checkvalue- the target value each element is compared againstepsilon- the allowed absolute difference for each comparison- Returns:
trueif all elements are withinepsilonofvalue
-