Class SwerveAlignment

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

public class SwerveAlignment extends Object
Publishes the raw per-module CANcoder data that swerve alignment needs.

CTRE's swerve telemetry only reports module angles after the magnet offset has been applied, so there is no way to recover the number that belongs in SwerveConfig.configEncoderOffsets(...) from a log or a dashboard. This class fills that gap: it publishes each module's offset-applied position, the magnet offset actually programmed into the device, and the difference between them, which is the "Absolute Position No Offset" value Phoenix Tuner X shows.

The Swerve Align page of the robot app (src/main/deploy/app/pages/swerve-align) subscribes to these keys over NetworkTables.

  • Field Details

  • Constructor Details

    • SwerveAlignment

      public SwerveAlignment(SwerveModule<?,?,CANcoder>[] modules, SwerveConfig config)
      Creates the alignment publisher.

      Construct this after optimizeBusUtilization() so the update frequencies it requests are not immediately thrown away.

      Parameters:
      modules - the drivetrain's modules, in SwerveConfig.getModules() order
      config - the swerve config the modules were built from
  • Method Details

    • log

      public void log()
      Refreshes and publishes the alignment data. Safe to call every robot loop.

      Only publishes while the robot is disabled. Alignment is a pit procedure done on blocks with the robot disabled. These are 32 keys at 20 Hz, about 77 records a second, going into a log that already overran DogLog's queue and dropped data during the 2026-09-05 17:10 session. There is nothing to learn from them while the robot is driving.

    • wrapRotations

      public static double wrapRotations(double rotations)
      Wraps a rotation count into [-0.5, 0.5), matching how CTRE reports CANcoder absolute position.
      Parameters:
      rotations - the value to wrap
      Returns:
      the equivalent value in [-0.5, 0.5)