Package com.marslib.util
Class LoggedTunableNumber
java.lang.Object
com.marslib.util.LoggedTunableNumber
- All Implemented Interfaces:
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
ConstructorsConstructorDescriptionLoggedTunableNumber(String dashboardKey) LoggedTunableNumber(String dashboardKey, double defaultValue) -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAutomates the visual construction of the native WPILib Tuning dashboard.static voidclear()Clears all registered tunables.voidclose()Releases native NetworkTables handles.doubleget()static edu.wpi.first.wpilibj2.command.CommandGenerates 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.booleanhasChanged(int id) Returns true if the value has changed since the last time this specific consumer checked.final voidinitDefault(double defaultValue) voidinitSendable(edu.wpi.first.util.sendable.SendableBuilder builder)
-
Constructor Details
-
LoggedTunableNumber
-
LoggedTunableNumber
-
-
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()ormotor.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:
initSendablein interfaceedu.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.
-