FRC2706 / 2018-2706-Robot-Code

Our 2018 robot code for FIRST POWER UP.
MIT License
1 stars 2 forks source link

Add Command and RobotMap configuration ability #10

Closed ryanlarkin closed 6 years ago

ryanlarkin commented 6 years ago

Using RobotConfig.get(String name, T defaultValue) allows the caller to get any String or primitive to load from a JSON file. The value is located by splitting the name by periods. The location of a given JSON in the directory /home/lvusr/config/, and the filename is the first section of the name ended with ".json". Any other tags are sub JSON objects. The final object contains "value" and "override" tags. The value element holds the JsonPrimitive value of the property, and the override element is whether or not the value should actually be used. This was done so that non-overridden values can be reset to the values in the code when they are left unchanged. All invalid config files are regenerated from where they became broken, or if there was no file in the first place.

There are a number of problems with this solution

  1. The solution makes use of templates. These are useful for things like RobotMap that don't know the type of the value that is going to be used, and reduces the amount of code needed to be written. This solution is somewhat messy because GSON (the JSON parser) can't handle templates, and each parameter must be cast to work with a valid GSON method, and cast back before being returned.
  2. It requires extra work in commands to get them working by requiring a name for each command. This is a bit annoying, but makes understanding what each command does a bit easier.
  3. Instances of a command that inadvertently have the same name could overwrite each others' values.
  4. Right now parameters for commands come from the command constructor, so to update values in JSON, the robot code must be restarted for changes to take effect. This shouldn't be a huge problem, since the code can be restarted from the driver station.

RobotConfig has been tested on my computer, but never on the actual robot. To avoid causing people to change all of their commands to integrate with RobotConfig in the future, this pull request should probably be merged as soon as it has been tested and reviewed adequately.