Class SwerveOffsetParams
java.lang.Object
frc.robot.subsystems.swerve.SwerveOffsetParams
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringIn the order ofSwerveConfig.getEncoderOffsetRotations().static final doubleAny offset has an equivalent within half a turn, and every robot's is there, so a value outside it is a typo (a misplaced digit, or degrees for rotations). -
Method Summary
Modifier and TypeMethodDescriptionstatic voidapply(SwerveConfig config) Declares the offsets and gives the config their resolved values.static booleanWhether an offset differs from the one the drivetrain booted with, as ofperiodic().static List<DoubleParam> declare(SwerveConfig config) Declares the four offsets with this robot's config values as the defaults.static voidperiodic()Raises an alert while an offset differs from the one the drivetrain booted with.
-
Field Details
-
GROUP
- See Also:
-
KEYS
In the order ofSwerveConfig.getEncoderOffsetRotations(). -
MAX_ABS_ROTATIONS
public static final double MAX_ABS_ROTATIONSAny offset has an equivalent within half a turn, and every robot's is there, so a value outside it is a typo (a misplaced digit, or degrees for rotations).- See Also:
-
-
Method Details
-
declare
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
Declares the offsets and gives the config their resolved values. Call once at boot, afterParams.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 ofperiodic(). -
periodic
public static void periodic()Raises an alert while an offset differs from the one the drivetrain booted with.
-