Class SwerveOffsetParams

java.lang.Object
frc.robot.subsystems.swerve.SwerveOffsetParams

public final class SwerveOffsetParams extends Object
The swerve CANcoder magnet offsets as params, group swerve, so a module re-zeroed in the pit (SwerveAlignment) can be saved without a code change.

The offsets are per robot: they live in params/robots/<robot>/swerve.json, and each default is the offset in that robot's config class (FM2026 and so on). A missing or unreadable file, or a value out of bounds, leaves the config's offset.

Read once at boot, before the drivetrain is built, because CTRE writes each offset into its CANcoder's config when the drivetrain starts. A value changed later (tuning mode, disabled) does not reach the modules until the robot reboots, and an alert says so until then. Applying it live would take a blocking CANcoder config call and rebuilt module constants.

  • Field Details

  • Method Details

    • declare

      public static List<DoubleParam> declare(SwerveConfig config)
      Declares the four offsets with this robot's config values as the defaults. Declared once per run; a second call must come from the same robot config.
      Parameters:
      config - the robot's swerve config, offsets as its config class set them
      Returns:
      the params, in the order of KEYS
    • apply

      public static void apply(SwerveConfig config)
      Declares the offsets and gives the config their resolved values. Call once at boot, after Params.start(Path, String, Path, ParamTransport) and before the drivetrain is built.
      Parameters:
      config - the robot's swerve config
    • changedSinceBoot

      public static boolean changedSinceBoot()
      Whether an offset differs from the one the drivetrain booted with, as of periodic().
    • periodic

      public static void periodic()
      Raises an alert while an offset differs from the one the drivetrain booted with.