Skip to content

Class subsystems::CommandSwerveDrivetrain

ClassList > subsystems > CommandSwerveDrivetrain

Class that extends the Phoenix 6 SwerveDrivetrain class and implements Subsystem so it can easily be used in command-based projects.

  • #include <CommandSwerveDrivetrain.h>

Inherits the following classes: frc2::SubsystemBase, TunerSwerveDrivetrain

Public Types inherited from TunerSwerveDrivetrain

See TunerSwerveDrivetrain

Type Name
typedef swerve::SwerveModuleConstants< configs::TalonFXConfiguration, configs::TalonFXConfiguration, configs::CANcoderConfiguration > SwerveModuleConstants

Public Functions

Type Name
void AddVisionMeasurement (frc::Pose2d visionRobotPose, units::second_t timestamp) override
Adds a vision measurement to the Kalman Filter. This will correct the odometry pose estimate while still accounting for measurement noise.
void AddVisionMeasurement (frc::Pose2d visionRobotPose, units::second_t timestamp, std::array< double, 3 > visionMeasurementStdDevs) override
Adds a vision measurement to the Kalman Filter. This will correct the odometry pose estimate while still accounting for measurement noise.
frc2::CommandPtr ApplyRequest (RequestSupplier request)
Returns a command that applies the specified control request to this swerve drivetrain.
frc2::CommandPtr ApplyRequest (RequestSupplier request)
Returns a command that applies the specified control request to this swerve drivetrain.
CommandSwerveDrivetrain (swerve::SwerveDrivetrainConstants const & driveTrainConstants, ModuleConstants const &... modules)
Constructs a CTRE SwerveDrivetrain using the specified constants.
CommandSwerveDrivetrain (swerve::SwerveDrivetrainConstants const & driveTrainConstants, units::hertz_t odometryUpdateFrequency, ModuleConstants const &... modules)
Constructs a CTRE SwerveDrivetrain using the specified constants.
CommandSwerveDrivetrain (swerve::SwerveDrivetrainConstants const & driveTrainConstants, units::hertz_t odometryUpdateFrequency, std::array< double, 3 > const & odometryStandardDeviation, std::array< double, 3 > const & visionStandardDeviation, ModuleConstants const &... modules)
Constructs a CTRE SwerveDrivetrain using the specified constants.
void Periodic () override
frc2::CommandPtr SysIdDynamic (frc2::sysid::Direction direction)
Runs the SysId Dynamic test in the given direction for the routine specified by m_sysIdRoutineToApply.
frc2::CommandPtr SysIdQuasistatic (frc2::sysid::Direction direction)
Runs the SysId Quasistatic test in the given direction for the routine specified by m_sysIdRoutineToApply.

Public Functions inherited from TunerSwerveDrivetrain

See TunerSwerveDrivetrain

Type Name
TunerSwerveDrivetrain (swerve::SwerveDrivetrainConstants const & driveTrainConstants, ModuleConstants const &... modules)
Constructs a CTRE SwerveDrivetrain using the specified constants.
TunerSwerveDrivetrain (swerve::SwerveDrivetrainConstants const & driveTrainConstants, units::hertz_t odometryUpdateFrequency, ModuleConstants const &... modules)
Constructs a CTRE SwerveDrivetrain using the specified constants.
TunerSwerveDrivetrain (swerve::SwerveDrivetrainConstants const & driveTrainConstants, units::hertz_t odometryUpdateFrequency, std::array< double, 3 > const & odometryStandardDeviation, std::array< double, 3 > const & visionStandardDeviation, ModuleConstants const &... modules)
Constructs a CTRE SwerveDrivetrain using the specified constants.

Public Functions Documentation

function AddVisionMeasurement [1/2]

Adds a vision measurement to the Kalman Filter. This will correct the odometry pose estimate while still accounting for measurement noise.

inline void subsystems::CommandSwerveDrivetrain::AddVisionMeasurement (
    frc::Pose2d visionRobotPose,
    units::second_t timestamp
) override

Parameters:

  • visionRobotPose The pose of the robot as measured by the vision camera.
  • timestamp The timestamp of the vision measurement in seconds.

