Class SwerveMech

java.lang.Object
com.marswars.mechanisms.MechBase
com.marswars.swerve_lib.SwerveMech
All Implemented Interfaces:
SubsystemIoBase

public class SwerveMech extends MechBase
Mechanism implementation for a four-module swerve drivetrain.
  • Constructor Details

    • SwerveMech

      public SwerveMech(String logging_prefix, SwerveDriveConfig config)
      Creates a new swerve mechanism using the provided drivetrain configuration.
      Parameters:
      logging_prefix - Logging prefix for telemetry
      config - Drivetrain configuration
  • Method Details

    • readInputs

      public void readInputs(double timestamp)
      Read inputs from hardware or simulation
      Parameters:
      timestamp - the current timestamp
    • writeOutputs

      public void writeOutputs(double timestamp)
      Write outputs to hardware or simulation
      Parameters:
      timestamp - the current timestamp
    • logData

      public void logData()
      Log data to NetworkTables or other logging systems
    • setChassisRequest

      public void setChassisRequest(ChassisRequest request)
      Sets the chassis request for the swerve drive.
      Parameters:
      request -
    • setChassisRequestParameters

      public void setChassisRequestParameters(Pose2d pose, Rotation2d operator_forward_direction)
      Sets the chassis request parameters for the swerve drive.
      Parameters:
      pose - The current robot pose.
      operator_forward_direction - The operator's forward direction.
    • setGyroYaw

      public void setGyroYaw(Rotation2d yaw)
      Sets the gyro yaw position.
      Parameters:
      yaw - The desired yaw rotation.
    • setModuleOffsets

      public void setModuleOffsets()
      Stores the current encoder readings as offsets
    • setNeutralMode

      public void setNeutralMode(NeutralModeValue mode)
      Sets the neutral mode for all swerve modules.
      Parameters:
      mode - The desired neutral mode
    • getModules

      public Module[] getModules()
      Returns the array of swerve modules in order (FL, FR, BL, BR).
      Returns:
      the module array
    • getCurrentChassisSpeeds

      public ChassisSpeeds getCurrentChassisSpeeds()
      Returns the measured chassis speeds of the robot.
      Returns:
      ChassisSpeeds object representing the robot's chassis speeds
    • getSetpointChassisSpeeds

      public ChassisSpeeds getSetpointChassisSpeeds()
      Returns the setpoint chassis speeds of the robot.
      Returns:
      ChassisSpeeds object representing the robot's setpoint chassis speeds
    • getCurrentModuleStates

      public SwerveModuleState[] getCurrentModuleStates()
      Returns the module states of the swerve drive.
      Returns:
      SwerveModuleState[] array of module states
    • isSkidding

      public boolean isSkidding()
      Detects wheel skid by comparing the per-module translational velocities after the shared rotational component is removed. If the spread between the fastest and slowest module exceeds the (speed-scaled) skid threshold, at least one wheel is slipping relative to the others.
      Returns:
      true if the drivetrain is skidding, false otherwise
    • getSetpointModuleStates

      public SwerveModuleState[] getSetpointModuleStates()
      Returns the setpoint module states of the swerve drive.
      Returns:
      SwerveModuleState[] array of setpoint module states
    • getModulePositions

      public SwerveModulePosition[] getModulePositions()
      Returns the module positions of the swerve drive.
      Returns:
      SwerveModulePosition[] array of module positions
    • getGyroYaw

      public Rotation2d getGyroYaw()
      Returns the raw gyro rotation used for odometry.
      Returns:
      Rotation2d representing the raw gyro rotation
    • getGyroYawRate

      public double getGyroYawRate()
      Returns the gyro yaw rate in radians per second.
      Returns:
      yaw rate in radians per second
    • getGyroRotation

      public Rotation3d getGyroRotation()
      Returns the gyro rotation as a Rotation3d containing pitch, yaw, and roll.
      Returns:
      Rotation3d representing the gyro rotation
    • getKinematics

      public SwerveDriveKinematics getKinematics()
      Returns the swerve drive kinematics instance
      Returns:
      SwerveDriveKinematics object representing the swerve drive