Class CommandSwerveDrivetrain

java.lang.Object
com.ctre.phoenix6.swerve.SwerveDrivetrain<TalonFX,TalonFX,CANcoder>
frc.robot.generated.TunerConstants.TunerSwerveDrivetrain
frc.robot.subsystems.CommandSwerveDrivetrain
All Implemented Interfaces:
Subsystem, AutoCloseable

public class CommandSwerveDrivetrain extends frc.robot.generated.TunerConstants.TunerSwerveDrivetrain implements Subsystem
Class that extends the Phoenix 6 SwerveDrivetrain class and implements Subsystem so it can easily be used in command-based projects. Generated by the 2026 Tuner X Swerve Project Generator https://v6.docs.ctr-electronics.com/en/stable/docs/tuner/tuner-swerve/index.html
  • Constructor Details

    • CommandSwerveDrivetrain

      public CommandSwerveDrivetrain(SwerveDrivetrainConstants drivetrainConstants, 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
    • CommandSwerveDrivetrain

      public CommandSwerveDrivetrain(SwerveDrivetrainConstants drivetrainConstants, double odometryUpdateFrequency, 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
      odometryUpdateFrequency - The frequency to run the odometry loop. If unspecified or set to 0 Hz, this is 250 Hz on CAN FD, and 100 Hz on CAN 2.0.
      modules - Constants for each specific module
    • CommandSwerveDrivetrain

      public CommandSwerveDrivetrain(SwerveDrivetrainConstants drivetrainConstants, double odometryUpdateFrequency, Matrix<N3,N1> odometryStandardDeviation, Matrix<N3,N1> visionStandardDeviation, 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
      odometryUpdateFrequency - The frequency to run the odometry loop. If unspecified or set to 0 Hz, this is 250 Hz on CAN FD, and 100 Hz on CAN 2.0.
      odometryStandardDeviation - The standard deviation for odometry calculation in the form [x, y, theta]ᵀ, with units in meters and radians
      visionStandardDeviation - The standard deviation for vision calculation in the form [x, y, theta]ᵀ, with units in meters and radians
      modules - Constants for each specific module
  • Method Details

    • applyRequest

      public Command applyRequest(Supplier<SwerveRequest> request)
      Returns a command that applies the specified control request to this swerve drivetrain.
      Parameters:
      request - Function returning the request to apply
      Returns:
      Command to run
    • sysIdQuasistatic

      public Command sysIdQuasistatic(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 Command sysIdDynamic(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
    • periodic

      public void periodic()
      Specified by:
      periodic in interface Subsystem
    • addVisionMeasurement

      public void addVisionMeasurement(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 SwerveDrivetrain<TalonFX,TalonFX,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(Pose2d visionRobotPoseMeters, double timestampSeconds, Matrix<N3,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(Matrix) or this method.

      Overrides:
      addVisionMeasurement in class SwerveDrivetrain<TalonFX,TalonFX,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.
    • samplePoseAt

      public Optional<Pose2d> samplePoseAt(double timestampSeconds)
      Return the pose at a given timestamp, if the buffer is not empty.
      Overrides:
      samplePoseAt in class SwerveDrivetrain<TalonFX,TalonFX,CANcoder>
      Parameters:
      timestampSeconds - The timestamp of the pose in seconds.
      Returns:
      The pose at the given timestamp (or Optional.empty() if the buffer is empty).