Class SwerveSubsystem

java.lang.Object
edu.wpi.first.wpilibj2.command.SubsystemBase
frc.robot.subsystems.SwerveSubsystem
All Implemented Interfaces:
edu.wpi.first.util.sendable.Sendable, edu.wpi.first.wpilibj2.command.Subsystem

public class SwerveSubsystem extends edu.wpi.first.wpilibj2.command.SubsystemBase
  • Constructor Summary

    Constructors
    Constructor
    Description
    This subsystems manages all of the swerve drive logic and also gives data to odometry
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    drive(double forwardMetersPerSecond, double sidewaysMetersPerSecond, double radiansPerSecond, boolean fieldRelative, boolean rateLimit)
    Swerve drive function.
    void
    driveRobotRelative(edu.wpi.first.math.kinematics.ChassisSpeeds chassisSpeeds)
    Drive the robot with ChassisSpeeds (mainly used for path planner)
    edu.wpi.first.math.kinematics.ChassisSpeeds
    Gets the robots chassis speed relative to the field
    edu.wpi.first.math.geometry.Pose2d
    Get robot's pose.
    edu.wpi.first.math.estimator.SwerveDrivePoseEstimator
    Get the pose estimator instance
    edu.wpi.first.math.kinematics.ChassisSpeeds
    Get the speed of the chassis relative to the robot
    double
    Get current heading of robot
    void
     
    void
    Resets swerve encoders
    void
    setModuleStates(edu.wpi.first.math.kinematics.SwerveModuleState[] desiredStates)
    Sets states of swerve modules
    void
    Set wheels to an X configuration for docking procedure.
    void
    Set wheels to a 0 configuration for calibration and testing.
    void
    Reset the gyro
    void
    Resets Gyro and odometry

    Methods inherited from class edu.wpi.first.wpilibj2.command.SubsystemBase

    addChild, getName, getSubsystem, initSendable, setName, setSubsystem

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface edu.wpi.first.wpilibj2.command.Subsystem

    defer, getCurrentCommand, getDefaultCommand, register, removeDefaultCommand, run, runEnd, runOnce, setDefaultCommand, simulationPeriodic, startEnd
  • Constructor Details

    • SwerveSubsystem

      public SwerveSubsystem()
      This subsystems manages all of the swerve drive logic and also gives data to odometry
  • Method Details

    • periodic

      public void periodic()
    • getPose

      public edu.wpi.first.math.geometry.Pose2d getPose()
      Get robot's pose.
      Returns:
      Returns the robots current position of the field as a Pose2d
    • heading

      public double heading()
      Get current heading of robot
      Returns:
      Heading of robot in radians
    • getPoseEstimator

      public edu.wpi.first.math.estimator.SwerveDrivePoseEstimator getPoseEstimator()
      Get the pose estimator instance
      Returns:
      Instance of the SwerveDrivePoseEstimator
    • driveRobotRelative

      public void driveRobotRelative(edu.wpi.first.math.kinematics.ChassisSpeeds chassisSpeeds)
      Drive the robot with ChassisSpeeds (mainly used for path planner)
      Parameters:
      chassisSpeeds - ChassisSpeeds object
    • getRobotRelativeSpeeds

      public edu.wpi.first.math.kinematics.ChassisSpeeds getRobotRelativeSpeeds()
      Get the speed of the chassis relative to the robot
      Returns:
      ChassisSpeeds of the current robots speed
    • getFieldRelativeChassisSpeeds

      public edu.wpi.first.math.kinematics.ChassisSpeeds getFieldRelativeChassisSpeeds()
      Gets the robots chassis speed relative to the field
      Returns:
      Returns robot speed as a ChassisSpeeds in meters/second
    • drive

      public void drive(double forwardMetersPerSecond, double sidewaysMetersPerSecond, double radiansPerSecond, boolean fieldRelative, boolean rateLimit)
      Swerve drive function.
      Parameters:
      forwardMetersPerSecond - The target forward m/s
      sidewaysMetersPerSecond - The target sideways m/s
      radiansPerSecond - The target Rad/s
      fieldRelative - If the robot is robot relative (forwards is front of robot) or field relative (forward is opposite side of field)
      rateLimit - If we should apply slew rates (should always be true unless you know what your doing)
    • setX

      public void setX()
      Set wheels to an X configuration for docking procedure.
    • setZero

      public void setZero()
      Set wheels to a 0 configuration for calibration and testing.
    • zeroGyro

      public void zeroGyro()
      Reset the gyro
    • zeroGyroAndOdometry

      public void zeroGyroAndOdometry()
      Resets Gyro and odometry
    • setModuleStates

      public void setModuleStates(edu.wpi.first.math.kinematics.SwerveModuleState[] desiredStates)
      Sets states of swerve modules
      Parameters:
      desiredStates - target states for the swerve modules (requires a list of 4 SwerveModuleStates)
    • resetEncoders

      public void resetEncoders()
      Resets swerve encoders