Class CommandSwerveDrivetrain
- All Implemented Interfaces:
edu.wpi.first.wpilibj2.command.Subsystem,AutoCloseable
-
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
FieldsModifier and TypeFieldDescriptionprivate final edu.wpi.first.networktables.StructPublisher<edu.wpi.first.math.kinematics.ChassisSpeeds>private final com.ctre.phoenix6.swerve.SwerveRequest.FieldCentricprivate static final CommandSwerveDrivetrainprivate static final doubleprivate doubleprivate final com.ctre.phoenix6.swerve.SwerveRequest.SysIdSwerveTranslationprivate final com.ctre.phoenix6.swerve.SwerveRequest.SysIdSwerveRotationprivate edu.wpi.first.wpilibj.Notifierprivate final com.ctre.phoenix6.swerve.SwerveRequest.SysIdSwerveSteerGainsprivate final edu.wpi.first.wpilibj2.command.sysid.SysIdRoutineprivate final edu.wpi.first.wpilibj2.command.sysid.SysIdRoutineprivate final edu.wpi.first.wpilibj2.command.sysid.SysIdRoutineprivate final edu.wpi.first.wpilibj2.command.sysid.SysIdRoutineprivate edu.wpi.first.wpilibj2.command.sysid.SysIdRoutineprivate MapleSimSwerveDrivetrainprivate final edu.wpi.first.networktables.StructArrayPublisher<edu.wpi.first.math.kinematics.SwerveModuleState>private final edu.wpi.first.networktables.StructPublisher<edu.wpi.first.math.geometry.Pose2d>private final com.ctre.phoenix6.swerve.SwerveRequest.RobotCentricFields inherited from class com.ctre.phoenix6.swerve.SwerveDrivetrain
kNumConfigAttempts, m_drivetrainId, m_jni, m_telemetryJNI -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateCommandSwerveDrivetrain(com.ctre.phoenix6.swerve.SwerveDrivetrainConstants drivetrainConstants, double odometryUpdateFrequency, com.ctre.phoenix6.swerve.SwerveModuleConstants<?, ?, ?>... modules) Constructs a CTRE SwerveDrivetrain using the specified constants.privateCommandSwerveDrivetrain(com.ctre.phoenix6.swerve.SwerveDrivetrainConstants drivetrainConstants, double odometryUpdateFrequency, edu.wpi.first.math.Matrix<edu.wpi.first.math.numbers.N3, edu.wpi.first.math.numbers.N1> odometryStandardDeviation, edu.wpi.first.math.Matrix<edu.wpi.first.math.numbers.N3, edu.wpi.first.math.numbers.N1> visionStandardDeviation, com.ctre.phoenix6.swerve.SwerveModuleConstants<?, ?, ?>... modules) Constructs a CTRE SwerveDrivetrain using the specified constants.protectedCommandSwerveDrivetrain(com.ctre.phoenix6.swerve.SwerveDrivetrainConstants drivetrainConstants, com.ctre.phoenix6.swerve.SwerveModuleConstants<?, ?, ?>... modules) Constructs a CTRE SwerveDrivetrain using the specified constants. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddVisionMeasurement(edu.wpi.first.math.geometry.Pose2d visionRobotPoseMeters, double timestampSeconds) Adds a vision measurement to the Kalman Filter.voidaddVisionMeasurement(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.voidvoiddrive(edu.wpi.first.math.geometry.Translation2d velocity, double rotation) edu.wpi.first.wpilibj2.command.CommandfollowPathCommand(com.pathplanner.lib.path.PathPlannerPath path) edu.wpi.first.wpilibj2.command.CommandfollowPathCommand(String pathName) edu.wpi.first.math.kinematics.ChassisSpeedscom.ctre.phoenix6.swerve.SwerveRequest.FieldCentricedu.wpi.first.math.geometry.Translation2dstatic CommandSwerveDrivetrainorg.ironmaple.simulation.drivesims.SwerveDriveSimulationedu.wpi.first.math.kinematics.SwerveModuleState[]edu.wpi.first.math.geometry.Pose2dgetPose()com.ctre.phoenix6.swerve.SwerveRequest.RobotCentricedu.wpi.first.math.geometry.Pose2dbooleanisAlignedToTarget(edu.wpi.first.math.geometry.Pose2d target) voidperiodic()voidresetPose(edu.wpi.first.math.geometry.Pose2d pose) private voidsetChassisSpeeds(edu.wpi.first.math.kinematics.ChassisSpeeds robotSpeeds) voidsetControl(com.ctre.phoenix6.swerve.SwerveRequest request) private voidedu.wpi.first.wpilibj2.command.CommandsysIdDynamic(edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction direction) Runs the SysId Dynamic test in the given direction for the routine specified bym_sysIdRoutineToApply.edu.wpi.first.wpilibj2.command.CommandsysIdQuasistatic(edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction direction) Runs the SysId Quasistatic test in the given direction for the routine specified bym_sysIdRoutineToApply.edu.wpi.first.wpilibj2.command.CommandsysidRotationDynamic(edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction direction) edu.wpi.first.wpilibj2.command.CommandsysidRotationQuasiStatic(edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction direction) edu.wpi.first.wpilibj2.command.CommandsysidSteerDynamic(edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction direction) edu.wpi.first.wpilibj2.command.CommandsysidSteerQuasistatic(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, optimizeBusUtilization, optimizeBusUtilization, optimizeBusUtilization, registerTelemetry, resetRotation, resetTranslation, samplePoseAt, seedFieldCentric, seedFieldCentric, 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
-
Field Details
-
instance
-
kSimLoopPeriod
- See Also:
-
m_simNotifier
-
m_lastSimTime
-
m_moduleTranslationCharacterization
private final com.ctre.phoenix6.swerve.SwerveRequest.SysIdSwerveTranslation m_moduleTranslationCharacterization -
m_steerCharacterization
-
m_rotationCharacterization
-
fieldCentricRequest
-
robotCentricRequest
-
m_sysIdRoutineModuleTranslation
-
m_sysIdRoutineChassisTranslation
-
m_sysIdRoutineSteer
-
m_sysIdRoutineRotation
-
m_sysIdRoutineToApply
-
mapleSimSwerveDrivetrain
-
posePublisher
private final edu.wpi.first.networktables.StructPublisher<edu.wpi.first.math.geometry.Pose2d> posePublisher -
chassisPublisher
private final edu.wpi.first.networktables.StructPublisher<edu.wpi.first.math.kinematics.ChassisSpeeds> chassisPublisher -
modulePublisher
private final edu.wpi.first.networktables.StructArrayPublisher<edu.wpi.first.math.kinematics.SwerveModuleState> modulePublisher
-
-
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 drivemodules- Constants for each specific module
-
CommandSwerveDrivetrain
private CommandSwerveDrivetrain(com.ctre.phoenix6.swerve.SwerveDrivetrainConstants drivetrainConstants, double odometryUpdateFrequency, 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 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
private CommandSwerveDrivetrain(com.ctre.phoenix6.swerve.SwerveDrivetrainConstants drivetrainConstants, double odometryUpdateFrequency, edu.wpi.first.math.Matrix<edu.wpi.first.math.numbers.N3, edu.wpi.first.math.numbers.N1> odometryStandardDeviation, edu.wpi.first.math.Matrix<edu.wpi.first.math.numbers.N3, edu.wpi.first.math.numbers.N1> visionStandardDeviation, 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 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
-
getInstance
-
getFieldCentricSwerveRequest
-
getRobotCentricSwerveRequest
-
setControl
- Overrides:
setControlin classcom.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 bym_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 bym_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) -
startSimThread
-
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:
addVisionMeasurementin classcom.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:
addVisionMeasurementin classcom.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
-
isAlignedToTarget
-
getShooterPose
-
resetPose
- Overrides:
resetPosein classcom.ctre.phoenix6.swerve.SwerveDrivetrain<com.ctre.phoenix6.hardware.TalonFX,com.ctre.phoenix6.hardware.TalonFX, com.ctre.phoenix6.hardware.CANcoder>
-
configureAutoBuilder
-
followPathCommand
-
followPathCommand
public edu.wpi.first.wpilibj2.command.Command followPathCommand(com.pathplanner.lib.path.PathPlannerPath path) -
getModuleStates
-
getChassisSpeeds
-
getFieldRelativeSpeeds
-
setChassisSpeeds
-
drive
-
periodic
- Specified by:
periodicin interfaceedu.wpi.first.wpilibj2.command.Subsystem
-