Class Swerve

java.lang.Object
org.team1126.lib.util.command.GRRSubsystem
org.team1126.robot.subsystems.Swerve
All Implemented Interfaces:
edu.wpi.first.wpilibj2.command.Subsystem

public final class Swerve extends GRRSubsystem
The robot's swerve drivetrain.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    edu.wpi.first.wpilibj2.command.Command
    aimAtHub(Supplier<edu.wpi.first.math.geometry.Translation2d> goal, DoubleSupplier maxDeceleration)
    Drives the robot to a target position using the P-APF while aiming at the hub.
    edu.wpi.first.wpilibj2.command.Command
     
    boolean
     
    double
    Returns the angle from the origin of our robot to the center of the hub in radians.
    edu.wpi.first.wpilibj2.command.Command
    apfDrive(Supplier<edu.wpi.first.math.geometry.Pose2d> goal, DoubleSupplier maxDeceleration)
    Drives the robot to a target position using the P-APF.
    edu.wpi.first.wpilibj2.command.Command
    apfDrive(Supplier<edu.wpi.first.math.geometry.Pose2d> goal, DoubleSupplier maxDeceleration, DoubleSupplier endTolerance)
    Drives the robot to a target position using the P-APF, until the robot is positioned within a specified tolerance of the target.
    List<edu.wpi.first.math.geometry.Pose2d>
    Remove @NotLogged for debugging
    boolean
    Returns true if the reef angle has changed.
    double
    Returns the distance from the origin of our robot to the center of the hub in meters.
    edu.wpi.first.wpilibj2.command.Command
    Drives the robot using driver input.
    edu.wpi.first.math.geometry.Pose2d
     
    edu.wpi.first.math.geometry.Pose2d
    Returns the current blue origin relative pose of the robot.
    double
    Returns the directionless measured velocity of the robot, in m/s.
    boolean
    Checks if the origin of the robot is in the neutral zone (between the blue zone and the red zone).
    boolean
    Checks if the origin of the robot is in our alliance's zone (the blue zone if we are on the blue alliance, and the red zone if we are on the red alliance).
    boolean
    Checks if the origin of the robot is in the opposing alliance's zone (the red zone if we are on the blue alliance, and the blue zone if we are on the red alliance).
    void
     
    edu.wpi.first.wpilibj2.command.Command
    Hard reset of odometry to origin relative to blue origin.
    edu.wpi.first.wpilibj2.command.Command
    resetPose(Supplier<edu.wpi.first.math.geometry.Pose2d> pose)
    Resets the pose of the robot, inherently seeding field-relative movement.
    boolean
    Returns true if an AprilTag has been seen since the last robot loop.
    edu.wpi.first.wpilibj2.command.Command
    stop(boolean lock)
    Drives the modules to stop the robot from moving.
    edu.wpi.first.wpilibj2.command.Command
    Tares the rotation of the robot.

    Methods inherited from class org.team1126.lib.util.command.GRRSubsystem

    commandBuilder, commandBuilder

    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, idle, register, removeDefaultCommand, run, runEnd, runOnce, setDefaultCommand, simulationPeriodic, startEnd, startRun
  • Field Details

  • Constructor Details

    • Swerve

      public Swerve()
  • Method Details

    • periodic

      public void periodic()
    • getPose

      public edu.wpi.first.math.geometry.Pose2d getPose()
      Returns the current blue origin relative pose of the robot.
    • getVelocity

      public double getVelocity()
      Returns the directionless measured velocity of the robot, in m/s.
    • apfVisualization

      public List<edu.wpi.first.math.geometry.Pose2d> apfVisualization()
      Remove @NotLogged for debugging
    • seesAprilTag

      public boolean seesAprilTag()
      Returns true if an AprilTag has been seen since the last robot loop.
    • changedReference

      public boolean changedReference()
      Returns true if the reef angle has changed.
    • tareRotation

      public edu.wpi.first.wpilibj2.command.Command tareRotation()
      Tares the rotation of the robot. Useful for fixing an out of sync or drifting IMU.
    • resetPose

      public edu.wpi.first.wpilibj2.command.Command resetPose(Supplier<edu.wpi.first.math.geometry.Pose2d> pose)
      Resets the pose of the robot, inherently seeding field-relative movement.
      Parameters:
      pose - A supplier that returns the new blue origin relative pose to apply to the pose estimator.
    • resetOdometry

      public edu.wpi.first.wpilibj2.command.Command resetOdometry()
      Hard reset of odometry to origin relative to blue origin. This will assume the robot's back right corner is on 0,0.
    • drive

      public edu.wpi.first.wpilibj2.command.Command drive(DoubleSupplier x, DoubleSupplier y, DoubleSupplier angular)
      Drives the robot using driver input.
      Parameters:
      x - The X value from the driver's joystick.
      y - The Y value from the driver's joystick.
      angular - The CCW+ angular speed to apply, from [-1.0, 1.0].
    • getFuelPose

      public edu.wpi.first.math.geometry.Pose2d getFuelPose()
    • apfDrive

      public edu.wpi.first.wpilibj2.command.Command apfDrive(Supplier<edu.wpi.first.math.geometry.Pose2d> goal, DoubleSupplier maxDeceleration, DoubleSupplier endTolerance)
      Drives the robot to a target position using the P-APF, until the robot is positioned within a specified tolerance of the target.
      Parameters:
      goal - A supplier that returns the target blue-origin relative field location.
      maxDeceleration - A supplier that returns the desired deceleration rate of the robot, in m/s/s.
      endTolerance - The tolerance in meters at which to end the command.
    • apfDrive

      public edu.wpi.first.wpilibj2.command.Command apfDrive(Supplier<edu.wpi.first.math.geometry.Pose2d> goal, DoubleSupplier maxDeceleration)
      Drives the robot to a target position using the P-APF. This command does not end.
      Parameters:
      goal - A supplier that returns the target blue-origin relative field location.
      maxDeceleration - A supplier that returns the desired deceleration rate of the robot, in m/s/s.
    • aimAtHub

      public edu.wpi.first.wpilibj2.command.Command aimAtHub(Supplier<edu.wpi.first.math.geometry.Translation2d> goal, DoubleSupplier maxDeceleration)
      Drives the robot to a target position using the P-APF while aiming at the hub. This command does not end.
      Parameters:
      goal - A supplier that returns the target blue-origin relative field location.
      maxDeceleration - A supplier that returns the desired deceleration rate of the robot, in m/s/s.
    • aimAtOurZone

      public edu.wpi.first.wpilibj2.command.Command aimAtOurZone(DoubleSupplier x, DoubleSupplier y)
    • stop

      public edu.wpi.first.wpilibj2.command.Command stop(boolean lock)
      Drives the modules to stop the robot from moving.
      Parameters:
      lock - If the wheels should be driven to an X formation to stop the robot from being pushed.
    • aimingAtHub

      public boolean aimingAtHub()
    • inOurZone

      public boolean inOurZone()
      Checks if the origin of the robot is in our alliance's zone (the blue zone if we are on the blue alliance, and the red zone if we are on the red alliance).
      Returns:
      True if we are in our zone, false otherwise.
    • inNeutralZone

      public boolean inNeutralZone()
      Checks if the origin of the robot is in the neutral zone (between the blue zone and the red zone).
      Returns:
      True if we are in the neutral zone, false otherwise.
    • inTheirZone

      public boolean inTheirZone()
      Checks if the origin of the robot is in the opposing alliance's zone (the red zone if we are on the blue alliance, and the blue zone if we are on the red alliance).
      Returns:
      True if we are in the opposing alliance's zone, false otherwise.
    • distanceToHub

      public double distanceToHub()
      Returns the distance from the origin of our robot to the center of the hub in meters.
      Returns:
      The distance from the origin of our robot to the center of the hub, recalculated every code cycle.
    • angleToHub

      public double angleToHub()
      Returns the angle from the origin of our robot to the center of the hub in radians.
      Returns:
      The angle from the origin of our robot to the center of the hub, recalculated every code cycle.