Class Swerve

All Implemented Interfaces:
Subsystem, AutoCloseable

public class Swerve extends SwerveDrivetrain<TalonFX,TalonFX,CANcoder> implements Subsystem
Class that extends the Phoenix SwerveDrivetrain class and implements subsystem so it can be used in command-based projects easily.
  • 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

      public Swerve(SwerveConfig config)
      Constructs a new Swerve drive subsystem.
      Parameters:
      config - The configuration object containing drivetrain constants and module configurations.
  • Method Details

    • log

      protected void log(SwerveDrivetrain.SwerveDriveState state)
    • 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.
      Specified by:
      periodic in interface Subsystem
    • getCurrentCommandName

      protected String getCurrentCommandName()
    • getRobotPose

      public Pose2d 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

      public Pose2d getPoseAtTimestamp(double timestampSeconds)
      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

      public void resetPose(Pose2d pose)
      Overrides:
      resetPose in class SwerveDrivetrain<TalonFX,TalonFX,CANcoder>
    • inXzone

      public Trigger inXzone(double minXmeter, double maxXmeter)
    • inYzone

      public Trigger inYzone(double minYmeter, double maxYmeter)
    • inXzoneAlliance

      public Trigger 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 Alliance
      Parameters:
      minXmeter - the minimum X coordinate in meters
      maxXmeter - the maximum X coordinate in meters
      Returns:
      the Trigger
    • inYzoneAlliance

      public Trigger 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 Alliance
      Parameters:
      minYmeter - the minimum Y coordinate in meters
      maxYmeter - the maximum Y coordinate in meters
      Returns:
      the Trigger
    • isInNeutralZone

      public boolean isInNeutralZone()
      Returns true when the robot is inside the neutral zone. Allocation-free.
    • isInEnemyAllianceZone

      public boolean isInEnemyAllianceZone()
      Returns true when the robot is inside the opposing alliance's zone (pose X is flipped for red so the same rectangle works for both alliances).
    • inNeutralZone

      public Trigger inNeutralZone()
    • inEnemyAllianceZone

      public Trigger inEnemyAllianceZone()
    • inFieldRight

      public Trigger inFieldRight()
    • inFieldLeft

      public Trigger inFieldLeft()
    • isGoingTooFast

      public boolean isGoingTooFast(double thresholdSpeed)
    • overSpeedTrigger

      public Trigger overSpeedTrigger(double thresholdSpeed)
    • getCurrentRobotChassisSpeeds

      public ChassisSpeeds getCurrentRobotChassisSpeeds()
    • reorient

      protected Command reorient(double angleDegrees)
    • reorientForward

      public Command reorientForward()
    • reorientLeft

      public Command reorientLeft()
    • reorientBack

      public Command reorientBack()
    • reorientRight

      public Command reorientRight()
    • getClosestCardinal

      protected double getClosestCardinal()
    • cardinalReorient

      protected Command cardinalReorient()
    • frontClosestToAngle

      public boolean frontClosestToAngle(double angleDegrees)
    • getRotationDifference

      public double getRotationDifference(double angle1, double angle2)
    • setWantedState

      public void setWantedState(Swerve.WantedState state)
    • 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

      public SwerveConfig getConfig()
    • getMapleSimSwerveDrivetrain

      public MapleSimSwerveDrivetrain getMapleSimSwerveDrivetrain()
    • getRobotBumpSim

      public RobotBumpSim getRobotBumpSim()
    • getSimRobotPose3d

      public Pose3d getSimRobotPose3d()