Class Module

java.lang.Object
frc.robot.subsystems.drive.module.Module

public class Module extends Object
Subsystem for a single swerve drive module.

Handles the control of drive and turn motors for a single wheel, including kinematics conversions and hardware fault monitoring.

  • Constructor Details

    • Module

      public Module(ModuleIO io, int index)
      Creates a new Module subsystem.
      Parameters:
      io - The abstraction layer for the module hardware.
      index - The index of the module (0-3).
  • Method Details

    • periodic

      public void periodic()
      Updates hardware inputs, calculates odometry data, and updates status alerts.
    • updateHighFreq

      public void updateHighFreq(double timestampSec)
      Updates high-frequency data for the module, which can be used for real-time pose estimation or control loops.
      Parameters:
      timestampSec - The timestamp for the data point.
    • runSetpoint

      public void runSetpoint(SwerveModuleState state)
      Runs the module with the specified setpoint state.

      Optimizes the state to minimize turn angle (turning < 90 degrees instead of > 90) and scales the drive velocity based on the cosine of the error between the setpoint angle and current angle.

      Parameters:
      state - The desired state (angle and velocity) for the module.
    • runCharacterization

      public void runCharacterization(Voltage output)
      Runs the module with the specified output while holding the turn module to zero degrees.
      Parameters:
      output - The voltage to apply to the drive motor.
    • stop

      public void stop()
      Disables all outputs to motors.
    • getCurrentAngle

      public Angle getCurrentAngle()
      Returns the current turn angle of the module.
      Returns:
      The current angle as an Angle measure.
    • getCurrentPosition

      public Distance getCurrentPosition()
      Returns the current drive position of the module in meters.
      Returns:
      The current distance as a Distance measure.
    • getCurrentVelocity

      public LinearVelocity getCurrentVelocity()
      Returns the current drive velocity of the module in meters per second.
      Returns:
      The current velocity as a LinearVelocity measure.
    • getPosition

      public SwerveModulePosition getPosition()
      Returns the module position (turn angle and drive position).
      Returns:
      The current SwerveModulePosition.
    • getState

      public SwerveModuleState getState()
      Returns the module state (turn angle and drive velocity).
      Returns:
      The current SwerveModuleState.
    • getOdometryPositions

      public SwerveModulePosition[] getOdometryPositions()
      Returns the module positions received this cycle from the asynchronous thread.
      Returns:
      An array of SwerveModulePositions.
    • getOdometryTimestamps

      public double[] getOdometryTimestamps()
      Returns the timestamps of the samples received this cycle from the asynchronous thread.
      Returns:
      An array of timestamps in seconds.
    • getWheelRadiusCharacterizationPosition

      public Angle getWheelRadiusCharacterizationPosition()
      Returns the module position in radians for wheel radius characterization.
      Returns:
      The drive position in radians.
    • getFFCharacterizationVelocity

      public AngularVelocity getFFCharacterizationVelocity()
      Returns the module velocity in rad/sec for feedforward characterization.
      Returns:
      The drive velocity in radians per second.
    • isHealthy

      public boolean isHealthy()
      Returns whether or not the subsystem is healthy
      Returns:
      True if the subsystem is healthy, false otherwise.
    • clearFaults

      public void clearFaults()
      Clears all faults and warnings.