Package frc.robot.subsystems.swerve
Class Swerve
java.lang.Object
com.ctre.phoenix6.swerve.SwerveDrivetrain<TalonFX,TalonFX,CANcoder>
frc.robot.subsystems.swerve.Swerve
- All Implemented Interfaces:
Subsystem,AutoCloseable
Phoenix SwerveDrivetrain wired up as a WPILib subsystem.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class com.ctre.phoenix6.swerve.SwerveDrivetrain
SwerveDrivetrain.DeviceConstructor<DeviceT extends Object>, SwerveDrivetrain.OdometryThread, SwerveDrivetrain.SwerveControlParameters, SwerveDrivetrain.SwerveDriveState -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doublestatic final doubleFields 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 Stringprotected doubleprotected doublegetPoseAtTimestamp(double timestampSeconds) Samples the pose buffer at a timestamp.Returns the simulated pose in sim, otherwise the pose odometry reports.doublegetRotationDifference(double angle1, double angle2) doubleprotected doubleprotected doubledoubleinXzone(double minXmeter, double maxXmeter) inXzoneAlliance(double minXmeter, double maxXmeter) inYzone(double minYmeter, double maxYmeter) inYzoneAlliance(double minYmeter, double maxYmeter) booleanbooleanisAtDesiredRotation(double toleranceRadians) booleanisGoingTooFast(double thresholdSpeed) booleanReturnstruewhen the robot is inside the opposing alliance's zone (pose X is flipped for red so the same rectangle works for both alliances).booleanReturnstruewhen the robot is inside the neutral zone.protected voidprotected voidoverSpeedTrigger(double thresholdSpeed) voidperiodic()Advances the state machine and the sim pose.protected Commandreorient(double angleDegrees) voidvoidsetRotationVelocityCoefficient(double rotationVelocityCoefficient) voidsetTeleopVelocityCoefficient(double teleopVelocityCoefficient) voidsetWantedState(Swerve.WantedState state) 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, optimizeBusUtilization, optimizeBusUtilization, optimizeBusUtilization, 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
-
Field Details
-
TRANSLATION_ERROR_MARGIN_METERS
public static final double TRANSLATION_ERROR_MARGIN_METERS -
DRIVE_TO_POINT_STATIC_FRICTION_CONSTANT
public static final double DRIVE_TO_POINT_STATIC_FRICTION_CONSTANT- See Also:
-
-
Constructor Details
-
Swerve
-
-
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()Advances the state machine and the sim pose. WPILib calls this every 20 ms. -
getCurrentCommandName
-
getRobotPose
Returns the simulated pose in sim, otherwise the pose odometry reports. -
getPoseAtTimestamp
Samples the pose buffer at a timestamp.- Parameters:
timestampSeconds- a RoboRIO timestamp, as inUtils.fpgaToCurrentTime(double)- Returns:
- the sampled pose, or the current pose if the timestamp is not buffered
-
resetPose
- Overrides:
resetPosein classSwerveDrivetrain<TalonFX,TalonFX, CANcoder>
-
inXzone
-
inYzone
-
inXzoneAlliance
-
inYzoneAlliance
-
isInNeutralZone
public boolean isInNeutralZone()Returnstruewhen the robot is inside the neutral zone. Allocation-free. -
isInEnemyAllianceZone
public boolean isInEnemyAllianceZone()Returnstruewhen the robot is inside the opposing alliance's zone (pose X is flipped for red so the same rectangle works for both alliances). -
inNeutralZone
-
inEnemyAllianceZone
-
inFieldRight
-
inFieldLeft
-
isGoingTooFast
public boolean isGoingTooFast(double thresholdSpeed) -
overSpeedTrigger
-
getCurrentRobotChassisSpeeds
-
reorient
-
reorientForward
-
reorientLeft
-
reorientBack
-
reorientRight
-
getClosestCardinal
protected double getClosestCardinal() -
cardinalReorient
-
frontClosestToAngle
public boolean frontClosestToAngle(double angleDegrees) -
getRotationDifference
public double getRotationDifference(double angle1, double angle2) -
setWantedState
-
isAtDesiredRotation
public boolean isAtDesiredRotation() -
isAtDesiredRotation
public boolean isAtDesiredRotation(double toleranceRadians) -
getTeleopVelocityCoefficient
public double getTeleopVelocityCoefficient() -
setTeleopVelocityCoefficient
public void setTeleopVelocityCoefficient(double teleopVelocityCoefficient) -
getRotationVelocityCoefficient
public double getRotationVelocityCoefficient() -
setRotationVelocityCoefficient
public void setRotationVelocityCoefficient(double rotationVelocityCoefficient) -
getConfig
-
getMapleSimSwerveDrivetrain
-
getRobotBumpSim
-
getSimRobotPose3d
-