-
Notifications
You must be signed in to change notification settings - Fork 0
Home
OxConfig is a modular and flexible utility for automatically setting up a JSON based config file and tuning over networktables.
It works by using two major structures: Configurable Classes and Configurable Parameters.
Configurable parameters have a type and JSON key associated with them. When the config file changes and it is reloaded, the parameters value will automatically change (no program restart needed! You don't even have to disable the robot.) They are registered and handled automatically, you just need to create them.
Configurable Classes are similar, they represent a group of configurable parameters that can be easily tuned by the Tuner. You can make your own using our interfaces, or use some of our (for Spark Max or Talon PID controllers) which are stable.
You can easily edit both of these live using Shrinkwrap which makes it easy to tune your robot.
After reading this page, check out Configurable Classes and Configurable Parameters.
Once you create all of your parameters or classes, you need to call OxConfig.initialize()
. This should be done at the very end of your robotInit method, after all configurable parameters and classes have been initialized.
You will need to add the Github packages maven repository to the repositories
section in build.gradle
maven {
url = uri("https://maven.pkg.github.com/FRCTeam3044/OxConfig")
credentials {
username = "3044-Packages-Bot"
password = "\u0067\u0068\u0070\u005f\u0038\u0055\u0068\u0037\u0061\u004f\u0062\u0049\u004a\u0041\u005a\u0045\u0059\u0073\u0041\u0055\u0033\u0063\u0041\u0037\u004f\u0065\u0070\u0037\u0053\u0074\u0073\u0058\u0058\u0059\u0031\u004e\u006e\u0056\u0030\u004a"
}
}
After adding the repo, add the following to dependencies in your build.grade:
implementation 'me.nabdev.oxconfig:oxconfig-wpi:1.3.1'
After installing into your robot project, you must create a file called config.json in the deploy folder (src/main/deploy). It needs to contain {}
.
THIS WILL NOT WORK ON FIRST DEPLOY TO A RIO! You will need to ssh to the rio (or use sftp/winscp) and grant write permissions to all users in /home/lvuser/deploy/config.json. You can do this with chmod 666 config.json
if you are using ssh.
OxConfig has several methods that can be called before OxConfig.initialize()
to change its behavior. They all have default values, so you only need to call them if you want to change them.
OxConfig.setLoggingMode(LoggingMode.Info);
OxConfig.setEditMode(EditMode.Locked);
OxConfig.setEnsureMode(EnsureMode.Always);
OxConfig.setModeList("Mode 1", "Mode 2", "Mode 3" /* ... */);
OxConfig.enableProfiling();
OxConfig.enableMinifyJSON();
OxConfig.initialize();
To learn more about any of them, check out Configuration.
Once OxConfig is in your project, it will generate a config.json file. When you add any configurable parameters or configurable classes, the config file will populate with them. OxConfig is non-destructive, so there should be no cases where it deletes values automatically from the config file. You can edit the values in the config, and when reloadFromFile() is called or on program startup they will be loaded.
OxConfig supports storing several values for the same parameter, to have different "modes" for the robot to run in. This is useful for having the robot be able to switch between competition, presentation, simulation, etc modes without code changes. To change the mode, you can change it in the json file and reload, or use AdvantageScope-3044.
If you launch the robot in simulation, the mode will be in simulation, but it will not be saved to the config file. You can change it through AdvantageScope-3044 and the new mode will be changed in the config file if you do this.
You can change modes programatically by calling OxConfig.modeSelector.setMode(newMode)
. It will not be saved to the config file if you do this, and will be overwritten the next time you reload from disk, change the mode manually, or relaunch robot code. An example use case would be a different set of values for autonomous and teleop.
OxConfig has four modes by default, Presentation, Testing, Competition, and Simulation, but you can specify your own list of modes if you'd like. Check out Configuration for info on how to do .
OxConfig provides three ways to reload ConfigurableClasses/Parameters:
-
OxConfig.reloadFromDisk()
Will reload all values from the config.json file. - Using AdvantageScope-3044 to live update
-
OxConfig.reload()
Will reload all values from the JSON Mapping stored in memory. There aren't many cases where you should need this.
Comments are handled automatically by OxConfig. Any comments in the json should remain even after auto-generation. Auto-generated fields will have an "Auto-generated" comment letting you know it hasn't been configured yet and is at its default value.
These are docs for v1.2.6. If you need docs for the beta (older version, v0.0.11), Unfortunately github doesn't host wiki branches so to view documentation for this version you will need to clone https://github.com/FRCTeam3044/OxConfig.wiki.git on branch b0.0.11