Class Util

java.lang.Object
frc.spectrumLib.util.Util

public class Util extends Object
From 254 lib imported from 1678-2024 Contains basic functions that are used often.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Trigger
    Trigger that is true when the robot is enabled in autonomous mode.
    static final Trigger
    Trigger that is true when the robot is disabled.
    static final Trigger
    Trigger that is true when the DriverStation is attached.
    static final double
    Small value used for floating-point equality comparisons.
    static final Trigger
    Trigger that is true when the robot is enabled in teleop mode.
    static final Trigger
    Trigger that is true when the robot is enabled in test mode.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    allCloseTo(List<Double> list, double value, double epsilon)
    Checks whether every element in list is within epsilon of value.
    static boolean
    epsilonEquals(double a, double b)
    Checks whether a and b are within EPSILON of each other.
    static boolean
    epsilonEquals(double a, double b, double epsilon)
    Checks whether a and b are within epsilon of each other.
    static boolean
    epsilonEquals(int a, int b, int epsilon)
    Checks whether integer a and b are within epsilon of each other.
    static boolean
    inRange(double v, double maxMagnitude)
    Checks whether v is strictly within [-maxMagnitude, maxMagnitude].
    static boolean
    inRange(double v, double min, double max)
    Checks if the given input is within the range (min, max), both exclusive.
    static boolean
    Checks whether the value supplied by v is strictly between the values supplied by min and max.
    static double
    interpolate(double a, double b, double x)
    Linearly interpolates between a and b by a factor x, clamped to [0, 1].
    static String
    joinStrings(String delim, List<?> strings)
    Joins a list of objects into a single string with the given delimiter.
    static double
    limit(double v, double maxMagnitude)
    Clamps v to the range [-maxMagnitude, maxMagnitude].
    static double
    limit(double v, double min, double max)
    Clamps v to the range [min, max].

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • EPSILON

      public static final double EPSILON
      Small value used for floating-point equality comparisons.
      See Also:
    • teleop

      public static final Trigger teleop
      Trigger that is true when the robot is enabled in teleop mode.
    • autoMode

      public static final Trigger autoMode
      Trigger that is true when the robot is enabled in autonomous mode.
    • testMode

      public static final Trigger testMode
      Trigger that is true when the robot is enabled in test mode.
    • disabled

      public static final Trigger disabled
      Trigger that is true when the robot is disabled.
    • dsAttached

      public static final Trigger dsAttached
      Trigger that is true when the DriverStation is attached.
  • Method Details

    • limit

      public static double limit(double v, double maxMagnitude)
      Clamps v to the range [-maxMagnitude, maxMagnitude].
      Parameters:
      v - the value to clamp
      maxMagnitude - the maximum absolute value allowed
      Returns:
      the clamped value
    • limit

      public static double limit(double v, double min, double max)
      Clamps v to the range [min, max].
      Parameters:
      v - the value to clamp
      min - the lower bound (inclusive)
      max - the upper bound (inclusive)
      Returns:
      the clamped value
    • inRange

      public static boolean inRange(double v, double maxMagnitude)
      Checks whether v is strictly within [-maxMagnitude, maxMagnitude].
      Parameters:
      v - the value to test
      maxMagnitude - the maximum absolute value (exclusive bound)
      Returns:
      true if |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

      public static boolean inRange(DoubleSupplier v, DoubleSupplier min, DoubleSupplier max)
      Checks whether the value supplied by v is strictly between the values supplied by min and max.
      Parameters:
      v - supplier of the value to test
      min - supplier of the lower bound (exclusive)
      max - supplier of the upper bound (exclusive)
      Returns:
      true if min.get() < v.get() < max.get()
    • interpolate

      public static double interpolate(double a, double b, double x)
      Linearly interpolates between a and b by a factor x, 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

      public static String joinStrings(String delim, List<?> strings)
      Joins a list of objects into a single string with the given delimiter.
      Parameters:
      delim - the delimiter placed between consecutive elements
      strings - the list of objects whose toString() values are joined
      Returns:
      the joined string
    • epsilonEquals

      public static boolean epsilonEquals(double a, double b, double epsilon)
      Checks whether a and b are within epsilon of each other.
      Parameters:
      a - first value
      b - second value
      epsilon - the allowed absolute difference
      Returns:
      true if |a - b| <= epsilon
    • epsilonEquals

      public static boolean epsilonEquals(double a, double b)
      Checks whether a and b are within EPSILON of each other.
      Parameters:
      a - first value
      b - second value
      Returns:
      true if |a - b| <= EPSILON
    • epsilonEquals

      public static boolean epsilonEquals(int a, int b, int epsilon)
      Checks whether integer a and b are within epsilon of each other.
      Parameters:
      a - first integer value
      b - second integer value
      epsilon - the allowed absolute difference
      Returns:
      true if |a - b| <= epsilon
    • allCloseTo

      public static boolean allCloseTo(List<Double> list, double value, double epsilon)
      Checks whether every element in list is within epsilon of value.
      Parameters:
      list - the list of doubles to check
      value - the target value each element is compared against
      epsilon - the allowed absolute difference for each comparison
      Returns:
      true if all elements are within epsilon of value