Package lib.util
Class Util
java.lang.Object
lib.util.Util
Common utilities
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic BooleanSupplierall(BooleanSupplier... conditions) Combines multiple boolean suppliers with a logical AND operator.static BooleanSupplierany(BooleanSupplier... conditions) Combines multiple boolean suppliers with a logical OR operator.static doubleclamp(double value, double min, double max) Clamp a value between a minimum and maximumstatic floatclamp(float value, float min, float max) Clamp a value between a minimum and maximumstatic intclamp(int value, int min, int max) Clamp a value between a minimum and maximumstatic voidclearPose(edu.wpi.first.wpilibj.smartdashboard.FieldObject2d... poses) Clears the pose(s) fromFieldObject2dinstancesstatic doubleepochSecondsToFPGATimestamp(double seconds) static doublefahrenheit(double celsius) static booleanisZero(double value) Returns true ifvalueis less thanepsilon.static booleanisZero(double value, double epsilon) Returns true ifvalueis less thanepsilon.static doublelerp(double x, double a, double b) static doubletimeConversionFactor(TimeUnit from, TimeUnit to) Computes the conversion factor between the first and secondTimeUnitgiven.static edu.wpi.first.math.geometry.Transform2dtransform2d(double x, double y, double rotations) Utility for creating Transform2D instancesstatic edu.wpi.first.math.geometry.Transform3dtransform3d(double x, double y, double z, double radians) Utility for creating Transform3D instancesstatic doubletransformRange(double x, double fromMin, double fromMax, double toMin, double toMax) Transform a number from one range into another.static doubletransformRange(double x, Util.Range from, Util.Range to)
-
Method Details
-
isZero
public static boolean isZero(double value, double epsilon) Returns true ifvalueis less thanepsilon. This is useful for floating point numbers, whose arithmetic operations tend to introduce small errors.- Parameters:
value- The floating point number to be comparedepsilon- The maximum magnitude of var such that it can be considered zero- Returns:
- Whether
valueis less thanepsilon
-
isZero
public static boolean isZero(double value) Returns true ifvalueis less thanepsilon. 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
valueis 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 valuemin- The minimum allowed valuemax- 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 valuemin- The minimum allowed valuemax- 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 valuemin- The minimum allowed valuemax- 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 clampedfromMin- Minimum value of the initial rangefromMax- Maximum value of the initial rangetoMin- Minimum value of the target rangetoMax- 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
-
lerp
public static double lerp(double x, double a, double b) -
timeConversionFactor
Computes the conversion factor between the first and secondTimeUnitgiven.- Parameters:
from- the source unitto- the target unit- Returns:
- the conversion factor
-
epochSecondsToFPGATimestamp
public static double epochSecondsToFPGATimestamp(double seconds) -
fahrenheit
public static double fahrenheit(double celsius) -
any
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
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) fromFieldObject2dinstances
-