Class TuningCommands

java.lang.Object
frc.robot.subsystems.swerve.util.TuningCommands

public final class TuningCommands extends Object
Collection of command factories used for drivetrain tuning and characterization.

This class provides reusable command sequences for empirically determining drivetrain parameters such as feedforward gains and effective wheel radius. These commands are intended to be run manually during calibration and development, not during normal match operation.

This class is non-instantiable and only contains static factory methods.

  • Method Details

    • feedforwardCharacterization

      public static Command feedforwardCharacterization(Swerve swerve, DoubleConsumer runCharacterization, DoubleSupplier getFFCharacterizationVelocity)
      Creates a command to characterize drivetrain feedforward constants.

      This routine performs a quasi-static ramp test by slowly increasing applied voltage while measuring the resulting drivetrain velocity. The collected data is fit using linear regression to estimate:

      • kS - static friction voltage
      • kV - velocity-proportional voltage

      The characterization process consists of:

      1. Orient all modules to face forward
      2. Holding zero output to allow modules to fully orient
      3. Linearly ramping voltage at a fixed rate
      4. Recording velocity and voltage samples each loop

      When the command is cancelled, the collected samples are fit and the resulting constants are printed to the console and logged.

      This routine should be run on flat carpet with minimal disturbances.

      Parameters:
      swerve - the swerve subsystem being characterized
      runCharacterization - consumer that applies a raw voltage command to the drivetrain
      getFFCharacterizationVelocity - supplier that returns the current drivetrain velocity for sampling
      Returns:
      a command that performs feedforward characterization
    • wheelRadiusCharacterization

      public static Command wheelRadiusCharacterization(Swerve swerve, Consumer<ChassisSpeeds> setModuleStates, Supplier<double[]> getWheelRadiusCharacterizationPositions, Supplier<Rotation2d> gyroYaw)
      Creates a command to characterize the effective wheel radius of the drivetrain.

      This routine estimates wheel radius by rotating the robot in place and comparing the integrated gyro rotation against the average wheel travel. The wheel radius is computed using the relationship:

       wheelRadius = (robotRotation * driveBaseRadius) / wheelTravel
       

      The command runs two sequences in parallel:

      • A drive sequence that smoothly accelerates rotational speed
      • A measurement sequence that integrates gyro rotation and wheel deltas

      Intermediate values and the computed wheel radius are logged continuously for validation and offline analysis.

      This routine assumes:

      • Accurate gyro measurements
      • Consistent wheel traction during rotation
      • Correct drivetrain geometry constants
      Parameters:
      swerve - the swerve subsystem being characterized
      setModuleStates - consumer used to command rotational chassis speeds
      getWheelRadiusCharacterizationPositions - supplier of wheel position measurements
      gyroYaw - supplier of the current robot yaw angle
      Returns:
      a command that performs wheel radius characterization