Package frc.robot.swerve
Class Swerve
- All Implemented Interfaces:
Subsystem,SpectrumSubsystem,AutoCloseable
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
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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected CommandbooleanfrontClosestToAngle(double angleDegrees) protected doubleprotected doubleprotected doubleprotected Stringprotected doubleprotected doublegetPoseAtTimestamp(double timestampSeconds) Get the robot's pose at a specific timestamp using interpolationThe function `getRobotPose` returns the robot's pose after checking and updating it.doublegetRotationDifference(double angle1, double angle2) protected doubleprotected doubleinXzone(double minXmeter, double maxXmeter) inXzoneAlliance(double minXmeter, double maxXmeter) This method is used to check if the robot is in the X zone of the field flips the values if Red AllianceinYzone(double minYmeter, double maxYmeter) inYzoneAlliance(double minYmeter, double maxYmeter) This method is used to check if the robot is in the Y zone of the field flips the values if Red AlliancebooleanisGoingTooFast(double thresholdSpeed) protected voidprotected voidoverSpeedTrigger(double thresholdSpeed) voidperiodic()This method is called periodically and is used to update the pilot's perspective.protected voidreorient(double angleDegrees) protected CommandreorientPilotAngle(double angleDegrees) voidvoidSet up the default command for this subsystem.voidSet up the states and triggers for this subsystem.Methods inherited from class com.ctre.phoenix6.swerve.SwerveDrivetrain
addVisionMeasurement, addVisionMeasurement, close, configNeutralMode, configNeutralMode, getKinematics, getModule, getModuleLocations, getModules, getOdometryFrequency, getOdometryFrequencyMeasure, getOdometryThread, getOperatorForwardDirection, getPigeon2, getRotation3d, getState, getStateCopy, isOdometryValid, isOnCANFD, registerTelemetry, resetRotation, resetTranslation, samplePoseAt, 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
-
Swerve
Constructs a new Swerve drive subsystem.- Parameters:
config- The configuration object containing drivetrain constants and module configurations.
-
-
Method Details
-
log
-
logBatteryUsage
protected void logBatteryUsage() -
getDriveMotorStatorCurrents
protected double getDriveMotorStatorCurrents() -
getSteerMotorStatorCurrents
protected double getSteerMotorStatorCurrents() -
getDriveMotorSupplyCurrents
protected double getDriveMotorSupplyCurrents() -
getSteerMotorSupplyCurrents
protected double getSteerMotorSupplyCurrents() -
periodic
public void periodic()This method is called periodically and is used to update the pilot's perspective. It ensures that the swerve drive system is aligned correctly based on the pilot's view. -
setupStates
public void setupStates()Description copied from interface:SpectrumSubsystemSet up the states and triggers for this subsystem. This is typically used to bind commands to SpectrumState triggers.- Specified by:
setupStatesin interfaceSpectrumSubsystem
-
setupDefaultCommand
public void setupDefaultCommand()Description copied from interface:SpectrumSubsystemSet up the default command for this subsystem. This command will run when no other command is using this subsystem.- Specified by:
setupDefaultCommandin interfaceSpectrumSubsystem
-
getCurrentCommandName
-
getRobotPose
The function `getRobotPose` returns the robot's pose after checking and updating it.- Returns:
- The `getRobotPose` method is returning the robot's current pose after calling the `seedCheckedPose` method with the current pose as an argument.
-
getPoseAtTimestamp
Get the robot's pose at a specific timestamp using interpolation- Parameters:
timestampSeconds- The timestamp to sample at- Returns:
- The interpolated pose, or current pose if timestamp not in buffer
-
resetPose
- Overrides:
resetPosein classSwerveDrivetrain<TalonFX,TalonFX, CANcoder>
-
inXzone
-
inYzone
-
inXzoneAlliance
This method is used to check if the robot is in the X zone of the field flips the values if Red Alliance- Parameters:
minXmeter- the minimum X coordinate in metersmaxXmeter- the maximum X coordinate in meters- Returns:
- the Trigger
-
inYzoneAlliance
This method is used to check if the robot is in the Y zone of the field flips the values if Red Alliance- Parameters:
minYmeter- the minimum Y coordinate in metersmaxYmeter- the maximum Y coordinate in meters- Returns:
- the Trigger
-
inNeutralZone
-
inEnemyAllianceZone
-
inFieldRight
-
inFieldLeft
-
isGoingTooFast
public boolean isGoingTooFast(double thresholdSpeed) -
overSpeedTrigger
-
getCurrentRobotChassisSpeeds
-
reorient
protected void reorient(double angleDegrees) -
reorientPilotAngle
-
getClosestCardinal
protected double getClosestCardinal() -
getClosest45
protected double getClosest45() -
getClosestFieldAngle
protected double getClosestFieldAngle() -
cardinalReorient
-
frontClosestToAngle
public boolean frontClosestToAngle(double angleDegrees) -
getRotationDifference
public double getRotationDifference(double angle1, double angle2) -
getConfig
-
getMapleSimSwerveDrivetrain
-