Package lib.util

Class Util

java.lang.Object
lib.util.Util

public final class Util extends Object
Common utilities
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    all(BooleanSupplier... conditions)
    Combines multiple boolean suppliers with a logical AND operator.
    any(BooleanSupplier... conditions)
    Combines multiple boolean suppliers with a logical OR operator.
    static double
    clamp(double value, double min, double max)
    Clamp a value between a minimum and maximum
    static float
    clamp(float value, float min, float max)
    Clamp a value between a minimum and maximum
    static int
    clamp(int value, int min, int max)
    Clamp a value between a minimum and maximum
    static void
    clearPose(edu.wpi.first.wpilibj.smartdashboard.FieldObject2d... poses)
    Clears the pose(s) from FieldObject2d instances
    static double
     
    static double
    fahrenheit(double celsius)
     
    static boolean
    isZero(double value)
    Returns true if value is less than epsilon.
    static boolean
    isZero(double value, double epsilon)
    Returns true if value is less than epsilon.
    static double
    lerp(double x, double a, double b)
     
    static double
    Computes the conversion factor between the first and second TimeUnit given.
    static edu.wpi.first.math.geometry.Transform2d
    transform2d(double x, double y, double rotations)
    Utility for creating Transform2D instances
    static edu.wpi.first.math.geometry.Transform3d
    transform3d(double x, double y, double z, double radians)
    Utility for creating Transform3D instances
    static double
    transformRange(double x, double fromMin, double fromMax, double toMin, double toMax)
    Transform a number from one range into another.
    static double
    transformRange(double x, Util.Range from, Util.Range to)

    Methods inherited from class java.lang.Object

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

    • isZero

      public static boolean isZero(double value, double epsilon)
      Returns true if value is less than epsilon. This is useful for floating point numbers, whose arithmetic operations tend to introduce small errors.
      Parameters:
      value - The floating point number to be compared
      epsilon - The maximum magnitude of var such that it can be considered zero
      Returns:
      Whether value is less than epsilon
    • isZero

      public static boolean isZero(double value)
      Returns true if value is less than epsilon. This is useful for floating point numbers, whose arithmetic operations tend to introduce small errors.
      Parameters:
      value - The floating point number to be compared
      Returns:
      Whether value is effectively zero
    • clamp

      public static double clamp(double value, double min, double max)
      Clamp a value between a minimum and maximum
      Parameters:
      value - The input value
      min - The minimum allowed value
      max - The maximum allowed value
      Returns:
      The clamped value
    • clamp

      public static float clamp(float value, float min, float max)
      Clamp a value between a minimum and maximum
      Parameters:
      value - The input value
      min - The minimum allowed value
      max - The maximum allowed value
      Returns:
      The clamped value
    • clamp

      public static int clamp(int value, int min, int max)
      Clamp a value between a minimum and maximum
      Parameters:
      value - The input value
      min - The minimum allowed value
      max - The maximum allowed value
      Returns:
      The clamped value
    • transformRange

      public static double transformRange(double x, double fromMin, double fromMax, double toMin, double toMax)
      Transform a number from one range into another. For example, transforming an input from [-1, 1] to [0, 10]:
      
       transformRange(getInput(), -1, 1, 0, 10);
       
      Parameters:
      x - Input number. Does not have to be within [fromMin, fromMax] and will not be clamped
      fromMin - Minimum value of the initial range
      fromMax - Maximum value of the initial range
      toMin - Minimum value of the target range
      toMax - Maximum value of the target range
      Returns:
      The transformed value. Will be outside of [toMin, toMax] if the initial value was outside of [fromMin, fromMax]
    • transformRange

      public static double transformRange(double x, Util.Range from, Util.Range to)
    • lerp

      public static double lerp(double x, double a, double b)
    • timeConversionFactor

      public static double timeConversionFactor(TimeUnit from, TimeUnit to)
      Computes the conversion factor between the first and second TimeUnit given.
      Parameters:
      from - the source unit
      to - the target unit
      Returns:
      the conversion factor
    • epochSecondsToFPGATimestamp

      public static double epochSecondsToFPGATimestamp(double seconds)
    • fahrenheit

      public static double fahrenheit(double celsius)
    • any

      public static BooleanSupplier any(BooleanSupplier... conditions)
      Combines multiple boolean suppliers with a logical OR operator.
      Parameters:
      conditions - the boolean suppliers
      Returns:
      callback which returns true if any of the suppliers return true
    • all

      public static BooleanSupplier all(BooleanSupplier... conditions)
      Combines multiple boolean suppliers with a logical AND operator.
      Parameters:
      conditions - the boolean suppliers
      Returns:
      callback which returns true if all of the suppliers return true
    • transform2d

      public static edu.wpi.first.math.geometry.Transform2d transform2d(double x, double y, double rotations)
      Utility for creating Transform2D instances
    • transform3d

      public static edu.wpi.first.math.geometry.Transform3d transform3d(double x, double y, double z, double radians)
      Utility for creating Transform3D instances
    • clearPose

      public static void clearPose(edu.wpi.first.wpilibj.smartdashboard.FieldObject2d... poses)
      Clears the pose(s) from FieldObject2d instances