Class Swerve

All Implemented Interfaces:
Sendable, Subsystem

public class Swerve extends SubsystemBase
Swerve Subsystem
  • Field Details

    • swerveMods

      public SwerveModule[] swerveMods
    • state

      public final RobotState state
    • initGyroBool

      public boolean initGyroBool
    • initGyro

      public Trigger initGyro
  • 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
    • resetFieldRelativeOffsetBasedOnPose

      public void resetFieldRelativeOffsetBasedOnPose()
      Set Field Relative Offset based on Pose
    • 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
    • setSpeedMultiplier

      public void setSpeedMultiplier(double multiplier)
    • getSpeedMultiplier

      public double getSpeedMultiplier()
    • teleOpDrive

      public Command teleOpDrive(CommandXboxController controller, boolean fieldRelative, boolean openLoop)
      Creates a command for driving the swerve drive during tele-op
      Parameters:
      controller - The driver controller
      fieldRelative - Whether the movement is relative to the field or absolute
      openLoop - Open or closed loop system
    • stop

      public Command stop()
    • followTrajectory

      public void followTrajectory(choreo.trajectory.SwerveSample sample)
      Follow Choreo Trajectory
      Parameters:
      sample - Swerve Sample
    • moveToPose

      public void moveToPose(Pose2d pose, double maxSpeed, double maxAcceleration)
      Move to a Pose2d
      Parameters:
      pose - Desired Pose2d
    • moveToPose

      public void moveToPose(Pose2d pose, double maxVelocity)
      Move to a Pose2d
      Parameters:
      pose - Desired Pose2d
    • moveToPose

      public void moveToPose(Pose2d pose)
      Move to a Pose2d
      Parameters:
      pose - Desired Pose2d