Class CommandSwerveDrivetrain
- All Implemented Interfaces:
Subsystem,AutoCloseable
-
Nested Class Summary
Nested classes/interfaces inherited from class com.ctre.phoenix6.swerve.SwerveDrivetrain
SwerveDrivetrain.DeviceConstructor<DeviceT extends Object>, SwerveDrivetrain.OdometryThread, SwerveDrivetrain.SwerveControlParameters, SwerveDrivetrain.SwerveDriveState -
Field Summary
Fields inherited from class com.ctre.phoenix6.swerve.SwerveDrivetrain
kNumConfigAttempts, m_drivetrainId, m_jni, m_telemetryJNI -
Constructor Summary
ConstructorsConstructorDescriptionCommandSwerveDrivetrain(SwerveDrivetrainConstants drivetrainConstants, double odometryUpdateFrequency, SwerveModuleConstants<?, ?, ?>... modules) Constructs a CTRE SwerveDrivetrain using the specified constants.CommandSwerveDrivetrain(SwerveDrivetrainConstants drivetrainConstants, double odometryUpdateFrequency, Matrix<N3, N1> odometryStandardDeviation, Matrix<N3, N1> visionStandardDeviation, SwerveModuleConstants<?, ?, ?>... modules) Constructs a CTRE SwerveDrivetrain using the specified constants.CommandSwerveDrivetrain(SwerveDrivetrainConstants drivetrainConstants, SwerveModuleConstants<?, ?, ?>... modules) Constructs a CTRE SwerveDrivetrain using the specified constants. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddVisionMeasurement(Pose2d visionRobotPoseMeters, double timestampSeconds) Adds a vision measurement to the Kalman Filter.voidaddVisionMeasurement(Pose2d visionRobotPoseMeters, double timestampSeconds, Matrix<N3, N1> visionMeasurementStdDevs) Adds a vision measurement to the Kalman Filter.applyRequest(Supplier<SwerveRequest> request) Returns a command that applies the specified control request to this swerve drivetrain.voidperiodic()samplePoseAt(double timestampSeconds) Return the pose at a given timestamp, if the buffer is not empty.sysIdDynamic(SysIdRoutine.Direction direction) Runs the SysId Dynamic test in the given direction for the routine specified bym_sysIdRoutineToApply.sysIdQuasistatic(SysIdRoutine.Direction direction) Runs the SysId Quasistatic test in the given direction for the routine specified bym_sysIdRoutineToApply.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, resetPose, resetRotation, resetTranslation, seedFieldCentric, seedFieldCentric, setControl, setOperatorPerspectiveForward, setStateStdDevs, setVisionMeasurementStdDevs, tareEverything, updateSimStateMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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
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 drivemodules- 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 driveodometryUpdateFrequency- 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 driveodometryUpdateFrequency- 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 radiansvisionStandardDeviation- The standard deviation for vision calculation in the form [x, y, theta]ᵀ, with units in meters and radiansmodules- Constants for each specific module
-
-
Method Details
-
applyRequest
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
Runs the SysId Quasistatic test in the given direction for the routine specified bym_sysIdRoutineToApply.- Parameters:
direction- Direction of the SysId Quasistatic test- Returns:
- Command to run
-
sysIdDynamic
Runs the SysId Dynamic test in the given direction for the routine specified bym_sysIdRoutineToApply.- Parameters:
direction- Direction of the SysId Dynamic test- Returns:
- Command to run
-
periodic
public void periodic() -
addVisionMeasurement
Adds a vision measurement to the Kalman Filter. This will correct the odometry pose estimate while still accounting for measurement noise.- Overrides:
addVisionMeasurementin classSwerveDrivetrain<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:
addVisionMeasurementin classSwerveDrivetrain<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
Return the pose at a given timestamp, if the buffer is not empty.- Overrides:
samplePoseAtin classSwerveDrivetrain<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).
-