Package frc.robot

Class RobotUtils

java.lang.Object
frc.robot.RobotUtils

public final class RobotUtils extends Object
A collection of convenience methods.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    A convenience class for storing a pose along with its mechanism positions.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    allianceFlipX(double x)
    Flips a field X-coordinate based on alliance.
    static double
    allianceFlipY(double y)
    Flips a field Y-coordinate based on alliance.
    static double
    allianceNegate(double x)
    Returns the negative of a value if the alliance is red.
    static double
    clampAbs(double x, double maxAbs)
    Clamp a value to a maximum absolute value.
    static edu.wpi.first.wpilibj2.command.Command
    decorateCommandFeedback(edu.wpi.first.wpilibj2.command.Command command, Runnable feedback)
    Decorates a command with a feedback end condition.
    static double
    hypot(double a, double b)
    Returns the hypotenuse of two values using the pythagorean theorem.
    static double
    hypot_inverse(double c, double a)
    Returns one side of a right triangle given a hypotenuse and side length.
    static boolean
    Checks the alliance of the robot.
    static edu.wpi.first.wpilibj2.command.Command
    onOffCommand(Consumer<Double> consumer, double value)
    Returns a StartEndCommand that takes one value on start and zero on end.
    static edu.wpi.first.wpilibj2.command.Command
    onOffCommand(Consumer<Double> consumer, double on_value, double off_value)
    Returns a StartEndCommand that takes one value on start and a second value on end.

    Methods inherited from class java.lang.Object

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

    • RobotUtils

      public RobotUtils()
  • Method Details

    • hypot

      public static double hypot(double a, double b)
      Returns the hypotenuse of two values using the pythagorean theorem.
      Parameters:
      a - The first value.
      b - The second value.
      Returns:
      The hypotenuse of the two values.
    • hypot_inverse

      public static double hypot_inverse(double c, double a)
      Returns one side of a right triangle given a hypotenuse and side length.
      Parameters:
      c - The hypotenuse length.
      a - The shorter side length.
      Returns:
      The third side length.
    • clampAbs

      public static double clampAbs(double x, double maxAbs)
      Clamp a value to a maximum absolute value.
      Parameters:
      x - The value to be clamped.
      maxAbs - The maximum absolute value.
      Returns:
      The clamped value.
    • isRedAlliance

      public static boolean isRedAlliance()
      Checks the alliance of the robot.
      Returns:
      Whether or not the robot is on red alliance.
    • allianceFlipX

      public static double allianceFlipX(double x)
      Flips a field X-coordinate based on alliance.
      Parameters:
      x - The original coordinate.
      Returns:
      The correct coordinate.
    • allianceFlipY

      public static double allianceFlipY(double y)
      Flips a field Y-coordinate based on alliance.
      Parameters:
      y - The original coordinate.
      Returns:
      The correct coordinate.
    • allianceNegate

      public static double allianceNegate(double x)
      Returns the negative of a value if the alliance is red.
      Parameters:
      x - The original value.
      Returns:
      The corrected value.
    • onOffCommand

      public static edu.wpi.first.wpilibj2.command.Command onOffCommand(Consumer<Double> consumer, double on_value, double off_value)
      Returns a StartEndCommand that takes one value on start and a second value on end.
      Parameters:
      consumer - The consumer to accept the double values.
      on_value - The first value.
      off_value - The final value.
      Returns:
      The composed command.
    • onOffCommand

      public static edu.wpi.first.wpilibj2.command.Command onOffCommand(Consumer<Double> consumer, double value)
      Returns a StartEndCommand that takes one value on start and zero on end.
      Parameters:
      consumer - The consumer to accept the double values.
      value - The first value.
      Returns:
      The composed command.
    • decorateCommandFeedback

      public static edu.wpi.first.wpilibj2.command.Command decorateCommandFeedback(edu.wpi.first.wpilibj2.command.Command command, Runnable feedback)
      Decorates a command with a feedback end condition.
      Parameters:
      command - The original command.
      feedback - The callback to the feedback method.
      Returns:
      The modified command.