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
ConstructorsModifierConstructorDescriptionprotectedCommandSwerveDrivetrain(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(com.stuypulse.stuylib.math.Vector2D 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.FieldCentriccom.stuypulse.stuylib.math.Vector2Dstatic 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) voidsetControl(com.ctre.phoenix6.swerve.SwerveRequest request) edu.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, 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
-
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
-
-
Method Details
-
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:
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) -
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:
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
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:
resetPosein classcom.ctre.phoenix6.swerve.SwerveDrivetrain<com.ctre.phoenix6.hardware.TalonFX,com.ctre.phoenix6.hardware.TalonFX, com.ctre.phoenix6.hardware.CANcoder>
-
configureAutoBuilder
public void configureAutoBuilder() -
followPathCommand
-
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:
periodicin interfaceedu.wpi.first.wpilibj2.command.Subsystem
-