Package frc.robot
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>
frc.robot.CommandSwerveDrivetrain
- All Implemented Interfaces:
edu.wpi.first.wpilibj2.command.Subsystem
,AutoCloseable
public class CommandSwerveDrivetrain
extends com.ctre.phoenix6.swerve.SwerveDrivetrain<com.ctre.phoenix6.hardware.TalonFX,com.ctre.phoenix6.hardware.TalonFX,com.ctre.phoenix6.hardware.CANcoder>
implements edu.wpi.first.wpilibj2.command.Subsystem
Class that extends the Phoenix SwerveDrivetrain class and implements subsystem
so it can be used in command-based projects easily.
-
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
ConstructorsConstructorDescriptionCommandSwerveDrivetrain
(com.ctre.phoenix6.swerve.SwerveDrivetrainConstants drivetrainConstants, com.ctre.phoenix6.swerve.SwerveModuleConstants<?, ?, ?>... modules) Constructs a CommandSwerveDrivetrain with the specified drivetrain constants and modules. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Applies the operator perspective based on the alliance color.void
followTrajectory
(choreo.trajectory.SwerveSample sample) Follows the given trajectory sample by adjusting the chassis speeds and heading.edu.wpi.first.math.kinematics.ChassisSpeeds
Get the chassis speeds of the drivetrain relative to the field.edu.wpi.first.math.kinematics.SwerveModulePosition[]
Get the SwerveModulePosition for localized odo.edu.wpi.first.math.geometry.Pose2d
getPose()
Return the pose of the drivetrain.edu.wpi.first.math.kinematics.ChassisSpeeds
Return the chassis speeds of the drivetrain relative to the robot.Get the sim drive train as a MapleSimSwerveDrivetrain.Methods inherited from class com.ctre.phoenix6.swerve.SwerveDrivetrain
addVisionMeasurement, addVisionMeasurement, close, configNeutralMode, getKinematics, getModule, getModuleLocations, getModules, getOdometryFrequency, getOdometryFrequencyMeasure, getOdometryThread, getOperatorForwardDirection, getPigeon2, getRotation3d, getState, getStateCopy, isOdometryValid, isOnCANFD, registerTelemetry, resetPose, resetRotation, resetTranslation, samplePoseAt, seedFieldCentric, setControl, setOperatorPerspectiveForward, setStateStdDevs, setVisionMeasurementStdDevs, tareEverything, updateSimState
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface edu.wpi.first.wpilibj2.command.Subsystem
defer, getCurrentCommand, getDefaultCommand, getName, periodic, register, removeDefaultCommand, run, runEnd, runOnce, setDefaultCommand, simulationPeriodic, startEnd, startRun
-
Constructor Details
-
CommandSwerveDrivetrain
public CommandSwerveDrivetrain(com.ctre.phoenix6.swerve.SwerveDrivetrainConstants drivetrainConstants, com.ctre.phoenix6.swerve.SwerveModuleConstants<?, ?, ?>... modules) Constructs a CommandSwerveDrivetrain with the specified drivetrain constants and modules.- Parameters:
drivetrainConstants
- the constants for the swerve drivetrainmodules
- the swerve modules
-
-
Method Details
-
applyOperatorPerspective
public void applyOperatorPerspective()Applies the operator perspective based on the alliance color. Blue alliance sees forward as 0 degrees (toward red alliance wall). Red alliance sees forward as 180 degrees (toward blue alliance wall). -
followTrajectory
public void followTrajectory(choreo.trajectory.SwerveSample sample) Follows the given trajectory sample by adjusting the chassis speeds and heading.- Parameters:
sample
- the swerve sample containing the desired trajectory information
-
getModulePositions
public edu.wpi.first.math.kinematics.SwerveModulePosition[] getModulePositions()Get the SwerveModulePosition for localized odo.- Returns:
- swerve module position
-
getSimDrivetrain
Get the sim drive train as a MapleSimSwerveDrivetrain.- Returns:
- the sim drivetrain of the current class, or null if not simulation
-
getPose
public edu.wpi.first.math.geometry.Pose2d getPose()Return the pose of the drivetrain.- Returns:
- pose
-
getRobotRelativeChassisSpeeds
public edu.wpi.first.math.kinematics.ChassisSpeeds getRobotRelativeChassisSpeeds()Return the chassis speeds of the drivetrain relative to the robot.- Returns:
- chassis speeds relative to robot
-
getFieldRelativeChassisSpeeds
public edu.wpi.first.math.kinematics.ChassisSpeeds getFieldRelativeChassisSpeeds()Get the chassis speeds of the drivetrain relative to the field.- Returns:
- chassis speeds relative to field
-