Class LoggedTunableNumber

java.lang.Object
com.marslib.util.LoggedTunableNumber
All Implemented Interfaces:
edu.wpi.first.util.sendable.Sendable

public class LoggedTunableNumber extends Object implements edu.wpi.first.util.sendable.Sendable
A tunable number that can be modified at runtime via NetworkTables for live PID tuning.

When the robot is connected to an FMS (real competition), the value is locked to the default for safety and determinism. In practice/simulation mode, values can be freely adjusted from the SmartDashboard or AdvantageScope.

Students: Use hasChanged(int id) to detect when a value has been modified. Each consumer (identified by a unique int ID) independently tracks whether it has seen the latest value.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
    LoggedTunableNumber(String dashboardKey, double defaultValue)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Automates the visual construction of the native WPILib Tuning dashboard.
    static void
    Clears all registered tunables.
    void
    Releases native NetworkTables handles.
    double
    get()
     
    static edu.wpi.first.wpilibj2.command.Command
    Generates a structural Command that pulls the live value of all registered tunables and dumps them as a formatted JSON document on the RoboRIO deployment storage.
    boolean
    hasChanged(int id)
    Returns true if the value has changed since the last time this specific consumer checked.
    final void
    initDefault(double defaultValue)
     
    void
    initSendable(edu.wpi.first.util.sendable.SendableBuilder builder)
     

    Methods inherited from class java.lang.Object

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

    • LoggedTunableNumber

      public LoggedTunableNumber(String dashboardKey)
    • LoggedTunableNumber

      public LoggedTunableNumber(String dashboardKey, double defaultValue)
  • Method Details

    • initDefault

      public final void initDefault(double defaultValue)
    • get

      public double get()
    • hasChanged

      public boolean hasChanged(int id)
      Returns true if the value has changed since the last time this specific consumer checked.
      Parameters:
      id - A unique identifier for the consumer (e.g., this.hashCode() or motor.getDeviceID()).
      Returns:
      Whether the current value differs from the last value seen by this consumer.
    • initSendable

      public void initSendable(edu.wpi.first.util.sendable.SendableBuilder builder)
      Specified by:
      initSendable in interface edu.wpi.first.util.sendable.Sendable
    • getDumpCommand

      public static edu.wpi.first.wpilibj2.command.Command getDumpCommand()
      Generates a structural Command that pulls the live value of all registered tunables and dumps them as a formatted JSON document on the RoboRIO deployment storage.
    • buildTuningDashboard

      public static void buildTuningDashboard()
      Automates the visual construction of the native WPILib Tuning dashboard. Dynamically iterates over every registered tunable globally, parses its subsystem path prefix, and buckets it into beautifully sorted List layouts seamlessly for 0-friction calibration logging.
    • clear

      public static void clear()
      Clears all registered tunables. Only used for unit testing.
    • close

      public void close()
      Releases native NetworkTables handles. Should be called when a tunable is no longer needed, especially in unit tests to prevent resource leaks and native crashes.