Class CommandSwerveDrivetrain

java.lang.Object
com.ctre.phoenix6.swerve.SwerveDrivetrain<com.ctre.phoenix6.hardware.TalonFX,com.ctre.phoenix6.hardware.TalonFX,com.ctre.phoenix6.hardware.CANcoder>
com.stuypulse.robot.subsystems.swerve.TunerConstants.TunerSwerveDrivetrain
com.stuypulse.robot.subsystems.swerve.CommandSwerveDrivetrain
All Implemented Interfaces:
edu.wpi.first.wpilibj2.command.Subsystem, AutoCloseable

public class CommandSwerveDrivetrain extends TunerConstants.TunerSwerveDrivetrain implements edu.wpi.first.wpilibj2.command.Subsystem
Class that extends the Phoenix 6 SwerveDrivetrain class and implements Subsystem so it can easily be used in command-based projects.
  • Nested Class Summary

    Nested classes/interfaces inherited from class com.ctre.phoenix6.swerve.SwerveDrivetrain

    com.ctre.phoenix6.swerve.SwerveDrivetrain.DeviceConstructor<DeviceT extends Object>, com.ctre.phoenix6.swerve.SwerveDrivetrain.OdometryThread, com.ctre.phoenix6.swerve.SwerveDrivetrain.SwerveControlParameters, com.ctre.phoenix6.swerve.SwerveDrivetrain.SwerveDriveState
  • Field Summary

    Fields inherited from class com.ctre.phoenix6.swerve.SwerveDrivetrain

    kNumConfigAttempts, m_drivetrainId, m_jni, m_telemetryJNI
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    CommandSwerveDrivetrain(com.ctre.phoenix6.swerve.SwerveDrivetrainConstants drivetrainConstants, com.ctre.phoenix6.swerve.SwerveModuleConstants<?,?,?>... modules)
    Constructs a CTRE SwerveDrivetrain using the specified constants.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addVisionMeasurement(edu.wpi.first.math.geometry.Pose2d visionRobotPoseMeters, double timestampSeconds)
    Adds a vision measurement to the Kalman Filter.
    void
    addVisionMeasurement(edu.wpi.first.math.geometry.Pose2d visionRobotPoseMeters, double timestampSeconds, edu.wpi.first.math.Matrix<edu.wpi.first.math.numbers.N3,edu.wpi.first.math.numbers.N1> visionMeasurementStdDevs)
    Adds a vision measurement to the Kalman Filter.
    void
     
    void
    drive(com.stuypulse.stuylib.math.Vector2D velocity, double rotation)
     
    edu.wpi.first.wpilibj2.command.Command
    followPathCommand(com.pathplanner.lib.path.PathPlannerPath path)
     
    edu.wpi.first.wpilibj2.command.Command
     
    edu.wpi.first.math.kinematics.ChassisSpeeds
     
    com.ctre.phoenix6.swerve.SwerveRequest.FieldCentric
     
    com.stuypulse.stuylib.math.Vector2D
     
     
    org.ironmaple.simulation.drivesims.SwerveDriveSimulation
     
    edu.wpi.first.math.kinematics.SwerveModuleState[]
     
    edu.wpi.first.math.geometry.Pose2d
     
    com.ctre.phoenix6.swerve.SwerveRequest.RobotCentric
     
    edu.wpi.first.math.geometry.Pose2d
     
    boolean
    isAlignedToTarget(edu.wpi.first.math.geometry.Pose2d target)
     
    void
     
    void
    resetPose(edu.wpi.first.math.geometry.Pose2d pose)
     
    void
    setControl(com.ctre.phoenix6.swerve.SwerveRequest request)
     
    edu.wpi.first.wpilibj2.command.Command
    sysIdDynamic(edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction direction)
    Runs the SysId Dynamic test in the given direction for the routine specified by m_sysIdRoutineToApply.
    edu.wpi.first.wpilibj2.command.Command
    sysIdQuasistatic(edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction direction)
    Runs the SysId Quasistatic test in the given direction for the routine specified by m_sysIdRoutineToApply.
    edu.wpi.first.wpilibj2.command.Command
    sysidRotationDynamic(edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction direction)
     
    edu.wpi.first.wpilibj2.command.Command
    sysidRotationQuasiStatic(edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction direction)
     
    edu.wpi.first.wpilibj2.command.Command
    sysidSteerDynamic(edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction direction)
     
    edu.wpi.first.wpilibj2.command.Command
    sysidSteerQuasistatic(edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction direction)
     

    Methods inherited from class com.ctre.phoenix6.swerve.SwerveDrivetrain

    close, configNeutralMode, configNeutralMode, getKinematics, getModule, getModuleLocations, getModules, getOdometryFrequency, getOdometryFrequencyMeasure, getOdometryThread, getOperatorForwardDirection, getPigeon2, getRotation3d, getState, getStateCopy, isOdometryValid, isOnCANFD, registerTelemetry, resetRotation, resetTranslation, samplePoseAt, seedFieldCentric, seedFieldCentric, setOperatorPerspectiveForward, setStateStdDevs, setVisionMeasurementStdDevs, tareEverything, updateSimState

    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, getName, idle, register, removeDefaultCommand, run, runEnd, runOnce, setDefaultCommand, simulationPeriodic, startEnd, startRun
  • Constructor Details

    • CommandSwerveDrivetrain

      protected CommandSwerveDrivetrain(com.ctre.phoenix6.swerve.SwerveDrivetrainConstants drivetrainConstants, com.ctre.phoenix6.swerve.SwerveModuleConstants<?,?,?>... modules)
      Constructs a CTRE SwerveDrivetrain using the specified constants.

      This constructs the underlying hardware devices, so users should not construct the devices themselves. If they need the devices, they can access them through getters in the classes.

      Parameters:
      drivetrainConstants - Drivetrain-wide constants for the swerve drive
      modules - Constants for each specific module
  • Method Details

    • getInstance

      public static CommandSwerveDrivetrain getInstance()
    • getFieldCentricSwerveRequest

      public com.ctre.phoenix6.swerve.SwerveRequest.FieldCentric getFieldCentricSwerveRequest()
    • getRobotCentricSwerveRequest

      public com.ctre.phoenix6.swerve.SwerveRequest.RobotCentric getRobotCentricSwerveRequest()
    • setControl

      public void setControl(com.ctre.phoenix6.swerve.SwerveRequest request)
      Overrides:
      setControl in class com.ctre.phoenix6.swerve.SwerveDrivetrain<com.ctre.phoenix6.hardware.TalonFX,com.ctre.phoenix6.hardware.TalonFX,com.ctre.phoenix6.hardware.CANcoder>
    • sysIdQuasistatic

      public edu.wpi.first.wpilibj2.command.Command sysIdQuasistatic(edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction direction)
      Runs the SysId Quasistatic test in the given direction for the routine specified by m_sysIdRoutineToApply.
      Parameters:
      direction - Direction of the SysId Quasistatic test
      Returns:
      Command to run
    • sysIdDynamic

      public edu.wpi.first.wpilibj2.command.Command sysIdDynamic(edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction direction)
      Runs the SysId Dynamic test in the given direction for the routine specified by m_sysIdRoutineToApply.
      Parameters:
      direction - Direction of the SysId Dynamic test
      Returns:
      Command to run
    • sysidRotationDynamic

      public edu.wpi.first.wpilibj2.command.Command sysidRotationDynamic(edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction direction)
    • sysidRotationQuasiStatic

      public edu.wpi.first.wpilibj2.command.Command sysidRotationQuasiStatic(edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction direction)
    • sysidSteerDynamic

      public edu.wpi.first.wpilibj2.command.Command sysidSteerDynamic(edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction direction)
    • sysidSteerQuasistatic

      public edu.wpi.first.wpilibj2.command.Command sysidSteerQuasistatic(edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction direction)
    • getMapleSimDrive

      public org.ironmaple.simulation.drivesims.SwerveDriveSimulation getMapleSimDrive()
    • addVisionMeasurement

      public void addVisionMeasurement(edu.wpi.first.math.geometry.Pose2d visionRobotPoseMeters, double timestampSeconds)
      Adds a vision measurement to the Kalman Filter. This will correct the odometry pose estimate while still accounting for measurement noise.
      Overrides:
      addVisionMeasurement in class com.ctre.phoenix6.swerve.SwerveDrivetrain<com.ctre.phoenix6.hardware.TalonFX,com.ctre.phoenix6.hardware.TalonFX,com.ctre.phoenix6.hardware.CANcoder>
      Parameters:
      visionRobotPoseMeters - The pose of the robot as measured by the vision camera.
      timestampSeconds - The timestamp of the vision measurement in seconds.
    • addVisionMeasurement

      public void addVisionMeasurement(edu.wpi.first.math.geometry.Pose2d visionRobotPoseMeters, double timestampSeconds, edu.wpi.first.math.Matrix<edu.wpi.first.math.numbers.N3,edu.wpi.first.math.numbers.N1> visionMeasurementStdDevs)
      Adds a vision measurement to the Kalman Filter. This will correct the odometry pose estimate while still accounting for measurement noise.

      Note that the vision measurement standard deviations passed into this method will continue to apply to future measurements until a subsequent call to SwerveDrivetrain.setVisionMeasurementStdDevs(Matrgix) or this method.

      Overrides:
      addVisionMeasurement in class com.ctre.phoenix6.swerve.SwerveDrivetrain<com.ctre.phoenix6.hardware.TalonFX,com.ctre.phoenix6.hardware.TalonFX,com.ctre.phoenix6.hardware.CANcoder>
      Parameters:
      visionRobotPoseMeters - The pose of the robot as measured by the vision camera.
      timestampSeconds - The timestamp of the vision measurement in seconds.
      visionMeasurementStdDevs - Standard deviations of the vision pose measurement in the form [x, y, theta]ᵀ, with units in meters and radians.
    • getPose

      public edu.wpi.first.math.geometry.Pose2d getPose()
    • isAlignedToTarget

      public boolean isAlignedToTarget(edu.wpi.first.math.geometry.Pose2d target)
    • getShooterPose

      public edu.wpi.first.math.geometry.Pose2d getShooterPose()
    • resetPose

      public void resetPose(edu.wpi.first.math.geometry.Pose2d pose)
      Overrides:
      resetPose in class com.ctre.phoenix6.swerve.SwerveDrivetrain<com.ctre.phoenix6.hardware.TalonFX,com.ctre.phoenix6.hardware.TalonFX,com.ctre.phoenix6.hardware.CANcoder>
    • configureAutoBuilder

      public void configureAutoBuilder()
    • followPathCommand

      public edu.wpi.first.wpilibj2.command.Command followPathCommand(String pathName)
    • followPathCommand

      public edu.wpi.first.wpilibj2.command.Command followPathCommand(com.pathplanner.lib.path.PathPlannerPath path)
    • getModuleStates

      public edu.wpi.first.math.kinematics.SwerveModuleState[] getModuleStates()
    • getChassisSpeeds

      public edu.wpi.first.math.kinematics.ChassisSpeeds getChassisSpeeds()
    • getFieldRelativeSpeeds

      public com.stuypulse.stuylib.math.Vector2D getFieldRelativeSpeeds()
    • drive

      public void drive(com.stuypulse.stuylib.math.Vector2D velocity, double rotation)
    • periodic

      public void periodic()
      Specified by:
      periodic in interface edu.wpi.first.wpilibj2.command.Subsystem