Package frc.lib.util
Class LoggedTunableNumber
java.lang.Object
frc.lib.util.LoggedTunableNumber
- All Implemented Interfaces:
DoubleSupplier
Class for a tunable number. Gets value from dashboard in tuning mode, returns default if not or
value not in dashboard.
-
Constructor Summary
ConstructorsConstructorDescriptionLoggedTunableNumber
(String dashboardKey) Create a new LoggedTunableNumberLoggedTunableNumber
(String dashboardKey, double defaultValue) Create a new LoggedTunableNumber with the default value -
Method Summary
Modifier and TypeMethodDescriptiondouble
get()
Get the current value, from dashboard if available and in tuning mode.double
boolean
hasChanged
(int id) Checks whether the number has changed since our last checkstatic void
ifChanged
(int id, Runnable action, LoggedTunableNumber... tunableNumbers) Runs action if any of the tunableNumbers have changedstatic void
ifChanged
(int id, Consumer<double[]> action, LoggedTunableNumber... tunableNumbers) Runs action if any of the tunableNumbers have changedvoid
initDefault
(double defaultValue) Set the default value of the number.
-
Constructor Details
-
LoggedTunableNumber
Create a new LoggedTunableNumber- Parameters:
dashboardKey
- Key on dashboard
-
LoggedTunableNumber
Create a new LoggedTunableNumber with the default value- Parameters:
dashboardKey
- Key on dashboarddefaultValue
- 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 methodtunableNumbers
- All tunable numbers to check
-
ifChanged
Runs action if any of the tunableNumbers have changed -
getAsDouble
public double getAsDouble()- Specified by:
getAsDouble
in interfaceDoubleSupplier
-