Class Params

java.lang.Object
frc.spectrumLib.params.Params

public final class Params extends Object
Robot params: values tuned on the robot that survive the next deploy, without editing code.

Layers

Each param is declared in code (ParamGroup) and resolved from these layers, later ones winning:
  1. the default in the declaration;
  2. <deploy>/params/<group>.json, in git;
  3. <deploy>/params/robots/<robot>/<group>.json, for one robot, in git;
  4. <robot>/<group>.json in the robot-local folder (e.g. /home/systemcore/params/FM2026/), which a deploy does not wipe: what was saved in the pit. A hard-stop group's file is used only on the robot it was saved on (HardwareStamp);
  5. live changes from the dashboard, only with a transport (tuning mode) and only while disabled with no field attached (liveChangesAllowed(boolean, boolean)).
A file holds a JSON object of key: value; a value may also be an object with the value under "value" (the local file records replaced and savedAt that way).

Never stops the robot booting

A missing file is skipped. An unreadable file (bad JSON, or a key given twice), or a value of the wrong type or out of bounds, is skipped too, and raises an alert; the value comes from the layer below. A key no code declares raises an info alert, since it is usually a typo. A bad default in code is a bug and throws.

Moving a controller between robots

The local folder is per robot config, and a hard-stop group's file (swerve offsets, soft limits) carries a HardwareStamp: a file saved on another robot, or one whose robot cannot be checked, is refused with an error alert and the group's values come from git. A file saved before the folder was per robot (<local>/<group>.json) is read from there until the next save moves it; a hard-stop group's such file has no stamp, so it is refused the same way.

Replay

Every value and the layer it came from is a logged input (ParamsInputs), processed when a param is declared and whenever a value changes, so replay runs on the robot's values. Live changes are applied in periodic() on the main thread, never in replay.

Saving

The transport's SaveParams button, or requestSave(), writes every value that differs from the git layers to the robot-local folder. Disabled only; the file write runs on a background thread and reaches the disk before it replaces the old file.

Main thread only.

  • Field Details

  • Method Details

    • group

      public static ParamGroup group(String name)
      Starts declaring params in a group. Hold the params in static final fields so each is declared once.
    • start

      public static void start(Path deployParamsDir, String robot, Path localRoot, ParamTransport transport)
    • start

      public static void start(Path deployParamsDir, String robot, Path localRoot, ParamTransport transport, Map<String, HardwareStamp> stamps)
      Reads the params files and re-resolves anything declared so far. Call once at boot, after Logger.start() and before the subsystems are built.
      Parameters:
      deployParamsDir - the deploy folder's params directory
      robot - this robot's name, for params/robots/<robot>/ and <localRoot>/<robot>/
      localRoot - the robot-local folder that survives deploys, or null for none (replay)
      transport - where live tuning comes from; used only in TuningMode
      stamps - the hard-stop groups, whose local file must have been saved on this robot
    • periodic

      public static void periodic()
      Applies live changes (liveChangesAllowed(boolean, boolean)), logs the values, handles a save. Call once per loop, before anything reads a param.
    • requestSave

      public static void requestSave()
      Asks for a save at the next periodic(); refused unless disabled.
    • liveTuning

      public static boolean liveTuning()
      Whether live tuning is running (tuning mode on and a transport given).
    • find

      public static Param<?> find(String path)
      The declared param at group/key, or null.
    • refusedInFile

      public static boolean refusedInFile(Param<?> p)
      Whether a params file refused this param's value (wrong type or out of bounds), or its group's file is unreadable or was saved on another robot, so the value came from a lower layer. Read-only, for checks. Judged on the files this run read: in replay, the replaying PC's.
    • checkFile

      public static List<String> checkFile(Path file)
      Problems with a params file against the params declared so far: unreadable, a key nobody declares, or a value of the wrong type or out of bounds. For tests and checks; it applies nothing.