Class Swerve

All Implemented Interfaces:
Subsystem, AutoCloseable

public class Swerve extends SwerveDrivetrain<TalonFX,TalonFX,CANcoder> implements Subsystem
Phoenix SwerveDrivetrain wired up as a WPILib subsystem.
  • 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

  • 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()
      Advances the state machine and the sim pose. WPILib calls this every 20 ms.
      Specified by:
      periodic in interface Subsystem
    • getCurrentCommandName

      protected String getCurrentCommandName()
    • getRobotPose

      public Pose2d getRobotPose()
      Returns the simulated pose in sim, otherwise the pose odometry reports.
    • getPoseAtTimestamp

      public Pose2d getPoseAtTimestamp(double timestampSeconds)
      Samples the pose buffer at a timestamp.
      Parameters:
      timestampSeconds - a RoboRIO timestamp, as in Utils.fpgaToCurrentTime(double)
      Returns:
      the sampled pose, or the current pose if the timestamp is not buffered
    • 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)
    • inYzoneAlliance

      public Trigger inYzoneAlliance(double minYmeter, double maxYmeter)
    • 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()