Class Swerve

All Implemented Interfaces:
Sendable, Subsystem

public class Swerve extends SubsystemBase
Swerve Subsystem
  • Field Details

  • Constructor Details

  • Method Details

    • drive

      public void drive(Translation2d translation, double rotation, boolean fieldRelative, boolean isOpenLoop)
      Tele-Op Drive method
      Parameters:
      translation - The magnitude in XY
      rotation - The magnitude in rotation
      fieldRelative - Whether or not field relative
      isOpenLoop - Whether or not Open or Closed Loop
    • setModuleStates

      public void setModuleStates(SwerveModuleState[] desiredStates)
      Set Swerve Module States
      Parameters:
      desiredStates - Array of desired states
    • setModuleStates

      public void setModuleStates(ChassisSpeeds chassisSpeeds)
      Sets swerve module states using Chassis Speeds.
      Parameters:
      chassisSpeeds - The desired Chassis Speeds
    • getChassisSpeeds

      public ChassisSpeeds getChassisSpeeds()
      Get current Chassis Speeds
      Returns:
      The current ChassisSpeeds
    • getModuleStates

      public SwerveModuleState[] getModuleStates()
      Get Swerve Module States
      Returns:
      Array of Swerve Module States
    • getModulePositions

      public SwerveModulePosition[] getModulePositions()
      Get Swerve Module Positions
      Returns:
      Array of Swerve Module Positions
    • getPose

      public Pose2d getPose()
      Get Position on field from Odometry
      Returns:
      Pose2d on the field
    • resetOdometry

      public void resetOdometry(Pose2d pose)
      Set the position on the field with given Pose2d
      Parameters:
      pose - Pose2d to set
    • getHeading

      public Rotation2d getHeading()
      Get Rotation of robot from odometry
      Returns:
      Heading of robot relative to the field as Rotation2d
    • getGyroYaw

      public Rotation2d getGyroYaw()
      Get Rotation from the gyro
      Returns:
      Current rotation/yaw of gyro as Rotation2d
    • getFieldRelativeHeading

      public Rotation2d getFieldRelativeHeading()
      Get Field Relative Heading
      Returns:
      The current field relative heading in Rotation2d
    • resetFieldRelativeOffset

      public void resetFieldRelativeOffset()
      Resets the gyro field relative driving offset
    • periodic

      public void periodic()
    • setMotorsZero

      public void setMotorsZero()
      Sets motors to 0 or inactive.
    • wheelsIn

      public void wheelsIn()
      Make an X pattern with the wheels
    • getSwerveModulePositions

      public SwerveModulePosition[] getSwerveModulePositions()
      Gets a list containing all 4 swerve module positions
    • shouldFlipPath

      public static boolean shouldFlipPath()
      Determine whether or not to flight the auto path
      Returns:
      True if flip path to Red Alliance, False if Blue
    • distanceFromSpeaker

      public double distanceFromSpeaker()
      Returns the distance between the speaker and Swerve
      Returns:
      the difference between the pose of speaker and swerve