Skip to content

Configurable Parameters

nab138 edited this page Jan 25, 2024 · 10 revisions

Configurable Parameters are parameters that are linked to keys in the config.json file. You can edit them either by editing the config.json file directly and reloading, or using AdvantageScope-3044.

If you have a group of configurable parameters, consider a Configurable Class instead.

Creating a configurable parameter

Configurable params are created like this:

ConfigurableParameter<Type> = new ConfigurableParameter<Type>(defaultValue,
key, /* The json key */
consumer // (Optional) Setter method of the parameter (e.g. this::updateParam) */

Please avoid using commas (,) in the key name, it can cause issues over the NT interface.

Using a configurable paramter

To use a configurable parameter, simply call param.get(). This will retrieve the value of the parameter. This will not retrieve the latest value from the config file, only the value from the most recent reload. You will have to call reload manually or use the NT Interface.

Full example

// Declaration
ConfigurableParameter<Double> speedLimit = new ConfigurableParameter<Double>(5, "drive/speedLimit");

//...
// Usage
speed = Math.min(speedLimit.get(), speed)

Example with a consumer

// Declaration
ConfigurableParameter<Double> speedLimit = new ConfigurableParameter<Double>(5, "drive/speedLimit", this::setSpeedLimit);

//...
// Consumer
public void setSpeedLimit(double newLimit){
    driveHandler.speedLimit = newLimit;
}

Clone this wiki locally