Class Module

java.lang.Object
com.marswars.mechanisms.MechBase
com.marswars.swerve_lib.module.Module
All Implemented Interfaces:
SubsystemIoBase
Direct Known Subclasses:
ModuleTalonFX

public abstract class Module extends MechBase
Base class for swerve modules with drive and steer control.
  • Field Details

    • config_

      protected final SwerveModuleConfig config_
    • module_index_

      protected final int module_index_
    • neutral_mode_

      protected NeutralModeValue neutral_mode_
    • setpoint_

      protected SwerveModuleState setpoint_
    • inputs_

      protected final com.marswars.swerve_lib.module.ModuleInputsAutoLogged inputs_
    • drive_conn_deb_

      protected final Debouncer drive_conn_deb_
    • steer_conn_deb_

      protected final Debouncer steer_conn_deb_
    • drive_disconnected_alert_

      protected final Alert drive_disconnected_alert_
    • steer_disconnected_alert_

      protected final Alert steer_disconnected_alert_
    • module_encoder_alert_

      protected final Alert module_encoder_alert_
  • Constructor Details

  • Method Details

    • runSetpoint

      public void runSetpoint(SwerveModuleState state, Module.DriveControlMode DriveMode, Module.SteerControlMode SteerMode)
      Runs the module with the specified setpoint state. Mutates the state to optimize it.
    • runCharacterization

      public void runCharacterization(double output)
      Runs the module with the specified output while controlling to zero degrees.
    • stop

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

      public Rotation2d getAngle()
      Returns the current turn angle of the module.
    • getPositionMeters

      public double getPositionMeters()
      Returns the current drive position of the module in meters.
    • getVelocityMetersPerSec

      public double getVelocityMetersPerSec()
      Returns the current drive velocity of the module in meters per second.
    • getPosition

      public SwerveModulePosition getPosition()
      Returns the module position (turn angle and drive position).
    • getCurrentState

      public SwerveModuleState getCurrentState()
      Returns the module state (turn angle and drive velocity).
    • getSetpointState

      public SwerveModuleState getSetpointState()
      Returns the module setpoint state (turn angle and drive velocity).
    • getWheelRadiusCharacterizationPosition

      public double getWheelRadiusCharacterizationPosition()
      Returns the module position in radians.
    • getFFCharacterizationVelocity

      public double getFFCharacterizationVelocity()
      Returns the module velocity in rotations/sec (Phoenix native units).
    • getTranslation

      public Translation2d getTranslation()
      Returns the translation of the module in the robot's coordinate system.
      Returns:
      Translation2d representing the module's position in meters
    • setDriveOpenLoop

      public abstract void setDriveOpenLoop(double output)
      Run the drive motor at the specified open loop value.
    • setSteerOpenLoop

      public abstract void setSteerOpenLoop(double output)
      Run the turn motor at the specified open loop value.
    • setDriveVelocity

      public abstract void setDriveVelocity(double velocityRadPerSec)
      Run the drive motor at the specified velocity.
    • setSteerPosition

      public abstract void setSteerPosition(Rotation2d rotation)
      Run the turn motor to the specified rotation.
    • setDriveGains

      public abstract void setDriveGains(int slot, SlotConfigs gains)
      Set the gains for the module drive motors to the given slot
    • setSteerGains

      public abstract void setSteerGains(SlotConfigs gains)
      Set the gains for the module steer motors to the given slot
    • setModuleOffset

      public void setModuleOffset()
      Stores the current encoder reading as an offset
    • setNeutralMode

      public void setNeutralMode(NeutralModeValue mode)
      Sets the neutral mode for both motors