function AddVisionMeasurement [2/2]

Adds a vision measurement to the Kalman Filter. This will correct the odometry pose estimate while still accounting for measurement noise.

inline void subsystems::CommandSwerveDrivetrain::AddVisionMeasurement (
    frc::Pose2d visionRobotPose,
    units::second_t timestamp,
    std::array< double, 3 > visionMeasurementStdDevs
) override

Note that the vision measurement standard deviations passed into this method will continue to apply to future measurements until a subsequent call to SetVisionMeasurementStdDevs or this method.

Parameters:

  • visionRobotPose The pose of the robot as measured by the vision camera.
  • timestamp The timestamp of the vision measurement in seconds.
  • visionMeasurementStdDevs Standard deviations of the vision pose measurement.

function ApplyRequest [1/2]

Returns a command that applies the specified control request to this swerve drivetrain.

template<typename RequestSupplier>
inline frc2::CommandPtr subsystems::CommandSwerveDrivetrain::ApplyRequest (
    RequestSupplier request
) 

This captures the returned swerve request by reference, so it must live for at least as long as the drivetrain. This can be done by storing the request as a member variable of your drivetrain subsystem or robot.

Parameters:

  • request Function returning the request to apply

Returns:

Command to run


function ApplyRequest [2/2]

Returns a command that applies the specified control request to this swerve drivetrain.

template<typename RequestSupplier>
inline frc2::CommandPtr subsystems::CommandSwerveDrivetrain::ApplyRequest (
    RequestSupplier request
) 

Parameters:

  • request Function returning the request to apply

Returns:

Command to run


function CommandSwerveDrivetrain [1/3]

Constructs a CTRE SwerveDrivetrain using the specified constants.

template<std::same_as< SwerveModuleConstants >... ModuleConstants>
inline subsystems::CommandSwerveDrivetrain::CommandSwerveDrivetrain (
    swerve::SwerveDrivetrainConstants const & driveTrainConstants,
    ModuleConstants const &... modules
) 

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

function CommandSwerveDrivetrain [2/3]

Constructs a CTRE SwerveDrivetrain using the specified constants.

template<std::same_as< SwerveModuleConstants >... ModuleConstants>
inline subsystems::CommandSwerveDrivetrain::CommandSwerveDrivetrain (
    swerve::SwerveDrivetrainConstants const & driveTrainConstants,
    units::hertz_t odometryUpdateFrequency,
    ModuleConstants const &... modules
) 

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

function CommandSwerveDrivetrain [3/3]

Constructs a CTRE SwerveDrivetrain using the specified constants.

template<std::same_as< SwerveModuleConstants >... ModuleConstants>
inline subsystems::CommandSwerveDrivetrain::CommandSwerveDrivetrain (
    swerve::SwerveDrivetrainConstants const & driveTrainConstants,
    units::hertz_t odometryUpdateFrequency,
    std::array< double, 3 > const & odometryStandardDeviation,
    std::array< double, 3 > const & visionStandardDeviation,
    ModuleConstants const &... modules
) 

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
  • visionStandardDeviation The standard deviation for vision calculation
  • modules Constants for each specific module

function Periodic

void subsystems::CommandSwerveDrivetrain::Periodic () override

function SysIdDynamic

Runs the SysId Dynamic test in the given direction for the routine specified by m_sysIdRoutineToApply.

inline frc2::CommandPtr subsystems::CommandSwerveDrivetrain::SysIdDynamic (
    frc2::sysid::Direction direction
) 

Parameters:

  • direction Direction of the SysId Dynamic test

Returns:

Command to run


function SysIdQuasistatic

Runs the SysId Quasistatic test in the given direction for the routine specified by m_sysIdRoutineToApply.

inline frc2::CommandPtr subsystems::CommandSwerveDrivetrain::SysIdQuasistatic (
    frc2::sysid::Direction direction
) 

Parameters:

  • direction Direction of the SysId Quasistatic test

Returns:

Command to run



The documentation for this class was generated from the following file src/main/include/subsystems/CommandSwerveDrivetrain.h