Package frc.lib.util

Class LoggedTunableNumber

java.lang.Object
frc.lib.util.LoggedTunableNumber
All Implemented Interfaces:
DoubleSupplier

public class LoggedTunableNumber extends Object implements DoubleSupplier
Class for a tunable number. Gets value from dashboard in tuning mode, returns default if not or value not in dashboard.
  • Constructor Details

    • LoggedTunableNumber

      public LoggedTunableNumber(String dashboardKey)
      Create a new LoggedTunableNumber
      Parameters:
      dashboardKey - Key on dashboard
    • LoggedTunableNumber

      public LoggedTunableNumber(String dashboardKey, double defaultValue)
      Create a new LoggedTunableNumber with the default value
      Parameters:
      dashboardKey - Key on dashboard
      defaultValue - Default value
  • Method Details

    • initDefault

      public void initDefault(double defaultValue)
      Set the default value of the number. The default value can only be set once.
      Parameters:
      defaultValue - The default value
    • get

      public double get()
      Get the current value, from dashboard if available and in tuning mode.
      Returns:
      The current value
    • hasChanged

      public boolean hasChanged(int id)
      Checks whether the number has changed since our last check
      Parameters:
      id - Unique identifier for the caller to avoid conflicts when shared between multiple objects. Recommended approach is to pass the result of "hashCode()"
      Returns:
      True if the number has changed since the last time this method was called, false otherwise.
    • ifChanged

      public static void ifChanged(int id, Consumer<double[]> action, LoggedTunableNumber... tunableNumbers)
      Runs action if any of the tunableNumbers have changed
      Parameters:
      id - Unique identifier for the caller to avoid conflicts when shared between multiple * objects. Recommended approach is to pass the result of "hashCode()"
      action - Callback to run when any of the tunable numbers have changed. Access tunable numbers in order inputted in method
      tunableNumbers - All tunable numbers to check
    • ifChanged

      public static void ifChanged(int id, Runnable action, LoggedTunableNumber... tunableNumbers)
      Runs action if any of the tunableNumbers have changed
    • getAsDouble

      public double getAsDouble()
      Specified by:
      getAsDouble in interface DoubleSupplier